[BUG] Claude code leaves temp files
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?
Bug: Claude Code leaves tmpclaude-*-cwd temporary files in working directory
Description
Claude Code creates temporary files named tmpclaude-{hash}-cwd in the current working directory during normal operation but fails to clean them up after execution completes. These files accumulate over time and require manual deletion.
Steps to Reproduce
- Use Claude Code normally with bash operations in a project directory
- After multiple sessions/operations, check the working directory
- Find multiple
tmpclaude-*-cwdfiles remaining in the directory
Expected Behavior
Temporary files created by Claude Code should be automatically cleaned up when:
- The operation completes successfully
- The operation fails/errors
- The Claude Code session ends
Temporary files should ideally be created in the system's temp directory (e.g., /tmp on Unix, %TEMP% on Windows) rather than the working directory.
Actual Behavior
Files like tmpclaude-448e-cwd, tmpclaude-8b98-cwd, etc. are left in the working directory and persist indefinitely. The files contain the working directory path.
Example file content:
/c/Users/dravo/Desktop/ASGARD/GitHub repo/JSUR-ASGARD/asgard
Impact
- Clutters the working directory with unnecessary files
- Risk of accidentally committing these files to version control
- Requires manual cleanup after each session
- Unprofessional when working in shared repositories
Environment
- OS: Windows (win32)
- Claude Code Model: claude-sonnet-4-5-20250929
- Project Type: Git repository
- Date Observed: January 2026
Workaround
Added the following to .gitignore:
# Claude Code temporary files
tmpclaude-*-cwd
claudetmp*
Manual deletion required:
rm tmpclaude-*-cwd
Suggested Fix
- Use system temp directory instead of working directory for temporary files
- Implement proper cleanup in finally blocks or exit handlers
- Add a cleanup routine that runs on session end
- Consider using language-specific temp file utilities that auto-delete (e.g., Python's
tempfile.TemporaryFile())
Additional Context
This issue has been occurring consistently across multiple sessions. In one session, 5 temporary files were found accumulated over time.
What Should Happen?
..there should be no temp files left behind?
Error Messages/Logs
Steps to Reproduce
I just run claude normally, tried reloading claude, rebooting etc.
Claude Model
Sonnet (default)
Is this a regression?
Yes, this worked in a previous version
Last Working Version
2.1.5
Claude Code Version
2.1.5
Platform
Anthropic API
Operating System
Windows
Terminal/Shell
PowerShell
Additional Information
No response
Found 3 possible duplicate issues:
- https://github.com/anthropics/claude-code/issues/17609
- https://github.com/anthropics/claude-code/issues/17568
- https://github.com/anthropics/claude-code/issues/17600
This issue will be automatically closed as a duplicate in 3 days.
- If your issue is a duplicate, please close it and 👍 the existing issue instead
- To prevent auto-closure, add a comment or 👎 this comment
🤖 Generated with Claude Code
+1
Plus one.
+1
Output from CC when I asked it to find the problem and give a report:
"Root cause: This is a bug in Claude Code 2.1.5 on Windows. The sandbox creates temp files to track the working directory when running Bash commands (using Git Bash), but fails to clean them up after each use. The /c/... path format confirms Git Bash is being used.
What I did:
- Deleted all 155 temp files
Workaround until the bug is fixed: Periodically clean them up with: Remove-Item '\tmpclaude-*-cwd' -Force
Or add this to a startup script if they become a nuisance.
You should report this bug to the Claude Code team at https://github.com/anthropics/claude-code/issues with:
- Version: 2.1.5
- Platform: Windows 11 Pro
- Shell: Git Bash (MINGW)
- Issue: tmpclaude-*-cwd sandbox temp files not cleaned up after Bash tool execution"
+1
Good lord please fix this... I had an epic session yesterday that would have filled my drive with these files if I had not been cleaning up as I went.
I am not sure which patch release did it but as of 2.1.14, this issue appears to be fixed. For me at least... :D
A Stop hook can automatically clean up these temp files when the session ends:
#!/bin/bash
# ~/.claude/hooks/temp-file-cleanup.sh
# Runs on Stop event — cleans up tmpclaude-*-cwd files
# Clean up in current directory
find . -maxdepth 1 -name "tmpclaude-*-cwd" -type f -delete 2>/dev/null || true
# Also clean up stale files in /tmp (older than 1 hour)
find /tmp -maxdepth 1 -name "tmpclaude-*" -type f -mmin +60 -delete 2>/dev/null || true
# Clean up .claude-tmp-* files too
find . -maxdepth 1 -name ".claude-tmp-*" -type f -delete 2>/dev/null || true
exit 0
{
"hooks": {
"Stop": [
{
"hooks": [{ "type": "command", "command": "bash ~/.claude/hooks/temp-file-cleanup.sh" }]
}
]
}
}
This runs every time the session ends (whether by user, error, or normal completion) and removes all tmpclaude-*-cwd and .claude-tmp-* files. The /tmp cleanup only targets files older than 60 minutes to avoid removing files from still-active sessions.
This is a duplicate of #17600, which was fixed as of version 2.1.47.
This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.