Model ignores user-defined rules: rewrites existing code instead of reusing it

Resolved 💬 3 comments Opened Mar 29, 2026 by Bobushka Closed May 10, 2026

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:

  1. Written in CLAUDE.md
  2. Stored in persistent memory (feedback_no_rewrite_use_existing.md)
  3. Confirmed by the user multiple times across sessions
  4. 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)

  1. User had a working function _take_parse_screenshot() in batch_parse_service.py
  2. Instead of calling it, Claude decomposed screenshot.py into individual imports and reassembled them by hand — three times
  3. Claude opened two Chrome sessions per test instead of one, directly violating another explicit rule
  4. This burned a production Chrome profile on CIAN (anti-bot detection triggered)
  5. 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

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗