CLI leaves orphaned `.claude.json.tmp.<pid>.<hash>` files when terminated during config write

Status Closed — not planned
Maintainer reply None cached
Activity 1 comment · opened Aug 25, 2026 · closed Aug 25, 2026

On a headless server running Claude Code as a long-lived systemd service, I found six orphaned ~/.claude.json.tmp.<pid>.<hash> files (~50 KB each). None of the PIDs exist anymore.

The timestamps show a clear pattern — five of the six match the exact moment our nightly CLI auto-update restarts the service, the sixth matches a watchdog restart during a network outage:

.claude.json.tmp.3883883.*  Aug 19 03:38   (nightly update restart)
.claude.json.tmp.574235.*   Aug 20 03:44   (nightly update restart)
.claude.json.tmp.1413420.*  Aug 21 03:45   (nightly update restart)
.claude.json.tmp.169897.*   Aug 23 03:43   (nightly update restart)
.claude.json.tmp.2532046.*  Aug 25 03:32   (nightly update restart)
.claude.json.tmp.2588692.*  Aug 25 10:06   (watchdog restart during outage)

So the CLI appears to write ~/.claude.json atomically (tmp file + rename), and when the process is terminated between the write and the rename, the tmp file is orphaned. Nothing ever cleans these up — they accumulate indefinitely (~50 KB per restart-during-write). Minor, but it adds up on flash storage and on any setup that restarts the CLI on a schedule.

Suggestion: garbage-collect stale .claude.json.tmp.* files on startup (older than a day and PID no longer running), or write the tmp file in a location that is cleaned automatically.

Environment: claude-code 2.1.243 (also seen on earlier versions per the dates above), Ubuntu Server 26.04, headless systemd service. We work around it server-side with a nightly cleanup of >1-day-old tmp files with dead PIDs.

View original on GitHub ↗

This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗