[BUG] Temp files (claude-*-cwd) not cleaned up on session exit
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
Claude Code creates temporary files named claude-{hash}-cwd in the system temp directory (%TEMP% on Windows, /tmp on Unix) to track the working directory for each session. These files are not cleaned up when sessions exit, leading to accumulation of thousands of orphaned temp files over time.
On my system (Windows 11), I found 1,988 leftover claude-*-cwd files in C:\Users\{username}\AppData\Local\Temp\ after several weeks of usage.
Each file is small (~25-84 bytes, containing just a path string), but the accumulation indicates a missing cleanup routine on session termination.
What Should Happen?
Claude Code should clean up its claude-*-cwd temp files when a session exits (either normally or abnormally). The cleanup should happen:
- On normal session exit
- On session crash/termination (via signal handlers or atexit hooks)
- Optionally: On startup, clean up stale cwd files from previous crashed sessions (files older than 24 hours)
Error Messages/Logs
Steps to Reproduce
- Start a Claude Code session:
claude - Run any command (e.g.,
echo "test") - Exit the session (Ctrl+C or
/exit) - Check your temp directory for
claude-*-cwdfiles:
- Windows:
dir %TEMP%\claude-*-cwd - Unix/macOS:
ls /tmp/claude-*-cwd
- Repeat steps 1-4 multiple times
- Observe that
claude-*-cwdfiles accumulate and are never cleaned up
To see the full extent of the issue:
# Windows (Git Bash)
find /c/Users/$USERNAME/AppData/Local/Temp -maxdepth 1 -name "claude-*-cwd" | wc -l
# macOS/Linux
find /tmp -maxdepth 1 -name "claude-*-cwd" | wc -l
Claude Model
None
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
1.0.33 (Claude Code)
Platform
Anthropic API
Operating System
Windows
Terminal/Shell
VS Code integrated terminal
Additional Information
_No response_
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗