Session scratchpad directory is derived from TEMP — live session state gets destroyed by routine temp-directory cleanup
Summary
Claude Code places each session's scratchpad directory (announced in the system
prompt as "Scratchpad Directory") under the TEMP environment variable's root
($TEMP/claude/<project-slug>/<session-id>/scratchpad). There is no way to set
the scratchpad root independently — changing TEMP in the settings env block
moves the scratchpad with it (verified empirically on Windows, 2026-07-17).
This is a state-lifetime mismatch: TEMP culturally and operationally means
"safe to delete anytime," while a session scratchpad holds live, sometimes
irreplaceable working state for the duration of a session (hours).
Real incident (2026-07-16, Windows 11, multi-session machine)
A machine running several concurrent Claude Code sessions had one session run a
disk-space cleanup that swept $env:TEMP (a routine, reasonable-looking act).
Because all sessions' scratchpads live under that root, two other live
sessions lost active git worktrees with uncommitted work mid-session. Recovery
was only possible because the affected sessions' edits still existed in their
conversation contexts; a session further from its edits would have lost work
irrecoverably. Root-cause analysis with timestamps available on request.
Ask
Any one of these would resolve it:
- An env var (e.g.
CLAUDE_CODE_SCRATCHPAD_DIR) or settings key setting the
scratchpad root independently of TEMP/TMP; or
- Defaulting the scratchpad root to a non-TEMP location (e.g. under the config
dir, like ~/.claude/scratch/<session-id>), keeping genuinely disposable
tool temp in TEMP.
Prior art
#17936, #45745, #17996 asked for adjacent temp-dir configurability and were
closed "not planned." This issue's distinction: it is not a convenience ask —
it documents data loss caused by the current coupling, on the default
configuration, triggered by ordinary system hygiene. #18197 / #21248 / #21602
(temp-file location/leak discussions) are adjacent context.
Environment
Claude Code on Windows 11 (PowerShell tool), settings-levelenv.TEMP/env.TMP overrides in use; behavior reproduced with fresh sessions
on 2026-07-17.