anthropics / anthropics/claude-code

[BUG] Session scratchpad silently wiped by macOS reboot and recreated empty on resume — agent gets no notification

未关闭
#88,773 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
area:core bug has repro platform:macos
主要语言
Python
星标
145k
派生
23.1k
PR 合并指标
PR 指标待抓取

描述

### 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/tmp` at 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-///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 `/tmp` cleaner (`/etc/periodic` is 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

1. the scratchpad lives somewhere that survives reboots for the session lifetime (e.g. `~/.claude/scratch/`, cleaned on session end/archive) — the same ask as #78475, item 2; or
2. 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

(2) is cheap and would also cover the #77669 case and any third-party temp cleanup.

### Steps to Reproduce

1. Start a desktop-app session on macOS; have the agent write a file into the scratchpad path from its system prompt.
2. Reboot the Mac; reopen the app and continue the same session.
3. 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-///scratchpad`

### Is this a regression?

I don't know

贡献指南

这个仓库没有索引到贡献指南

调研方向

Start by tracing scratchpad creation and session-resume handling for the documented /private/tmp/.../scratchpad path. Reproduce the macOS reboot scenario from the listed steps, then determine whether the directory is recreated without its contents. Done means the harness either preserves the scratchpad for the session lifetime or detects the loss and delivers a system message before the agent continues.

由索引模型根据 Issue 内容生成。

评估

技术栈
macos, python
领域
operating-systems, tooling
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
活跃
描述清晰度
基本清楚
新手友好度
45/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。