Enforce Code Style on Claude Code Using Hooks
abemedia · reddit · 2026-08-29
The author introduces a method to enforce code style in Claude Code using hooks instead of relying on CLAUDE.md advice. By using a Stop hook that runs linters/formatters and feeding back errors via stderr (exit code 2), Claude automatically fixes its own code before showing the diff.
The author uses stagelint, a file-routing tool, to map file globs to specific commands (Prettier, ESLint, Ruff, etc.). Configuration involves setting up .stagelint.yml for rules and adding a hook command in .claude/settings. targeting unstaged changes.
While PostToolUse hooks offer faster feedback, the Stop hook is preferred to avoid stale states and redundant full-project checks like tsc.
More from coding & agent
- How to hook Claude Code or Codex up to iMessage in 3 steps — jacob_posel · 2026-10-16
- Are the fastest GPU kernels now written by AI? Kernels are hyper-verifiable, argues one dev — fleetwood___ · 2026-10-16
- Anthropic lead engineer's 4-question prompt makes agents more ambitious, now a free skill — daniel_mac8 · 2026-10-16
- ChainForge dev shows 'feature map' for orchestrating subagents on large PRs — IanArawjo · 2026-10-16
- aiDotEngineer benchmarks agent orchestration pipelines, staging humans as Foreman and workers — vikvang1 · 2026-10-16
- Developer mass-produces 200 videos in hours using Claude Code + Hyperframes — mcraddock · 2026-10-16