Back to Hooks
Lint on Edit
PostToolUseAutomatically run ESLint on files after Claude Code edits them
lintingeslintcode-quality
By Claude Code Community
Hook Script
#!/bin/bash
# Lint on Edit Hook
# Runs ESLint on files after they are edited
# Get the file path from the hook context
FILE_PATH="$CLAUDE_FILE_PATH"
# Check if file exists and is a JS/TS file
if [[ -f "$FILE_PATH" && "$FILE_PATH" =~ \.(js|jsx|ts|tsx)$ ]]; then
npx eslint --fix "$FILE_PATH" 2>/dev/null
fi
Settings Configuration
{
"hooks": {
"PostToolUse": [
{
"matcher": "Edit",
"command": "./hooks/lint-on-edit.sh"
}
]
}
}How to use
- Create a hooks directory in your project: mkdir hooks
- Save the hook script as hooks/lint-on-edit.sh
- Make it executable: chmod +x hooks/lint-on-edit.sh
- Add the configuration to your Claude Code settings
- Restart Claude Code to apply changes