2026-01-23 02:14:08 +09:00
|
|
|
# CLAUDE CODE HOOKS COMPATIBILITY
|
2026-01-19 20:18:26 +09:00
|
|
|
|
|
|
|
|
## OVERVIEW
|
2026-02-01 19:26:57 +09:00
|
|
|
|
|
|
|
|
Full Claude Code `settings.json` hook compatibility layer. Intercepts OpenCode events to execute external scripts/commands.
|
|
|
|
|
|
2026-02-06 18:59:58 +09:00
|
|
|
**Config Sources** (priority): `.claude/settings.local.json` > `.claude/settings.json` (project) > `~/.claude/settings.json` (global)
|
2026-01-19 20:18:26 +09:00
|
|
|
|
|
|
|
|
## STRUCTURE
|
|
|
|
|
```
|
|
|
|
|
claude-code-hooks/
|
2026-02-09 14:29:53 +09:00
|
|
|
├── index.ts # Barrel export
|
|
|
|
|
├── claude-code-hooks-hook.ts # Main factory
|
|
|
|
|
├── config.ts # Claude settings.json loader
|
|
|
|
|
├── config-loader.ts # Extended plugin config
|
|
|
|
|
├── pre-tool-use.ts # PreToolUse hook executor
|
|
|
|
|
├── post-tool-use.ts # PostToolUse hook executor
|
2026-01-23 02:14:08 +09:00
|
|
|
├── user-prompt-submit.ts # UserPromptSubmit executor
|
2026-02-09 14:29:53 +09:00
|
|
|
├── stop.ts # Stop hook executor
|
2026-01-23 02:14:08 +09:00
|
|
|
├── pre-compact.ts # PreCompact executor
|
|
|
|
|
├── transcript.ts # Tool use recording
|
2026-01-26 11:48:30 +09:00
|
|
|
├── tool-input-cache.ts # Pre→post input caching
|
2026-02-06 18:59:58 +09:00
|
|
|
├── todo.ts # Todo integration
|
2026-02-09 14:29:53 +09:00
|
|
|
├── session-hook-state.ts # Active state tracking
|
|
|
|
|
├── types.ts # Hook & IO type definitions
|
|
|
|
|
├── plugin-config.ts # Default config constants
|
|
|
|
|
└── handlers/ # Event handlers (5 files)
|
2026-01-19 20:18:26 +09:00
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## HOOK LIFECYCLE
|
2026-02-10 14:53:39 +09:00
|
|
|
|
2026-01-26 11:48:30 +09:00
|
|
|
| Event | Timing | Can Block | Context Provided |
|
|
|
|
|
|-------|--------|-----------|------------------|
|
2026-02-10 14:53:39 +09:00
|
|
|
| PreToolUse | Before exec | Yes (exit 2) | sessionId, toolName, toolInput, cwd |
|
|
|
|
|
| PostToolUse | After exec | Warn (exit 1) | + toolOutput, transcriptPath |
|
|
|
|
|
| UserPromptSubmit | On message | Yes (exit 2) | sessionId, prompt, parts, cwd |
|
|
|
|
|
| Stop | Session end | Inject | sessionId, parentSessionId, cwd |
|
2026-01-26 11:48:30 +09:00
|
|
|
| PreCompact | Before summarize | No | sessionId, cwd |
|
2026-01-19 20:18:26 +09:00
|
|
|
|
2026-02-10 14:53:39 +09:00
|
|
|
## EXIT CODES
|
|
|
|
|
|
|
|
|
|
- `0`: Pass (continue)
|
|
|
|
|
- `1`: Warn (continue + system message)
|
|
|
|
|
- `2`: Block (abort operation)
|
2026-01-19 20:18:26 +09:00
|
|
|
|
|
|
|
|
## ANTI-PATTERNS
|
2026-02-10 14:53:39 +09:00
|
|
|
|
|
|
|
|
- **Heavy PreToolUse**: Runs before EVERY tool — keep scripts fast
|
|
|
|
|
- **Blocking non-critical**: Prefer PostToolUse warnings
|
|
|
|
|
- **Ignoring exit codes**: Return `2` to block sensitive tools
|