2026-01-23 02:14:08 +09:00
|
|
|
# CLAUDE CODE HOOKS COMPATIBILITY
|
2026-01-19 20:18:26 +09:00
|
|
|
|
|
|
|
|
## OVERVIEW
|
|
|
|
|
|
2026-01-23 02:14:08 +09:00
|
|
|
Full Claude Code settings.json hook compatibility. 5 lifecycle events: PreToolUse, PostToolUse, UserPromptSubmit, Stop, PreCompact.
|
2026-01-19 20:18:26 +09:00
|
|
|
|
|
|
|
|
## STRUCTURE
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
claude-code-hooks/
|
2026-01-23 02:14:08 +09:00
|
|
|
├── index.ts # Main factory (401 lines)
|
2026-01-19 20:18:26 +09:00
|
|
|
├── config.ts # Loads ~/.claude/settings.json
|
2026-01-23 02:14:08 +09:00
|
|
|
├── config-loader.ts # Extended config
|
|
|
|
|
├── pre-tool-use.ts # PreToolUse executor
|
|
|
|
|
├── post-tool-use.ts # PostToolUse executor
|
|
|
|
|
├── user-prompt-submit.ts # UserPromptSubmit executor
|
|
|
|
|
├── stop.ts # Stop hook executor
|
|
|
|
|
├── pre-compact.ts # PreCompact executor
|
|
|
|
|
├── transcript.ts # Tool use recording
|
|
|
|
|
├── tool-input-cache.ts # Pre→post caching
|
|
|
|
|
├── types.ts # Hook types
|
|
|
|
|
└── todo.ts # Todo JSON fix
|
2026-01-19 20:18:26 +09:00
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## HOOK LIFECYCLE
|
|
|
|
|
|
2026-01-23 02:14:08 +09:00
|
|
|
| Event | When | Can Block | Context |
|
|
|
|
|
|-------|------|-----------|---------|
|
|
|
|
|
| PreToolUse | Before tool | Yes | sessionId, toolName, toolInput |
|
|
|
|
|
| PostToolUse | After tool | Warn | + toolOutput, transcriptPath |
|
|
|
|
|
| UserPromptSubmit | On message | Yes | sessionId, prompt, parts |
|
|
|
|
|
| Stop | Session idle | inject | sessionId, parentSessionId |
|
|
|
|
|
| PreCompact | Before summarize | No | sessionId |
|
2026-01-19 20:18:26 +09:00
|
|
|
|
|
|
|
|
## CONFIG SOURCES
|
|
|
|
|
|
|
|
|
|
Priority (highest first):
|
|
|
|
|
1. `.claude/settings.json` (project)
|
|
|
|
|
2. `~/.claude/settings.json` (user)
|
|
|
|
|
|
|
|
|
|
## HOOK EXECUTION
|
|
|
|
|
|
2026-01-23 02:14:08 +09:00
|
|
|
1. Hooks loaded from settings.json
|
|
|
|
|
2. Matchers filter by tool name
|
|
|
|
|
3. Commands via subprocess with `$SESSION_ID`, `$TOOL_NAME`
|
2026-01-19 20:18:26 +09:00
|
|
|
4. Exit codes: 0=pass, 1=warn, 2=block
|
|
|
|
|
|
|
|
|
|
## ANTI-PATTERNS
|
|
|
|
|
|
2026-01-23 02:14:08 +09:00
|
|
|
- **Heavy PreToolUse**: Runs before EVERY tool call
|
|
|
|
|
- **Blocking non-critical**: Use PostToolUse warnings
|