
5. A Check That Runs Without Being Asked
Moving the type check from something you remember to run into a PostToolUse hook that Claude Code runs after every edit, feeding errors back so the agent fixes them before finishing. Also covers this fortnight's Claude Code changes to hook failure handling, sandbox fixes and headless time limits. This episode is narrated by AI-generated synthetic voices. Episode page & show notes Visit website Turning the type check into a hook The routine still relied on memory for two steps: running the type check and running the tests. An example shows the gap. A request to add an optional note field to list items looks fine in the browser. Then the compiler fails on a shared-view component the agent never opened, because the note was marked required by mistake. CLAUDE.md is an instruction the model can skip. A hook is a command Claude Code itself runs at a defined moment, every time. The chapter wires the project's no-emit TypeScript check to the PostToolUse event with an Edit|Write matcher, as described in the hooks guide. It lives in the committed project settings file so everyone working in the repository gets it. Exit codes carry the meaning, per the hooks reference: Zero stays silent. Two hands the compiler's stderr back to Claude to fix. Any other code is a non-blocking warning. The build starts small: a hook that only logs "hook fired." It is confirmed with /hooks, and a file read is shown not to trigger it. The logger is then replaced with a committed script. The script reads the event JSON with jq, skips non-TypeScript files, and checks the whole project, because the note bug lived in an untouched file. It runs through CLAUDE_PROJECT_DIR with a 120-second timeout. The test suite stays out of the hook because it is too slow to run after every edit. The hook is proven by breaking types on purpose, then by making a correct edit that should produce no output. Where hooks go wrong Four risks are covered: Cost: every second the hook takes is added to every edit. Setup failures: a missing tool or uninstalled dependencies should exit one, not two, so the agent isn't sent to fix errors it didn't cause. Repair loops: start from a clean type check, and step in if the agent goes in circles. Trust: hooks run with your permissions without a prompt, so review them like code. disableAllHooks turns off custom hooks but not hooks from an organization's managed settings. The work ends with a commit and one line in CLAUDE.md explaining where the type errors come from. This fortnight's releases The Claude Code changelog covers versions 2.1.286 through 2.1.288: PreToolUse and PermissionRequest hooks now fail closed. Shell sandbox escapes through nested bash -c and symlinked writes are patched. Background time limits are strictly enforced in headless runs, CI and the Agent SDK. Up arrow on an empty prompt restores a request cleared with Control C. /code-review accepts a max-findings option.