Hook in workflow
typecheck-on-edit
A PostToolUse hook that type-checks the project after Claude edits a TypeScript, Python, or Go file and returns the errors as context immediately, listing the edited file's errors first. Uses only the project's own tsc, pyright or mypy, or go vet, and stays silent when none applies. Use to catch type errors in the same step as the edit that caused them instead of at the end of the session.
Install
As a plugin
Bundled in the workflow-hooks plugin. Add the marketplace once, then install the bundle; it updates with the marketplace.
/plugin marketplace add KhaledSaeed18/dotclaude/plugin install workflow-hooks@dotclaudeAs a single item
Run from the project root; the hook lands under .claude/. Copy it to ~/.claude/ to make it global.
npx shadcn@latest add KhaledSaeed18/dotclaude/typecheck-on-editInstalled as a single item, a hook still needs the settings block documented below added to .claude/settings.json. The plugin route wires it automatically.
Files installed
.claude/hooks/typecheck-on-edit/HOOK.md.claude/hooks/typecheck-on-edit/typecheck-on-edit.mjs
What it does
typecheck-on-edit
A Claude Code hook that pairs with format-on-edit: after each edit it runs the type checker the project already has and, when errors exist, adds them to Claude's context so the next action is the fix.
- TypeScript: finds the nearest
tsconfig.jsonabove the edited file and runs the project's ownnode_modules/.bin/tsc --noEmitagainst it. Never a network fetch. - Python:
pyrightfromnode_modules/.binor onPATH, elsemypy, on the edited file. - Go:
go veton the file's package. - Edited file first. Errors in the file Claude just touched lead the list; errors elsewhere (callers it broke) follow, up to 25 lines.
- Context, not a block. The edit already happened; the hook informs rather than rejects.
- Fails open. No checker, a crash, or a 60-second timeout means silence and exit
0.
Files
| File | Purpose |
|---|---|
typecheck-on-edit.mjs |
The hook script. |
HOOK.md |
This file. |
Activate it (required manual step)
Add this to .claude/settings.json (project) or ~/.claude/settings.json (global):
{
"hooks": {
"PostToolUse": [
{
"matcher": "Edit|Write|MultiEdit",
"hooks": [
{
"type": "command",
"command": "node \"$CLAUDE_PROJECT_DIR/.claude/hooks/typecheck-on-edit/typecheck-on-edit.mjs\"",
"timeout": 90
}
]
}
]
}
}
Installing the workflow-hooks plugin from the dotclaude marketplace wires this automatically.
Verify it
printf 'export const n: number = "x";\n' > src/bad.ts
echo '{"tool_name":"Edit","tool_input":{"file_path":"'$PWD'/src/bad.ts"},"cwd":"'$PWD'"}' \
| node .claude/hooks/typecheck-on-edit/typecheck-on-edit.mjs
You should see a JSON object whose additionalContext lists the TS2322 error.
Tune it
{
"typecheckOnEdit": {
"enabled": true,
"timeoutMs": 60000,
"maxLines": 25
}
}
On a large TypeScript project a full tsc --noEmit can take longer than the default cap; raise timeoutMs (and the settings.json timeout) or use project references so the nearest tsconfig.json is a small one.
Hooks run arbitrary commands on your machine with your credentials whenever their event fires. Read any hook script (including this one) before enabling it.
This is the hook as installed, rendered from its source on GitHub. Read it as Markdown.
More in workflow
- branch-protectA UserPromptSubmit hook that, once per session, tells Claude the checkout is on a protected branch (main, master, develop, or a configured list) so it...
- git-guardA PreToolUse hook for Bash that blocks git operations which destroy work or bypass review, with a reason Claude can act on. Stops force-pushes and...
- session-contextA SessionStart hook that orients every new session before the first prompt by injecting the current branch, ahead/behind status, uncommitted files, the...
- stop-gateA Stop hook that runs the project's test command before Claude may end a turn with uncommitted changes, blocking the stop and returning the failure output...
- subagent-summaryA SubagentStop hook that appends one JSON line per finished subagent to a project log (timestamp, session, agent id, and the first 300 characters of its...