[BUG] File Deletion (possibly) Due to Compact and/or Clear

Resolved 💬 3 comments Opened Oct 16, 2025 by codyollinger-cmd Closed Jan 8, 2026

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

I'm reporting a critical bug where files written successfully using the Write tool disappeared from the filesystem after running the /clear command, despite no explicit deletion operations being executed.

Quick Summary

  • Issue: Files written → verified present → ran /clear → files disappeared
  • Evidence: Conversation logs confirm successful writes, no deletion commands found
  • Impact: Data loss for user work product
  • Workaround: Files found intact in .claude/file-history/ backup

Environment

  • Claude Code v2.0.20
  • Sonnet 4.5 (claude-sonnet-4-5-20250929)
  • macOS (Darwin 25.0.0)

What Happened

  1. ✅ Wrote 2 markdown files (701 and 778 lines) to ~/cc-dev/learning/
  2. ✅ Conversation logs confirm: "Wrote 701 lines to learning/comprehensive-analysis.md"
  3. ✅ User verified files exist and opened them
  4. ❌ User ran /clear command
  5. ❌ Files disappeared from ~/cc-dev/learning/ directory
  6. ✅ Files found intact in .claude/file-history/d3110207-fbec-4553-b80d-ad7e398a8434/

Evidence

Successful Write (from logs):

⏺ Write(learning/comprehensive-analysis.md)
  ⎿  Wrote 701 lines to learning/comprehensive-analysis.md

⏺ Write(learning/HOW-TO-SETUP-GUIDE.md)
  ⎿  Wrote 778 lines to learning/HOW-TO-SETUP-GUIDE.md

No Deletion Found:
Searched all conversation logs - no delete/rm/unlink operations for these files.

Files in Backup:

$ ls -lt ~/.claude/file-history/d3110207-fbec-4553-b80d-ad7e398a8434/
-rw-r--r--  30479 Oct 16 13:04 1d993fae96c5cc65@v2  # HOW-TO (1271 lines)
-rw-r--r--  18273 Oct 16 13:04 7bb53f7837b5bf8a@v2  # Analysis (587 lines)

Files Missing:

$ ls ~/cc-dev/learning/
# comprehensive-analysis.md - MISSING
# HOW-TO-SETUP-GUIDE.md - MISSING

Not in Trash:
Files not found in macOS Trash.

Expected Behavior

The /clear command should only clear conversation history, NOT delete user files from the filesystem. Write operations should persist regardless of conversation state.

Reproduction Steps

  1. Start Claude Code in a directory
  2. Use Write tool to create files
  3. Verify files exist on disk
  4. Run /clear command
  5. Files disappear from original location
  6. Files remain in .claude/file-history/ backup only

Possible Causes

  1. /clear bug: Inadvertently cleaning up recent file operations
  2. File-history sync: Writes going to backup but not actual location
  3. Session cleanup: Aggressive cleanup on session termination
  4. Compaction side-effect: User ran /compact after writes

Impact

Severity: High

  • Data loss risk for any Write operations before /clear
  • User lost hours of work (recoverable from backup, but unexpected)
  • Undermines confidence in file persistence

Questions

  1. Is .claude/file-history/ the primary write location or just a backup?
  2. Should Write operations sync to filesystem before completing?
  3. Is there a known interaction between /clear and recent Writes?
  4. Are file cleanup hooks triggered by session end?

Workaround Used

Successfully restored files from backup:

cp ~/.claude/file-history/{session}/{hash}@v2 ~/cc-dev/learning/{filename}.md

Additional Info Available

I can provide:

  • Complete conversation logs
  • Full file-history backups
  • Screen recordings (if reproducible)
  • Additional diagnostic output

Session IDs:

  • Previous: efe1f091-7c47-4053-a099-f5302e327eb2
  • Issue: d3110207-fbec-4553-b80d-ad7e398a8434

Request

Please investigate why files written successfully disappear after /clear command. This creates data loss risk for users.

Full detailed bug report saved at: /Users/codyollinger/cc-dev/bug-report-file-deletion.md

Thank you for your time!

---

GitHub Issue Link: https://github.com/anthropics/claude-code/issues

What Should Happen?

The /clear command should only clear conversation history, NOT delete user files from the filesystem. Write operations should persist regardless of conversation state.

Error Messages/Logs

Steps to Reproduce

Reproduction Steps

  1. Start Claude Code in a directory
  2. Use Write tool to create files
  3. Verify files exist on disk
  4. Run /clear command
  5. Files disappear from original location
  6. Files remain in .claude/file-history/ backup only

Claude Model

Sonnet (default)

Is this a regression?

Yes, this worked in a previous version

Last Working Version

_No response_

Claude Code Version

2.0.20

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

Terminal.app (macOS)

Additional Information

_No response_

View original on GitHub ↗

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