Skip to content

Opus 4.6 (1M): Model regularly attempts Edit/Write on files it hasn't Read — harness-level enforcement needed #27790

Closed as not planned

Description

@karljtaylor

TL;DR

Opus 4.6 with 1M context systematically edits files without reading them first. We deployed a Haiku-based PreToolUse hook that validates read-before-edit and it fires on a significant percentage of edit attempts — confirming this is a model-level behavior pattern, not user error. A harness-level check in Claude Code would eliminate this at near-zero cost.

The behavior

In multi-file coding tasks, Opus 4.6 (1M) regularly:

  1. Edits files it hasn't read — attempts Edit or Write on files not previously fetched via Read in the conversation
  2. Writes duplicates — creates new implementations without searching for existing ones
  3. Skips verification — declares completion without running tests or re-reading modified files
  4. Cascading corrections — each fix introduces new bugs because surrounding context isn't re-read

This produces a ratchet effect where each iteration degrades the codebase further.

Reproduction

The pattern is most reliably triggered with:

  • A task involving 3+ interdependent files
  • An existing codebase (not greenfield)
  • Opus 4.6 with 1M context in Claude Code

Minimal example:

Project has src/api.py (imports from src/utils.py) and tests/test_api.py.
Ask: "Add input validation to the create_user endpoint"

Expected: Read api.py → Read utils.py → Read test_api.py → Plan → Edit → Run tests
Actual: Edit api.py (without reading) → Break import → Fix import (without reading utils.py) → Create duplicate validation function

We don't have a standalone script that triggers this deterministically — the behavior is stochastic but frequent enough that our PreToolUse hook catches it regularly across normal development work.

Evidence: PreToolUse hook as instrumentation

We deployed a Haiku-based PreToolUse prompt hook on Edit|Write that checks whether the agent read the target file before attempting the edit. Configuration:

{
  "PreToolUse": [{
    "matcher": "Edit|Write",
    "hooks": [{
      "type": "prompt",
      "prompt": "Did the agent Read the target file before this edit? If not, return {\"ok\": false}.",
      "model": "haiku"
    }]
  }]
}

Key finding: The hook blocks edits regularly across normal development sessions. This means Opus 4.6 is systematically attempting to modify files it hasn't read — a $0.001 Haiku call catches what the main model's reasoning does not.

We also deployed a Stop hook that checks for premature completion (claiming work is "pre-existing" or "out of scope"). This also fires in a non-trivial percentage of sessions.

This is not isolated

Timeline correlation

Our observed onset (Feb 20-21) coincides with Claude Code v2.1.43–v2.1.50 shipping in 4 days (Feb 17-20) alongside the Sonnet 4.6 launch. We cannot isolate which specific change caused the regression.

Suggested fix

Built-in read-before-edit enforcement at the harness level.

Claude Code's system prompt already says "read files before editing." The model regularly violates this. A harness-level check — has this file path appeared in a Read tool response in this conversation? — before allowing Edit or Write would:

  • Eliminate the most common failure pattern
  • Cost effectively nothing (string comparison, no API call)
  • Be consistent with Claude Code's existing "You must use your Read tool at least once before editing" instruction
  • Not require model-level changes

This is the single highest-impact, lowest-cost fix available. Our Haiku-based hook proves the approach works, but a native harness check would be faster and free.

Additional suggestions (may require model-side changes, noting for visibility):

  • Context-aware effort scaling: /effort high at 50K context behaves very differently than at 800K. The deliberation budget may need to scale with loaded context.
  • alwaysThinkingEnabled helps but doesn't fully resolve — suggesting the issue is upstream of extended thinking.

Environment

  • Claude Code v2.1.50+
  • Model: claude-opus-4-6 (1M context)
  • macOS Darwin 24.6.0
  • Workload: Multi-file Python/TypeScript, infrastructure automation

Activity

  1. github-actions commented on Feb 23, 2026

    @github-actions

    Found 3 possible duplicate issues:

    1. [BUG] Model attempts file edits without reading file first, wasting tokens and time #16546
    2. Claude Code implements speculative fixes without verifying root cause #23833
    3. [Bug] Claude Code: Cascading Diagnosis Failures with Unverified Fixes in Dependency Migration #27689

    This issue will be automatically closed as a duplicate in 3 days.

    • If your issue is a duplicate, please close it and 👍 the existing issue instead
    • To prevent auto-closure, add a comment or 👎 this comment

    🤖 Generated with Claude Code

  2. karljtaylor commented on Feb 23, 2026

    @karljtaylor
    Author

    three issues speaks to the severity of the issue.

    #16546 reports the same symptom but proposes no fix.

    This issue provides instrumented evidence via a PreToolUse hook and a specific harness-level enforcement proposal (string comparison on Read history before Edit/Write).

    The data and proposed solution are novel.

  3. github-actions commented on Mar 23, 2026

    @github-actions

    Closing for now — inactive for too long. Please open a new issue if this is still relevant.

  4. github-actions commented on Mar 31, 2026

    @github-actions

    This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.

  5. locked as resolved and limited conversation to collaborators on Mar 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    staleIssue is inactive

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions