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
- 19 GitHub Actions Runner Providers Benchmarked: Speed and Cost, Updated Weekly — DanielLockyer · 2026-11-30
- User says Grok agents killed his Gmail habit — Musk amplifies the agent-takes-over-email workflow — elonmusk · 2026-11-30
- open-daytona: rootless gVisor sandbox pool runs 1,536 concurrent agent-RL sandboxes on Slurm — victor_explore · 2026-11-30
- SteerCamp launches on iPhone: AI coworkers run cloud PCs while you approve on the go — pramodk73 · 2026-11-30
- Returning to Squad after 6 months: the agent OS feels far more mature — ayushtweetshere · 2026-11-30
- Indie dev vibe-codes a native iOS RSS app with 183 curated AI sources, awaiting TestFlight — vista8 · 2026-11-30