Enforce Code Style Rules in Claude Code via Python Hooks
chaumian · x · 2026-08-07
A developer shared a Python script acting as a Claude Code hook to enforce custom code style rules (STYLERULES.md).
Key mechanics of the script:
- Interception: Triggers scans on Stop events (reading the last assistant message) and PostToolUse events (Write, Edit, etc.).
- Banned Lexicon: Reads disallowed words or anti-patterns (like em dashes) from /.claude/bannedwords.txt.
- Blocking Mechanism: Blocks the response or file write with an exit 2 code and returns a violation list if non-compliant content is detected, forcing adherence.
- Path Skipping: Uses regex to bypass checks for specific paths like config files and memory bases.
More from coding & agent
- Perfect Pixel: Open-Source Tool to Refine AI Pixel Art into Aligned Grids — tom_doerr · 2026-08-07
- Enterprise Drops Copilot for Claude Code: Context Window Drives Migration — zephyr_z9 · 2026-08-07
- Snowflake Open-Sources Data Engineering Agent Benchmark — AlexGDimakis · 2026-08-07
- celld: Self-Hosted Distributed Durable Objects Slashing Cloud Costs — steren · 2026-08-07
- MindsDB Open-Sources Anton, a Self-Improving AI Coworker Agent — tom_doerr · 2026-08-07
- Agent Skills: Standardizing AI Agent Capabilities with SKILL.md Packaging — steren · 2026-08-07