ESLint after JS/TS edit
Runs eslint --fix on JavaScript and TypeScript files after Claude edits them, and warns (never blocks) on remaining problems.
PostToolUseEdit|Writereview riskneeds manual checkWhat it does
Same shape as the Prettier hook, but runs eslint --fix on .js/.jsx/.ts/.tsx files. If problems remain after fixing, the script exits 2 so Claude sees the lint output as a warning and can react - the edit itself already happened, so nothing is blocked.
When it runs
| Event | PostToolUse |
| Matcher | Edit|Write |
| Scope | project |
| Platforms | macos, linux |
| Timeout | 30s |
| Requires | jq eslint |
| Failure mode | warn |
| Verified against | Claude Code hooks reference, event/matcher schema checked 2026-09-10 |
| Test status | needs manual check - run the test steps below before relying on it |
Config
Merge this into .claude/settings.json - or use the generator to combine hooks.
{
"hooks": {
"PostToolUse": [
{
"hooks": [
{
"type": "command",
"command": "${CLAUDE_PROJECT_DIR}/.claude/hooks/eslint-after-edit.sh",
"timeout": 30
}
],
"matcher": "Edit|Write"
}
]
}
}Script
Save as .claude/hooks/eslint-after-edit.sh and chmod +x it.
#!/bin/bash
# eslint-after-edit: run after Claude edits a file. Reads hook JSON from stdin.
set -u
file=$(jq -r '.tool_input.file_path // empty')
[ -z "$file" ] && exit 0
[ -f "$file" ] || exit 0
case "$file" in
*.js|*.jsx|*.ts|*.tsx) ;;
*) exit 0 ;;
esac
if ! command -v eslint >/dev/null 2>&1; then
exit 0 # formatter not installed; stay silent
fi
if ! npx eslint --fix "$file" >/dev/null 2>&1; then
echo "ESLint still reports problems in $file" >&2
npx eslint "$file" >&2 2>/dev/null
exit 2
fi
exit 0
Install
- Save the script to .claude/hooks/eslint-after-edit.sh and run: chmod +x .claude/hooks/eslint-after-edit.sh
- Install the formatter (eslint) and make sure it is on your PATH, plus jq.
- Add the config fragment to .claude/settings.json (or use the generator).
Test it
- Positive: have Claude write a JS file with an auto-fixable lint issue (e.g. extra semicolon per your config) and confirm it gets fixed.
- Warn path: have Claude write a file with a non-fixable issue and confirm Claude sees the warning (exit 2 shows stderr to Claude after the edit).
- Negative: edit a .py file - ESLint should not run.
Sources
- Claude Code hooks reference (checked 2026-09-10)
- Claude Code hooks guide (checked 2026-09-10)
Related hooks
Prettier after edit
Runs Prettier on any JS/TS/JSON/CSS/Markdown file right after Claude edits it.
PostToolUseEdit|Writelow riskneeds manual checkTypecheck after TypeScript changes
Runs tsc --noEmit in the background after Claude edits TypeScript, so type errors surface even when tests don't cover the file.
PostToolUseEdit|Writereview riskneeds manual checkPro Pack (later)
Framework bundles, cross-platform scripts, tested blocking policies, and a test harness. Free recipes and the generator stay free.
Waitlist opens soon.