Claude Code hook

tx0 hook runs after every edit a coding agent makes. It checks the edited files and, when the edit introduced a finding, prints it on standard error and exits with 2, which Claude Code passes back to the model.

All docs pages

Set it up

Add a PostToolUse hook to .claude/settings.json in the repository, or to ~/.claude/settings.json for every project:

.claude/settings.json
{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "Edit|MultiEdit|Write",
        "hooks": [{ "type": "command", "command": "tx0 hook" }]
      }
    ]
  }
}

Claude Code runs tx0 hook after each Edit, MultiEdit or Write and passes the tool call as JSON on standard input. tx0 takes the edited paths from it (tool_input.file_path and the paths of multiple edits, relative to cwd), skips files that were removed or are in a language it has no rules for, and checks the rest. tx0 init --agents prints the same snippet.

The hook and the MCP server work well together: the hook reports without being asked, and the tools let the agent fix, explain or suppress what it reported.

What the agent reads

With something new, the hook writes the findings in the agent format, each with its id, the line and its fix as a diff, followed by the commands to act on them. It shows at most 20 findings and says how many it left out. Here an edit to jobs/queue.py compared an int with is:

$ tx0 hook
load index: 0.0 ms
refresh: 67.7 ms
save index: 0.2 ms
check: 4.8 ms
tx0 found new problems in the edited files: 1 finding (1 warning) in 1 file
jobs/queue.py
  HQ4Y8YG86 12:12 warning tx0/python:is-literal `is` compares identity; use `==` to compare with the int `0`
    12 |         if len(self.items) is 0:
       |            ^^^^^^^^^^^^^^^^^^^^
    note: whether equal values are the same object depends on the interpreter
    fix (unsafe): write `==`
    @@ -12 +12 @@
    -        if len(self.items) is 0:
    +        if len(self.items) == 0:
next: tx0 fix --finding ID | tx0 explain ID | tx0 suppress ID --reason TEXT
exit 2

After the agent applied the fix, the same hook prints nothing and exits with 0:

$ tx0 hook
exit 0

What counts as new

The hook compares with the last commit. A finding is new when its file changed and the same finding, compared by rule and identity rather than by line, was not there at HEAD. Findings that existed before the edit stay out of the report, including those in code the edit moved or reformatted, so the agent is not asked to fix what it did not write.

Other agents

Any agent that can run a command after an edit can use the hook. Pass the edited files as arguments, or the hook's JSON on standard input with the path in tool_input.file_path:

$ tx0 hook src/server/handler.go
Exit codeMeaning
0nothing new
2new findings, on standard error
1tx0 could not run

How long it takes

In Kubernetes (18 328 files checked), checking the edited file took 3 ms and the whole hook 0.8 s, most of it bringing the index of the tree up to date. Measured with tx0 0.1.0-alpha.2, default tier, on a ThinkPad T14s Gen 1 (AMD Ryzen 7 PRO 4750U, 16 threads, 30 GB) that was running other work at a load average of 24 to 33, measured on 27 November 2026; Speed has the method.