Documentation

Hooks

Run formatters, linters, and tests automatically in response to agent actions.

Edit on GitHub

Hooks let you run commands automatically in response to agent actions. Use them to enforce formatting, run linters, execute tests, or perform any automated check after the agent modifies files. Results are reported back to the agent so it can react to failures.

Configure hooks in configuration, or define them directly in config.toml.


Configuration

Hooks are defined as an array in config.toml:

[[agent.hooks]]
event = "after_edit"
command = "cargo fmt -- {file}"
pattern = "*.rs"
timeout = 30

[[agent.hooks]]
event = "after_turn"
command = "cargo clippy --all -- -D warnings"
timeout = 60

Hook events

EventTriggerAvailable context
after_editAfter any file-modifying tool (write, edit, multi_edit, apply_patch){file} — the changed file path
after_turnAfter each complete agent turnNone
pre_toolBefore a tool executestool_name filter
post_toolAfter a tool succeedstool_name filter
post_tool_failureAfter a tool failstool_name filter
teammate_idleWhen a teammate reports no workTeam context
task_completedWhen a team task is marked completeTask context

Hook properties

PropertyTypeRequiredDescription
eventstringyesWhen to trigger (see table above)
commandstringyesShell command to execute
patternstringnoFile pattern filter (for after_edit)
timeoutintegernoTimeout in seconds (default: 30)
blockbooleannoIf true, non-zero exit blocks the triggering action
tool_namestringnoFilter by tool name (for pre/post_tool events)

Placeholders

The {file} placeholder in the command string is replaced with the path of the changed file. Only available for after_edit hooks.

[[agent.hooks]]
event = "after_edit"
command = "prettier --write {file}"
pattern = "*.ts,*.tsx"

Pattern matching

The pattern field filters which files trigger the hook:

  • Extension matching*.rs, *.ts, *.py
  • Path substringsrc/api/ matches any file containing that substring
  • Multiple patterns — Comma-separated, e.g. *.ts,*.tsx,*.js

If no pattern is specified, the hook runs for all file changes.


Blocking hooks

When block = true, a non-zero exit code from the hook prevents the triggering tool from completing. Useful for pre-tool validation:

[[agent.hooks]]
event = "pre_tool"
tool_name = "git_commit"
command = "cargo test"
block = true
timeout = 120

This prevents commits if tests fail. See verification for more on integrating tests into your workflow.


Hook results

Each hook execution produces a result with:

  • command — the executed command
  • stdout — standard output
  • stderr — standard error
  • exit_code — process exit code
  • timed_out — whether the hook exceeded its timeout

Results are reported back to the agent so it can react to failures.


Hook types

Three hook execution types exist (currently only command is configurable):

TypeDescription
CommandRuns a shell command via sh -c. Supports timeout, stdin (JSON context).
PromptEvaluates a prompt with context (placeholder, returns YES).
AgentDelegates to an agent for evaluation (placeholder, returns safe).

Prompt and Agent types are reserved for future use.


Special exit codes

For team hooks (teammate_idle, task_completed):

  • Exit code 0 — success, continue normally
  • Exit code 2 — rejection with feedback. The hook’s stdout is returned as feedback to the agent, which may adjust its approach.

Examples

Format Rust files after edit

[[agent.hooks]]
event = "after_edit"
command = "cargo fmt -- {file}"
pattern = "*.rs"
timeout = 30

Run clippy after each turn

[[agent.hooks]]
event = "after_turn"
command = "cargo clippy --all -- -D warnings"
timeout = 60

Lint TypeScript on save

[[agent.hooks]]
event = "after_edit"
command = "eslint --fix {file}"
pattern = "*.ts,*.tsx"
timeout = 15

Run tests before commits

[[agent.hooks]]
event = "pre_tool"
tool_name = "git_commit"
command = "npm test"
block = true
timeout = 120

Format Python files

[[agent.hooks]]
event = "after_edit"
command = "black {file}"
pattern = "*.py"
timeout = 15

Viewing hooks

In the TUI, use /hooks to see all configured hooks and their settings.