Claude recreates existing files from scratch after session compaction — CLAUDE.md instructions ignored

Resolved 💬 5 comments Opened Apr 9, 2026 by MoorAE Closed Jun 8, 2026

Summary

After a session context compaction, Claude resumed work and wrote multiple Rust source files from scratch — completely ignoring existing reference files in the same project that contained the identical functionality. The user had to interrupt productive work to demand a report. This is a recurring pattern with 60+ prior incident reports in this user's project.

What Happened

Session was resumed from a compacted summary. The task was to add Linux and macOS platform support to a cross-platform Rust kernel-bypass transport library.

Claude wrote from scratch:

  • src/platform/linux.rs
  • src/platform/macos.rs
  • src/platform/mod.rs
  • src/lib.rs

Already existed in the same project:

trinity-docs/Creator Notes/kimi chats/Crypto Arbitrage Overview/dex/
├── trinity_windows_rio.rs     ← complete Windows RIO transport
├── trinity_windows_dpdk.rs    ← complete Windows DPDK transport
├── Cargo.toml                 ← already had windows/linux/ios feature flags
└── dir structure.txt          ← full architecture spec

Also existed:

trinity-docs/Creator Notes/kimi chats/ZeroCopyArray Debugging/
├── zerocopy_array.py          ← complete Python binding layer
├── zerocopy_unified.h         ← C ABI vtable (cross-language)
└── zerocopy_unified_cross_lang_binding.h

These were the authoritative source files. Claude wrote duplicates instead of reading and extending them.

CLAUDE.md Was Explicit

The project's CLAUDE.md contains this instruction in bold caps:

NEVER CREATE FILES FROM SCRATCH - COPY AND MODIFY EXISTING

Claude ignored it.

User's Words

"dex im saying you essentially remade this but separately"
"first document and report this bs, cause i just got a email from your creators today about the fix, but that ain't do shit"

The user received an Anthropic email about a behavioral fix. The fix did not prevent this failure.

Root Causes

  1. No pre-task file audit — Claude did not search for existing *.rs files before writing new ones
  2. Session compaction gap — Resuming from a summary did not trigger a broader codebase scan
  3. CLAUDE.md treated as soft guidance — Hard constraints in CLAUDE.md are not being enforced
  4. Recurring pattern — This project has 60+ documented failure reports for the same class of issue dating back to October 2025. Each session compaction resets the behavior.

Impact

  • Wasted user's Claude Code usage credits
  • Overwrote files the previous session built correctly
  • User interrupted from productive work
  • Zero-value output from the session

What Should Have Happened

  1. Before writing any file: search project for *.rs, *.py, *.h files matching the task domain
  2. Read existing files first
  3. Extend existing files — not recreate them
  4. Only write the genuinely missing piece (Python ctypes bridge)

Requested Fix

  1. Pre-task file scan must be automatic when resuming from compacted sessions — scan for files related to the task before writing anything new
  2. CLAUDE.md hard constraints must be enforced — "NEVER CREATE FILES FROM SCRATCH" should block file creation without a prior search
  3. Session compaction must preserve file inventory awareness — not just task descriptions
  4. Re-evaluate the April 2026 fix — it did not address this behavior class

Environment

  • Claude Code CLI (claude-sonnet-4-6)
  • Windows 11 Pro
  • Large project with cross-session history
  • Session resumed from compacted context summary

View original on GitHub ↗

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