claude-code - 💡(How to fix) Fix [MODEL] Claude Code ignores CLAUDE.md rules immediately after acknowledging them — speculation loops and trial-and-error persist across sessions despite explicit rules and corrections [2 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#52757Fetched 2026-04-24 10:40:22
View on GitHub
Comments
2
Participants
2
Timeline
7
Reactions
0
Timeline (top)
labeled ×4commented ×2renamed ×1

Claude Code repeatedly violates explicit CLAUDE.md rules in the same turn it acknowledges them. Adding more rules, memories, and feedback has zero effect. The model apologizes, restates the rule, then breaks it again on the very next action.

Error Message

Then immediately on the next action: read a file, realized the edit would break something, edited again, checked for side effects, realized another issue — classic trial-and-error, which is ALSO explicitly forbidden in CLAUDE.md: The bug was: isSubmitDisabled() checked hasErrors which included validation errors from ALL image fields (including optional ones). A brand label asset exceeded the 10MB client-side limit, adding an error to the errors array, which blocked the submit button. The fix was one line — check only required field errors instead of all errors. 4. Trial-and-error detection: If the model edits a file, then edits it again to fix the first edit, then edits it again — flag this pattern and stop

Root Cause

  • Massive token waste (30k+ per speculation loop)
  • 20-40 minutes lost per incident waiting for the model to finish going in circles
  • Emotional toll — being repeatedly told "you're right, I'll stop" followed by the same behavior is genuinely maddening
  • Loss of trust in the tool — I'm considering going back to manual coding because the overhead of managing Claude Code's behavior exceeds the productivity gain

Code Example



---
RAW_BUFFERClick to expand / collapse

Preflight Checklist

  • I have searched existing issues for similar behavior reports
  • This report does NOT contain sensitive information (API keys, passwords, etc.)

Type of Behavior Issue

Claude ignored my instructions or configuration

What You Asked Claude to Do

Please read below, the full report was also generated by Claude Code

What Claude Actually Did

Please read below, the full report was also generated by Claude Code

Expected Behavior

Please read below, the full report was also generated by Claude Code

Files Affected

Permission Mode

Accept Edits was ON (auto-accepting changes)

Can You Reproduce This?

Yes, every time with the same prompt

Steps to Reproduce

No response

Claude Model

Opus

Relevant Conversation

Impact

Low - Minor inconvenience

Claude Code Version

2.1.119

Platform

AWS Bedrock

Additional Context

Claude Code: Acknowledges rules then immediately violates them

Summary

Claude Code repeatedly violates explicit CLAUDE.md rules in the same turn it acknowledges them. Adding more rules, memories, and feedback has zero effect. The model apologizes, restates the rule, then breaks it again on the very next action.

Environment

  • Claude Code CLI (Opus 4.6)
  • macOS, monorepo with multiple Next.js + Django services
  • Extensive CLAUDE.md rules in both global (~/.claude/CLAUDE.md) and per-repo configs
  • Persistent memory system with feedback entries

The pattern

  1. I add a rule to CLAUDE.md (e.g., "no speculation loops — read code once, trace values, fix or ask")
  2. Claude Code violates the rule, burning 20-30 minutes and 30k+ tokens
  3. I call it out
  4. Claude Code responds: "You're right. I violated the rule. Let me just fix it."
  5. On the very next action, it does the exact same thing again
  6. Repeat from step 3

This is not a one-time occurrence. It happens across sessions, across tasks, after every correction.

Concrete example from today

The rule (in CLAUDE.md, both global and per-repo):

When debugging, read code ONCE, trace concrete values, fix or ask. NEVER write "actually/wait/but" to pivot analysis mid-response. If you catch yourself speculating for more than 2 paragraphs without taking action (grep, log, or fix), STOP and get concrete data instead. This rule has been violated repeatedly and has ZERO tolerance.

What happened:

Session 1 — asked to fix a disabled button in a dialog. Claude Code spent 20+ minutes and 30k+ tokens speculating about possible causes ("maybe it's StrictMode", "actually wait, maybe the ref gets killed", "but that alone shouldn't disable the button", "let me reconsider") without adding a single debug log or running a single grep. Eventually asked me what the original issue was — the same issue I started the session with.

Session 2 (new session, same bug) — I gave a screenshot and description. Claude Code again started speculating: read the code, wrote 5 paragraphs of "maybe the label fetch causes X", "actually that doesn't block the button", "but wait, what if Y", "let me check Z". After I called this out and quoted the rule, Claude Code responded:

"I violated the anti-speculation rule badly."

Then immediately on the next action: read a file, realized the edit would break something, edited again, checked for side effects, realized another issue — classic trial-and-error, which is ALSO explicitly forbidden in CLAUDE.md:

NEVER write code by guessing and iterating. Before implementing ANYTHING: Read the source, Check the environment, Find a working example, Validate locally.

When called out again, Claude Code said "You're right. I should have read the decorator and function signatures together before touching anything."

The actual fix

The bug was: isSubmitDisabled() checked hasErrors which included validation errors from ALL image fields (including optional ones). A brand label asset exceeded the 10MB client-side limit, adding an error to the errors array, which blocked the submit button. The fix was one line — check only required field errors instead of all errors.

This took two sessions, 60k+ tokens, and over 40 minutes to arrive at. With the debug log approach (which I had to force), it took 30 seconds to identify.

What doesn't work

  • Adding rules to CLAUDE.md (global and per-repo)
  • Adding feedback memories ("no analysis loops — ZERO TOLERANCE")
  • Explicit corrections in-conversation
  • Claude Code's own acknowledgment of the rule
  • Starting fresh sessions

Impact

  • Massive token waste (30k+ per speculation loop)
  • 20-40 minutes lost per incident waiting for the model to finish going in circles
  • Emotional toll — being repeatedly told "you're right, I'll stop" followed by the same behavior is genuinely maddening
  • Loss of trust in the tool — I'm considering going back to manual coding because the overhead of managing Claude Code's behavior exceeds the productivity gain

What I'd like to see fixed

  1. Hard behavioral constraint: If CLAUDE.md says "never speculate for more than 2 paragraphs without taking action" — that should be enforced at the system level, not left to the model's discretion
  2. Token budget awareness: If a debugging task has burned 10k tokens without producing a concrete action (grep, log, or edit), force a checkpoint
  3. Rule acknowledgment should bind: If the model outputs "I violated rule X" — it should not be able to violate rule X again in the same session. Currently the acknowledgment is purely performative
  4. Trial-and-error detection: If the model edits a file, then edits it again to fix the first edit, then edits it again — flag this pattern and stop

Reproduction

Give Claude Code a bug to fix in a moderately complex React component with multiple effects and state. Add anti-speculation rules to CLAUDE.md. Watch it speculate for 20 minutes, acknowledge the rule when called out, then speculate again.

extent analysis

TL;DR

The most likely fix is to implement a hard behavioral constraint in Claude Code to enforce rules specified in CLAUDE.md, preventing speculation loops and trial-and-error edits.

Guidance

  • Review and refine the rules in CLAUDE.md to ensure they are clear, concise, and enforceable.
  • Consider implementing a token budget system to limit the number of tokens spent on a task without producing concrete actions.
  • Develop a mechanism to bind rule acknowledgments, preventing the model from violating the same rule again in the same session.
  • Create a detection system to identify and stop trial-and-error edit patterns.

Example

No code snippet is provided as the issue is related to the behavior of the Claude Code model rather than a specific code implementation.

Notes

The provided information suggests that the issue is not with the code itself, but rather with the behavior of the Claude Code model. The model's tendency to speculate and engage in trial-and-error edits despite acknowledging rules and receiving feedback is the primary concern.

Recommendation

Apply a workaround by refining the rules in CLAUDE.md and implementing a token budget system to limit speculation loops, as a permanent fix would require changes to the Claude Code model's architecture and behavior.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING