Install
openclaw skills install nm-abstract-hook-scope-guideSelect hook scope (plugin, project, global) by audience
openclaw skills install nm-abstract-hook-scope-guideNight Market Skill — ported from claude-night-market/abstract. For the full experience with agents, hooks, and commands, install the Claude Code plugin.
This skill helps you choose the right location for Claude Code hooks based on their purpose, audience, and persistence needs.
hooks/hooks.jsonis automatically loaded by Claude Code when the plugin is enabled. Do NOT add"hooks": "./hooks/hooks.json"to yourplugin.json- this causes duplicate load errors. Thehooksfield inplugin.jsonis only needed for additional hook files beyond the standardhooks/hooks.json.
| Scope | Location | Audience | Committed? | Persistence |
|---|---|---|---|---|
| Plugin | hooks/hooks.json in plugin | Plugin users | With plugin | When plugin enabled |
| Project | .claude/settings.json | Team members | Yes (repo) | Per project |
| Global | ~/.claude/settings.json | Only you | Never | All sessions |
Only plugin users → Plugin hooks
All team members on this project → Project hooks
/src/production/ configsOnly me, everywhere → Global hooks
Yes, as part of a distributable plugin → Plugin hooks Yes, shared with team in repo → Project hooks No, keep private → Global hooks
Only when my plugin is active → Plugin hooks Always in this specific project → Project hooks Always, in every project I work on → Global hooks
Location: <plugin-root>/hooks/hooks.json
When to use:
Configuration:
{
"PreToolUse": [
{
"matcher": "Read",
"hooks": [{
"type": "command",
"command": "echo 'Plugin reading: $CLAUDE_TOOL_INPUT' >> ${CLAUDE_PLUGIN_ROOT}/log.txt"
}]
}
]
}
Note: Use string matchers (
"Read") not object matchers ({"toolName": "Read"}).
Key features:
${CLAUDE_PLUGIN_ROOT} for plugin-relative pathsExamples:
Location: .claude/settings.json (in project root)
When to use:
Configuration:
{
"hooks": {
"PreToolUse": [
{
"matcher": "Bash",
"hooks": [{
"type": "command",
"command": "if [[ \"$CLAUDE_TOOL_INPUT\" == *\"production\"* ]]; then echo 'BLOCKED: Production access requires approval'; exit 1; fi"
}]
}
]
}
}
Note: Use string matchers (
"Bash") not object matchers.
Key features:
Examples:
Location: ~/.claude/settings.json
When to use:
Configuration:
{
"hooks": {
"PreToolUse": [
{
"hooks": [{
"type": "command",
"command": "echo \"$(date): $CLAUDE_TOOL_NAME\" >> ~/.claude/audit.log"
}]
}
]
}
}
Key features:
Examples:
Claude Code loads settings in this priority (highest first):
claude --flag).claude/settings.local.json).claude/settings.json)~/.claude/settings.json)Important: Multiple hooks from different scopes can respond to the same event. When they do, all matching hooks execute in parallel.
Is this hook part of a plugin's core functionality?
├─ YES → Plugin hooks (hooks/hooks.json in plugin)
└─ NO ↓
Should all team members on this project have this hook?
├─ YES → Project hooks (.claude/settings.json)
└─ NO ↓
Should this hook apply to all my Claude sessions?
├─ YES → Global hooks (~/.claude/settings.json)
└─ NO → Reconsider if you need a hook at all
Plugin hooks:
Project hooks:
Global hooks:
SessionStart hooks now receive additional input fields via stdin:
| Field | Type | Description |
|---|---|---|
session_id | string | Unique session identifier |
source | enum | "startup" | "resume" | "clear" | "compact" |
agent_type | string | Agent name if --agent flag used, empty otherwise |
The agent_type field enables scope-appropriate context injection:
# Skip heavy context for review agents
input_data = json.loads(sys.stdin.read())
if input_data.get("agent_type") in ["code-reviewer", "quick-query"]:
print(json.dumps({"hookSpecificOutput": {"additionalContext": "Minimal"}}))
This is particularly useful for: