[BUG] Claude Code's Write tool stores files in ~/.claude/sessions/ which are then silently deleted by Claude Code's own cleanup
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?
Claude Code's own Write tool happily writes .md files to ~/.claude/sessions/. There is no warning, no restriction, and no documentation that this directory is internally managed. Claude Code then silently deletes those files through its cleanup process.
In my case, a custom /sessions skill (created by Claude Code itself) stored session log markdown files in ~/.claude/sessions/ for months. Over ~196 session logs were written there between October 2025 and March 2026 — post-session reflections with quality ratings, root cause analyses, key decisions, and lessons learned. All of them were silently deleted. Only 17 were recoverable from JSONL transcript history. The rest are permanently lost.
The irony: Claude Code chose ~/.claude/sessions/ as the storage path when building the skill. It was never flagged as an internal directory. No warning was shown during any of the ~196 Write operations.
Root Cause
Two interacting issues:
- No guardrails on Write tool paths. The Write tool allows writing to any path under
~/.claude/without warning that some subdirectories are internally managed and subject to cleanup.
cleanupPeriodDaysdeletes more than documented. The documentation says it affects "sessions inactive for longer than this period." In practice, files placed in~/.claude/sessions/by the Write tool are also affected. My setting wascleanupPeriodDays: 7, which compounded the default behavior.
What Should Happen
- The Write tool should warn or refuse when writing to internally managed directories (
~/.claude/sessions/,~/.claude/cache/,~/.claude/file-history/). - The documentation should explicitly list which
~/.claude/subdirectories are safe for user files and which are internally managed. cleanupPeriodDaysshould not delete files it didn't create. User-placed files in managed directories should be preserved, or at minimum the directory's managed status should be documented.
Related Issues
- #22547 — [BUG] data loss through bad default settings (high-priority)
- #15935 — [Bug] Project files deleted despite cleanupPeriodDays set to 1825
- #16970 — [BUG] claude is losing chat history
Steps to Reproduce
- Have Claude Code create a skill that writes
.mdfiles to~/.claude/sessions/ - Use the skill multiple times over months
- Observe that files disappear silently over months without any warning or notification
- No warning is shown at any point
Error Messages/Logs
No errors. Files are silently deleted. The Write tool reports "File created successfully"
every time. The cleanup produces no user-visible output.
Claude Model
Opus (claude-opus-4-6)
Is this a regression?
No, this never worked
Last Working Version
_No response_
Claude Code Version
2.1.76
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
Terminal.app (macOS)
Additional Information
Impact: ~179 session log files permanently destroyed over ~5 months (October 2025 – March 2026). Months of curated reflections, failure analyses, and decision records. 17 partially recovered from JSONL history. The remaining ~162 are unrecoverable — the JSONL transcripts containing the Write tool calls were also deleted by cleanupPeriodDays.
Workaround: Store user files in ~/.claude/session-logs/ or any other directory not managed by Claude Code internally.
This issue has 5 comments on GitHub. Read the full discussion on GitHub ↗