claude-code - 💡(How to fix) Fix Feature request: Skill-level hooks (pre-tool-use hooks declared in SKILL.md) [1 participants]

Official PRs (…)
ON THIS PAGE

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#46256Fetched 2026-04-11 06:25:07
View on GitHub
Comments
0
Participants
1
Timeline
3
Reactions
0
Author
Participants
Timeline (top)
labeled ×3

Fix Action

Fix / Workaround

When the skill is active, the declared hooks would be merged into the active hook set — no manual settings.json configuration needed. The hook script lives inside the skill folder and ships with it.

Code Example

---
name: my-skill
description: Wraps a third-party API safely
allowed-tools: ["Bash"]
hooks:
  pre-tool-use:
    - tool: Bash
      script: ./guard.sh
      message: "Direct library access blocked. Use the skill's utility module."
---
RAW_BUFFERClick to expand / collapse

Problem

Skills currently have no way to enforce safety constraints on tool usage. The only enforcement mechanism is instructions in SKILL.md, which are advisory — the LLM can bypass them by writing ad-hoc code (e.g. importing a library directly instead of going through the skill's sealed utility layer).

Hooks (pre-tool-use, post-tool-use) solve this at the user/project level via settings.json, but they are not portable with the skill. When a skill is shared across a team, each user must manually configure the hook — or it simply doesn't exist.

Real-world example

We built a skill that wraps a third-party API client with a sealed access pattern (similar to how database skills use callback-based encapsulation). All operations must go through a utility module that enforces batch API calls and prevents rate limiting.

However, nothing stops the LLM from writing ad-hoc code in a Bash call that imports the underlying library directly — bypassing the utility entirely. This actually happened during use: multiple individual API calls in a loop triggered rate limiting (HTTP 500 errors for ~30 seconds).

A pre-tool-use hook that blocks direct library imports in Bash commands would enforce this. But when the skill is shared with teammates, the hook doesn't travel with it.

Proposed solution

Allow SKILL.md to declare hooks that activate when the skill is loaded. For example:

---
name: my-skill
description: Wraps a third-party API safely
allowed-tools: ["Bash"]
hooks:
  pre-tool-use:
    - tool: Bash
      script: ./guard.sh
      message: "Direct library access blocked. Use the skill's utility module."
---

When the skill is active, the declared hooks would be merged into the active hook set — no manual settings.json configuration needed. The hook script lives inside the skill folder and ships with it.

Benefits

  • Portable enforcement: Safety constraints travel with the skill, not the user's config
  • Defense in depth: Complements SKILL.md instructions with actual runtime blocking
  • Team-friendly: No per-user setup when sharing skills across an organization
  • Consistent with existing patterns: Uses the same hook mechanism already in settings.json, just scoped to skill activation

🤖 Generated with Claude Code

extent analysis

TL;DR

To enforce safety constraints on tool usage, allow skills to declare hooks in their SKILL.md file that activate when the skill is loaded.

Guidance

  • Implement a mechanism to parse and merge hooks declared in SKILL.md into the active hook set when a skill is loaded.
  • Ensure the hook script lives inside the skill folder and ships with it, as proposed in the solution.
  • Test the implementation with a sample skill that wraps a third-party API client, verifying that the hook blocks direct library imports in Bash commands.
  • Consider adding validation for the hooks section in SKILL.md to prevent errors or security vulnerabilities.

Example

---
name: my-skill
description: Wraps a third-party API safely
allowed-tools: ["Bash"]
hooks:
  pre-tool-use:
    - tool: Bash
      script: ./guard.sh
      message: "Direct library access blocked. Use the skill's utility module."
---

This example demonstrates how a skill can declare a hook to block direct library imports in Bash commands.

Notes

The proposed solution relies on the existing hook mechanism in settings.json, but scopes it to skill activation. This approach may require modifications to the skill loading and hook merging logic.

Recommendation

Apply the proposed workaround by allowing skills to declare hooks in their SKILL.md file, as it provides portable enforcement of safety constraints and complements existing patterns.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix Feature request: Skill-level hooks (pre-tool-use hooks declared in SKILL.md) [1 participants]