QuestionQ47

Claude Code Configuration & Workflows

Your team's CLAUDE.md includes a rule: "Use 4-space indentation and always run Prettier formatting." Despite this, code reviews reveal that roughly 30% of files Claude Code generates use inconsistent formatting — sometimes 2-space indentation, sometimes missing trailing commas.

Adding emphasis ("IMPORTANT: You MUST use Prettier formatting") reduces violations to about 15%, but doesn't eliminate them.

What is the most effective way to ensure all generated code is consistently formatted?

Explanation

A PostToolUse hook configured with an Edit|Write matcher runs automatically and deterministically after Claude writes or edits any file, invoking a formatter such as Prettier directly on the file path via a shell command. Because this enforcement happens outside the language model's generation process, it guarantees 100% consistent formatting regardless of what the model produces, unlike prompt-based instructions (CLAUDE.md rules, emphasis, rules files, or skills) which only influence generation probabilistically and can still be missed. A Stop hook with a prompt-based check is also unreliable since it still depends on an LLM evaluation and correction step rather than a deterministic tool invocation.

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!