Skip to main content
The ChatCLI Hooks System lets you execute automatic actions in response to application lifecycle events. With hooks, you can auto-format code after edits, send notifications, block dangerous commands, log audit trails, and much more.
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:
Workspace hooks are additive — they combine with global hooks. If the same event has hooks at both levels, all are executed (global first, then workspace).

File Structure


Available Events

ChatCLI emits 9 lifecycle events that hooks can bind to:
The PreToolUse event is blocking: if the hook returns exit code 2, the tool execution is blocked. This allows you to create guardrails that prevent dangerous operations.

Hook Types

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 for PreToolUse)
The command is executed via sh -c on Linux/macOS and cmd /c on Windows.

ToolPattern — Tool Filtering

The toolPattern field lets you filter which tools trigger the hook. It accepts glob patterns:

Environment Variables

Command hooks receive environment variables with event context:

Complete Examples

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.