[BUG] File Deletion (possibly) Due to Compact and/or Clear
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
- ✅ Wrote 2 markdown files (701 and 778 lines) to
~/cc-dev/learning/ - ✅ Conversation logs confirm: "Wrote 701 lines to learning/comprehensive-analysis.md"
- ✅ User verified files exist and opened them
- ❌ User ran
/clearcommand - ❌ Files disappeared from
~/cc-dev/learning/directory - ✅ 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
- Start Claude Code in a directory
- Use Write tool to create files
- Verify files exist on disk
- Run
/clearcommand - Files disappear from original location
- Files remain in
.claude/file-history/backup only
Possible Causes
/clearbug: Inadvertently cleaning up recent file operations- File-history sync: Writes going to backup but not actual location
- Session cleanup: Aggressive cleanup on session termination
- Compaction side-effect: User ran
/compactafter 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
- Is
.claude/file-history/the primary write location or just a backup? - Should Write operations sync to filesystem before completing?
- Is there a known interaction between
/clearand recent Writes? - 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
- Start Claude Code in a directory
- Use Write tool to create files
- Verify files exist on disk
- Run
/clearcommand - Files disappear from original location
- 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_
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗