Prevent Claude Code Temp File Accumulation

Claude Code creates /tmp/claude-*-cwd files for directory tracking but never cleans them up. Over time, hundreds of files accumulate, consuming disk space and inodes.

The Problem

800+ temp files consuming 1.2GB (#8856)

A user ran ls /tmp/claude-* | wc -l and found 823 files. Each Claude Code session creates new files without deleting old ones. Over weeks, this fills the /tmp partition.

#8856 — 67 reactions

Disk full → .claude.json corruption

When /tmp fills up, Claude Code's config file (~/.claude.json) can become zero-length on the next write. This destroys all authentication tokens and project settings, requiring manual recovery.

Quick Check

# How many temp files do you have right now?
ls /tmp/claude-* 2>/dev/null | wc -l

# How much space?
du -sh /tmp/claude-* 2>/dev/null | tail -1

Fix: Auto-Cleanup on Session End

Install the temp-file-cleanup Stop hook:

npx cc-safe-setup --install-example temp-file-cleanup

This runs automatically when Claude Code exits, deleting temp files older than 1 hour (keeping files from concurrent sessions).

Manual Cleanup

# Delete all Claude temp files
find /tmp -maxdepth 1 -name "claude-*" -type f -delete

# Delete only old ones (safe for concurrent sessions)
find /tmp -maxdepth 1 -name "claude-*" -type f -mmin +60 -delete

Full safety setup in 10 seconds

npx cc-safe-setup

8 safety hooks + 655 examples. 9,200+ tests.

npx cc-health-check — 20-point diagnostic

Related Pages

Prevent rm -rf · Prevent force push · Prevent secret leaks · Prevent git reset --hard · Prevent syntax errors · Prevent dependency bloat

cc-safe-setup · 667 hooks · 9,200+ tests · GitHub

New: Hook if field — reduce overhead (v2.1.85)

Learn more: Production Guide · All Tools