[BUG] Temp files (claude-*-cwd) not cleaned up on session exit

Resolved 💬 2 comments Opened Jan 13, 2026 by mosesgonzales Closed Feb 27, 2026

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:

  1. On normal session exit
  2. On session crash/termination (via signal handlers or atexit hooks)
  3. Optionally: On startup, clean up stale cwd files from previous crashed sessions (files older than 24 hours)

Error Messages/Logs

Steps to Reproduce

  1. Start a Claude Code session: claude
  2. Run any command (e.g., echo "test")
  3. Exit the session (Ctrl+C or /exit)
  4. Check your temp directory for claude-*-cwd files:
  • Windows: dir %TEMP%\claude-*-cwd
  • Unix/macOS: ls /tmp/claude-*-cwd
  1. Repeat steps 1-4 multiple times
  2. Observe that claude-*-cwd files 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_

View original on GitHub ↗

This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗