Add an event-based hook to Claude Code configuration (Claude only - Codex uses rules instead)
Adds event-based hooks to Claude Code configuration for automated command execution.
/plugin marketplace add DuncanJurman/entropy-plugins/plugin install meta-unify@entropy-marketplaceYou are helping the user add an event-based hook to Claude Code.
Note: This command only configures Claude Code. Codex does not have hooks - it uses rules for command-level control instead. If the user wants command-level permissions, suggest /meta-unify:add-rule instead.
Parse $ARGUMENTS for hook details:
Check for these flags in $ARGUMENTS:
--project: Use project scope instead of user scope (default: user scope)| Event | Description | Common Use Cases |
|---|---|---|
PreToolUse | Before any tool executes | Block dangerous operations, validate inputs |
PostToolUse | After tool succeeds | Run linters, formatters, tests |
PostToolUseFailure | After tool fails | Log errors, notify |
UserPromptSubmit | Before processing user input | Validate prompts, add context |
Stop | When main agent finishes | Cleanup, notifications |
SubagentStop | When subagent finishes | Log subagent results |
SessionStart | Session begins | Initialize environment |
SessionEnd | Session ends | Cleanup |
PreCompact | Before conversation compaction | Save important context |
Notification | When notifications sent | Custom notification handling |
PermissionRequest | Permission dialog shown | Auto-approve known safe operations |
If the user provided sufficient context, proceed to Step 2.
If missing required information, ask conversationally:
"I'll help you add a hook to Claude Code. I need to know:
- When should this trigger? (e.g., after file edits, before bash commands, when session starts)
- What should happen? (the command to run)
- Which tools should trigger it? (optional - e.g., only Edit and Write, or all tools)"
Based on user description, determine the event:
PostToolUsePreToolUsePostToolUseFailureSessionStartStopMatcher patterns for filtering which tools trigger the hook:
* or omit → All toolsWrite → Only Write toolEdit|Write → Edit OR Write toolsBash → Only Bash toolNotebook.* → Any Notebook tools (regex)Common tool names: Bash, Read, Write, Edit, Glob, Grep, WebFetch, WebSearch, Task
User Scope (default):
~/.claude/settings.jsonProject Scope (--project flag):
.claude/settings.json{
"hooks": {
"EVENT_NAME": [
{
"matcher": "TOOL_PATTERN",
"hooks": [
{
"type": "command",
"command": "COMMAND_HERE",
"timeout": 30
}
]
}
]
}
}
Hook types:
command - Execute a shell command (most common)prompt - LLM-based evaluation (for Stop/SubagentStop)agent - Complex agentic verificationReport success:
"Added hook to Claude Code:
- Event: PostToolUse
- Matcher: Edit|Write
- Command: npm run lint:fix
- Location: ~/.claude/settings.json
Note: Codex doesn't support hooks. For command-level permissions in Codex, use
/meta-unify:add-rule.Restart Claude Code to activate the hook."
User input: "Run eslint after every file edit"
PostToolUseEdit|Writeeslint --fix $FILE (or npm run lint)User input: "Block any rm -rf commands"
PreToolUseBashUser input: "Run tests when I'm done"
Stopnpm test$FILE - The file being operated on (for file-related tools)$TOOL_NAME - Name of the tool being executed$SESSION_ID - Current session identifierFor complete hook specifications, invoke the meta-unify-core skill to access: