[BUG] Claude code leaves temp files

Resolved 💬 10 comments Opened Jan 12, 2026 by dr8vr Closed Apr 18, 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?

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

  1. Use Claude Code normally with bash operations in a project directory
  2. After multiple sessions/operations, check the working directory
  3. Find multiple tmpclaude-*-cwd files 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

  1. Use system temp directory instead of working directory for temporary files
  2. Implement proper cleanup in finally blocks or exit handlers
  3. Add a cleanup routine that runs on session end
  4. 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_

View original on GitHub ↗

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