NativeAIHub
🧹

Auto Lint Hook

Automatically runs your linter after Claude edits code files, catching style violations before they compound.

Hook·2 sections·1 min read
codingdevops
Install Prompt

Paste this into Claude Code to set it up:

Add a PostToolUse hook to your ~/.claude/settings.json that runs ESLint with auto fix on TypeScript files after every Edit tool use.

In your settings.json, add this under the "hooks" key:

"PostToolUse": [
  {
    "matcher": "Edit",
    "command": "echo $CLAUDE_FILE_PATH | grep -E '\.(ts|tsx)$' && npx eslint --fix $CLAUDE_FILE_PATH 2>/dev/null || true"
  }
]

This ensures every file Claude edits gets linted automatically. The grep filter limits it to .ts and .tsx files, and the || true prevents linter warnings from blocking Claude's workflow.

01What It Does

Catch lint issues the moment they appear

Instead of discovering dozens of lint errors at the end of a session, the Auto Lint Hook runs ESLint immediately after Claude edits a file. Violations surface while the context is still fresh, so Claude can fix them in the same turn. This prevents small issues from compounding into a wall of warnings that takes longer to resolve than the original task.
1

Claude edits a file

The Edit tool modifies a .ts or .tsx file in your project. The PostToolUse event fires automatically.

2

Hook filters by file type

The command checks the file extension. If it matches .ts or .tsx, ESLint runs. Other file types are skipped entirely.

3

ESLint runs with auto fix

The linter applies fixable rules automatically (formatting, import order, unused imports) and reports anything it cannot fix.

4

Results appear in context

Claude sees the linter output and can address remaining issues immediately, before moving on to the next change.

02Configuration

How the hook is structured

Hooks live in ~/.claude/settings.json under the "hooks" key. Each hook needs an event type (PostToolUse), an optional matcher to filter which tools trigger it, and a command to execute.

The matcher is set to "Edit" so the hook only fires after file edits, not after every tool call. The command pipes the file path through grep to check the extension, then runs eslint --fix on matching files. The trailing || true ensures linter warnings never block Claude from continuing its work.

For projects that use a different linter (Biome, oxlint, or a custom script), swap out the ESLint command while keeping the same hook structure. The event and matcher stay the same; only the command changes.