DEV Community

eyesofish
eyesofish

Posted on

After a Delete, I Kill the Session

Problem

The longer a Claude Code session runs, the worse the model’s judgment gets. Anthropic calls it “context rot.” In one dissected 70 MB session dump, 93 % was noise: redundant JSON envelope metadata, stale tool results, old base64 screenshots. Only 3 % was actual conversation.

Clouded judgment while editing yields messy diffs. During deletions, it can destroy the project. Incident reports: December 2025, a user saw Claude run rm -rf … ~/ where the trailing ~/ expanded to the entire home directory. October 2025, another user watched rm -rf / execute from root; only file permissions saved the system. Deletion risk isn’t linear—it’s explosive.

My hard rule: if a session has ever run a delete command, I kill it and start fresh.

Approach

Instead of just exiting, I first ask the model to summarize where we are—what we’ve built, what’s left, key decisions. Then I run /compact. /compact compresses hundreds of messages into a short summary; the signal survives, the noise is dropped.

After that, I start a new session and feed it the summary. Fresh context means the model’s full attention is available. It won’t confuse “delete that config file” with “delete the project root.”

Many already adopt a plan‑then‑new‑session workflow. I make the trigger explicit: if a session has been in YOLO mode and a remove command has been issued, I start a new conversation. No exceptions.

Implementation

The steps:

  1. After any delete operation (file, directory, rm, etc.), ask the model: Summarize the current state of the project. What have we accomplished? What remains? Note any decisions or open questions.
  2. Run /compact to distill the session into a high‑signal, compact context.
  3. Start a fresh Claude Code session and paste the summary as the initial prompt.

It takes a couple of minutes and drives the risk of destructive misjudgment close to zero.

This practice aligns with Anthropic’s five‑pronged context‑rot strategy: /rewind (roll back), /clear (wipe), /compact (compress), subagents (isolate tasks), and Continue (pick up where you left off with less noise). Combining /compact with a manual fresh start is essentially Continue with an explicit summary handoff.

The community agrees this is a pain point: Cozempic, an open‑source context‑pruning tool, has 35,000+ users and offers 18 pruning strategies across three tiers.

Results

I can’t quantify “fewer catastrophic deletions,” but the mechanism is sound. /compact strips away over 90 % of the noise. A fresh session eliminates residual context confusion—the model sees only the essential summary, not thousands of stale tool outputs. In a long‑running session, “delete that test file” might match a dozen paths the model saw earlier; a fresh session has no such memory.

Editing risk is linear: mess up one file, you lose one file; git diff catches it. Deletion risk is exponential—one command can destroy the entire project. Treating them the same is a mistake.

Lessons learned

  • Context rot is measurable and dangerous. A 70 MB session dump can be 93 % noise.
  • Deletion commands in long‑running sessions are the highest‑risk moment. The 2025 incidents show that even with guardrails, YOLO mode can issue rm -rf ~/ or rm -rf /.
  • Session hygiene is a necessary workaround for a fundamental architecture limitation. Anthropic’s official strategy and community tools like Cozempic confirm this.
  • The “plan‑then‑new‑session” pattern is already widespread. Making “delete” an explicit trigger formalizes a sensible boundary.

Top comments (0)