Skip to content

Claude Code hooks (optional)

Three hooks. None blocks your work except intent, which is meant to: the other two only add a suggestion to Claude's context (additionalContext, exit 0). All need clarent on the PATH (pip install clarent-methods).

Hook Event What it does
clarent hook ach-on-repeat-failure PostToolUse + PostToolUseFailure, matcher Bash When the same test command (pytest, unittest, npm/yarn/pnpm test, jest, vitest, go test, cargo test, gradle, mvn, rspec, …) fails twice in a row, suggests /clarent-methods:ach once. A success resets the count.
clarent hook aar-on-incident-close UserPromptSubmit When a prompt says an incident is resolved/closed, or asks for a postmortem or retrospective (English or Spanish), suggests /clarent-methods:aar.
clarent intent hook SubagentStop Verifies .clarent/intent.md when a subagent stops; exit 2 sends the report back (up to 3 times). See methods/intent/CARD.md.

Add to .claude/settings.json (project) or ~/.claude/settings.json (user):

{
  "hooks": {
    "PostToolUse":        [{"matcher": "Bash", "hooks": [{"type": "command", "command": "clarent hook ach-on-repeat-failure"}]}],
    "PostToolUseFailure": [{"matcher": "Bash", "hooks": [{"type": "command", "command": "clarent hook ach-on-repeat-failure"}]}],
    "UserPromptSubmit":   [{"hooks": [{"type": "command", "command": "clarent hook aar-on-incident-close"}]}],
    "SubagentStop":       [{"hooks": [{"type": "command", "command": "clarent intent hook"}]}]
  }
}

Both events are needed for the ach hook: Claude Code sends failed Bash calls to PostToolUseFailure and successful ones to PostToolUse (which resets the count). clarent init can write this for you.

Tested

On 2026-11-28 with Claude Code 2.1.332 (claude -p --model sonnet --setting-sources project):

  • A session ran python3 -m unittest test_x twice on a failing test; after the second run Claude reported receiving: "PostToolUseFailure:Bash hook additional context: Clarent: python3 -m unittest test_x has now failed 2 times in a row. Before another fix attempt, consider /clarent-methods:ach …". Nothing after the first.
  • The prompt "INC-2210 is resolved now" arrived with the aar suggestion attached.
  • intent hook with a real subagent: evals/intent/subagent-hook/.

Limits: the test-command pattern is a regular expression (wrapper scripts with other names are not seen), the incident pattern is keyword matching with false positives, and the counter lives in the system temp directory per session. Whether these suggestions change what the agent does next was not measured.