[BUG] Session scratchpad silently wiped by macOS reboot and recreated empty on resume — agent gets no notification
Preflight Checklist
- [x] I have searched existing issues. Closest: #78475 (scratchpad root derived from TEMP; Windows TEMP sweep killed live sessions) and #77669 (scratchpad lost after a usage-limit idle; path moved to a new session UUID). This report documents a different, deterministic trigger — macOS clears
/private/tmpat every boot; the SAME session id is silently recreated empty on resume — and asks specifically for detection + a system message to the agent. - [x] This is a single bug report
- [x] I am using the latest version of Claude Code (2.1.226)
What's Wrong?
Each session gets a scratchpad at /private/tmp/claude-<uid>/<project-slug>/<session-id>/scratchpad. The system prompt tells the agent to keep all temporary files there and states "This directory already exists".
On macOS, /private/tmp is cleared on every boot. Desktop-app sessions survive reboots (they are resumed in place with the same session id), and on resume the harness silently recreates the scratchpad directory — empty. No system message, no error. The agent keeps believing its files exist until something fails downstream.
Real incident (2026-08, macOS 26.5.2). During a long session the agent wrote several HTML files to the scratchpad, built and published Artifacts from them, and served them with a local preview server. The Mac rebooted; the session was resumed. Later in the same session the scratchpad directory existed but was empty — discovered only when the preview server started returning 404. The sources had to be rebuilt from scratch. (They are in fact recoverable by mining the transcript JSONL for the Write calls or by re-fetching the published Artifact — but the agent gets no signal that it needs to.)
Live reproduction while preparing this report. The reporting session was started on 2026-08-16; the machine rebooted four times (2026-08-18, 2026-08-21 ×3); the session was resumed on 2026-08-22 with the same session id. Its scratchpad/ now has ctime = resume time and is empty, and a background-agent output file from 08-16 under the session's tasks/ directory is gone. Nothing in /private/tmp is older than the last boot.
Diagnosis notes:
- Claude Code itself does not delete anything; macOS does, at boot.
- Modern macOS (26.x) no longer ships the periodic 3-day
/tmpcleaner (/etc/periodicis absent), so the loss is deterministic on every reboot rather than "after 3 idle days". - Because the directory is recreated, "This directory already exists" stays technically true while the contents are gone.
What Should Happen?
Either
- the scratchpad lives somewhere that survives reboots for the session lifetime (e.g.
~/.claude/scratch/<session-id>, cleaned on session end/archive) — the same ask as #78475, item 2; or - the harness detects that the directory was recreated — write a sentinel file at session start, check it on resume / each turn — and injects a system message such as "Scratchpad was cleared (OS reboot at <time>); anything kept there must be re-created", so the agent can re-save before continuing.
(2) is cheap and would also cover the #77669 case and any third-party temp cleanup.
Steps to Reproduce
- Start a desktop-app session on macOS; have the agent write a file into the scratchpad path from its system prompt.
- Reboot the Mac; reopen the app and continue the same session.
- Ask the agent to read the file: the directory exists and is empty; neither the agent nor the user was warned.
Environment
- Claude Code 2.1.226, desktop app (macOS), model Claude Fable 5
- macOS 26.5.2 (Darwin 25.5.0, build 25F84)
- Scratchpad path:
/private/tmp/claude-<uid>/<project-slug>/<session-id>/scratchpad
Is this a regression?
I don't know