Model ignores user-defined rules: rewrites existing code instead of reusing it
Bug: Model systematically ignores user-defined rules
Severity: Critical — causes real production damage
What happens
Claude Code ignores rules defined in CLAUDE.md and memory files. Specifically, the rule "search for existing code before writing new code" is violated repeatedly despite being:
- Written in CLAUDE.md
- Stored in persistent memory (
feedback_no_rewrite_use_existing.md) - Confirmed by the user multiple times across sessions
- Reinforced after each violation
The model generates new code from scratch instead of calling existing functions. This is not a one-time mistake — it is a systematic pattern.
Real damage caused (2026-03-29)
- User had a working function
_take_parse_screenshot()inbatch_parse_service.py - Instead of calling it, Claude decomposed
screenshot.pyinto individual imports and reassembled them by hand — three times - Claude opened two Chrome sessions per test instead of one, directly violating another explicit rule
- This burned a production Chrome profile on CIAN (anti-bot detection triggered)
- Multiple iterations wasted. User had to stop work and debug Claude's behavior instead of doing actual work.
Why this is critical
Rules and instructions are the only mechanism users have to control model behavior across sessions. If the model ignores them, users cannot trust it with autonomous work. The entire value proposition of Claude Code breaks down.
Adding more rules does not help — the model ignores those too. The user was forced to install a PreToolUse hook as a workaround to inject reminders before every Write/Edit. This is a hack compensating for a fundamental defect.
Expected behavior
When a user defines a rule (in CLAUDE.md, memory, or conversation), the model must follow it. "Search for existing code before writing new" means:
- grep/glob the project first
- Find the existing function
- Call it as-is
- Do NOT decompose it into parts and reassemble
Environment
- Claude Code CLI
- Model: claude-opus-4-6 / claude-sonnet-4-6
- Both models exhibit this behavior
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗