Hooks are additive: global and workspace configurations are merged. Workspace hooks complement global ones β they never replace them.
Configuration
Hooks are defined in JSON files at two levels:File Structure
Available Events
ChatCLI emits 8 lifecycle events that hooks can bind to:
Compaction events carry a
trigger field (auto, manual, recovery) and, on PostCompact, an outcome (applied when the history changed, skipped when nothing changed: no-op, rejected summary, failure) in the JSON payload and in CHATCLI_HOOK_TRIGGER / CHATCLI_HOOK_OUTCOME; every PreCompact is paired with exactly one PostCompact, so a hook can snapshot the transcript before an automatic rewrite, log manual /compact runs separately, or alert on overflow recoveries. PreCompact runs synchronously before the history changes; PostCompact runs detached from the turn.
Hook Types
- Command (Shell)
- HTTP (Webhook)
Executes a shell command on the operating system. The command has access to environment variables with event context.Exit codes:
0β Success (execution continues normally)1β Error (logged, but does not block)2β Blocks the operation (only forPreToolUse)
The command is executed via
sh -c on Linux/macOS and cmd /c on Windows.ToolPattern β Tool Filtering
ThetoolPattern field lets you filter which tools trigger the hook. It accepts glob patterns:
Environment Variables
Command hooks receive environment variables with event context:
Everything else about the event β tool arguments and output, the user prompt, the working directory, the error message β arrives as the JSON payload on stdin (
toolArgs, toolOutput, userPrompt, workingDir, error, trigger); read it with jq when a hook needs more than the four variables above.
Complete Examples
- Auto-Format
- Notifications
- Block Commands
- Audit
Auto-format Go files after any edit:
Use Cases
Auto-Format
Run formatters (gofmt, prettier, black) automatically after file edits.
Notifications
Send alerts to Slack, Discord, or email at the end of sessions or on errors.
Guardrails
Block dangerous commands (rm -rf, DROP TABLE, force push) with PreToolUse.
Audit
Log all agent actions to files for compliance.
Auto-Test
Run tests automatically after every code edit.
Linting
Run linters (golangci-lint, eslint) after every write/patch.
Next Steps
Coder Security
Security policies and approval for coder operations.
Security
Understand the ChatCLI security model.
Compact UI
Minimalist display mode for coder mode.
Coder Mode
The full engineering cycle with integrated hooks.