Back to Hooks

Lint on Edit

PostToolUse

Automatically 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

  1. Create a hooks directory in your project: mkdir hooks
  2. Save the hook script as hooks/lint-on-edit.sh
  3. Make it executable: chmod +x hooks/lint-on-edit.sh
  4. Add the configuration to your Claude Code settings
  5. Restart Claude Code to apply changes