Claude Code intermittently skips mandatory quality gates defined in CLAUDE.md and rules files
Bug Description
Claude Code (Opus 4.6) intermittently fails to follow mandatory quality gate rules defined in user rule files (~/.claude/rules/*.md) and project CLAUDE.md, even when those rules are loaded into context at session start.
Specific Failure
Rule: After completing code changes, run linting (pre-commit run --all-files) and formatting (ruff format) before presenting work as complete.
What happened: Twice in the same session, Claude Code completed implementation work, ran pytest for verification, then presented results as "ready for feedback" — without running the mandatory lint/format quality gate. The rules are defined in:
~/.claude/rules/constitution.md→ Quality Gates section (explicit checklist)- Project
CLAUDE.md→ Commands section (explicitmake lint/make formatcommands) ~/.claude/rules/code-quality.md→ references ruff formatting
All three files were confirmed loaded at session start.
Expected Behavior
When rules files define mandatory post-implementation quality gates (lint, format, pre-commit), Claude Code should execute them as part of the verification step before claiming work is complete — every time, not intermittently.
Environment
- Model: Claude Opus 4.6 (
eu.anthropic.claude-opus-4-6-v1) - Platform: macOS Darwin 25.3.0
- Claude Code version: Latest as of 2026-03-02
- Rules loaded:
~/.claude/rules/constitution.md,code-quality.md,testing.md,workflow.md,learnings-behavioral.md+ projectCLAUDE.md
Reproduction
- Set up
~/.claude/rules/with a constitution that includes explicit quality gates (lint, format, pre-commit) - Ask Claude Code to implement a multi-file code change
- Observe that pytest runs but lint/format steps are skipped
- This is intermittent — sometimes the gates are followed, sometimes not
Impact
- Trust erosion: users define rules precisely because they need consistent enforcement
- Defeats the purpose of customizable rules if compliance is probabilistic
- Requires users to manually verify every step, negating the automation benefit
Suggested Investigation Areas
- Are rules files losing priority when the context window fills up or compresses?
- Is there a token budget issue where longer sessions cause rule adherence to degrade?
- Could a "mandatory checklist" mechanism (vs. freeform prose rules) improve compliance?
🤖 Generated with Claude Code
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗