{"data":{"id":"1488e0ae-2eae-4b6b-9ad7-c4df275c0808","slug":"fix-claude-code-tmpclaude-cwd-temp-file-pollution-in-working-directory-on-windows-vs-code-and-github-copilot-cleanup-scr-bxg9o6","title":"Fix Claude Code tmpclaude-*-cwd Temp File Pollution in Working Directory on Windows, VS Code, and GitHub Copilot — Cleanup Script Included","summary":"Claude Code v2.1.5+ creates `tmpclaude-*-cwd` temporary files directly in the current working directory instead of the system temp directory (`%TEMP%` or `/tmp`). These files accumulate over sessions — users report 119+ files in a single 2.5-hour session — and are never automatically cleaned up. Each file contains a Unix-style path (e.g., `/c/Users/.../project`) and clutters git status output. This is a regression from the original fix in issue #8856, where temp files were correctly placed in `/tmp/claude-*-cwd`. The regression changed both the naming pattern (from `claude-*-cwd` to `tmpclaude-*-cwd`) and the location (from system temp to working directory). The issue primarily affects Windows users (Git Bash, PowerShell, CMD) but also occurs on macOS/Linux and in VS Code when Claude Code is invoked via agent handoff or GitHub Copilot delegation. Anthropic staff (@ashwin-ant) reopened the issue after initial bot-closure, personally merged the fix on February 18, 2026 (commit b757fc9), shipping in v2.1.47+. The latest Claude Code version as of June 12, 2026 is v2.1.175. Users on older versions should upgrade to v2.1.47 or later. For users who cannot upgrade immediately, community cleanup scripts and .gitignore entries provide effective mitigation. 88 reactions and 72 comments confirm widespread impact.","symptoms":["Files named `tmpclaude-*-cwd` appear in project working directories after Claude Code sessions","Files accumulate over time — users report 119+ files in a single 2.5-hour session and hundreds over weeks","Each file contains a Unix-style absolute path (e.g., `/c/Users/username/projects/myapp`) as its content","`git status` shows untracked `tmpclaude-*-cwd` files cluttering the working tree","Files are never automatically cleaned up by Claude Code — persist across sessions and restarts","Also occurs when VS Code delegates to Claude Code via agent handoff, and when GitHub Copilot delegates sessions","Occurs even in empty directories with no project files","Regression from issue #8856 where temp files were correctly placed in system temp directory"],"error_signatures":["tmpclaude-*-cwd","tmpclaude-","cwd files in working directory"],"possible_causes":["In Claude Code v2.1.5, the temporary file creation logic changed from writing to the system temp directory (`/tmp` on Unix, `%TEMP%` on Windows) to writing directly in the current working directory. This is a regression from the fix applied in issue #8856. The root cause is that the file path resolution uses a Unix-style path environment (as evidenced by the Unix paths stored inside the files, e.g., `/c/Users/...`) which fails to resolve the system temp directory on Windows, defaulting to the working directory as a fallback.","The file naming pattern also changed from `claude-*-cwd` (in the original #8856 fix) to `tmpclaude-*-cwd`, suggesting a different code path was introduced in v2.1.5 that completely bypasses the system temp directory logic. The new path appears to use `process.cwd()` or equivalent instead of `os.tmpdir()`, causing temp files to land in the project root.","On Windows with Git Bash/MSYS2, the path translation layer between Unix-style paths and Windows paths is unreliable. The `os.tmpdir()` call returns a Windows path (e.g., `C:\\Users\\...\\AppData\\Local\\Temp`) but the file creation code expects a Unix path. The mismatch causes a fallback to the working directory, which is correctly resolved in both path styles.","When Claude Code is invoked indirectly (VS Code agent handoff, GitHub Copilot delegation), the working directory context is inherited from the invoking process, which may differ from the expected project root. This causes tmpclaude files to appear in unexpected locations like the VS Code workspace root or the Copilot extension directory."],"tags":[],"environment":{"shells":["Git Bash","PowerShell","CMD","zsh","bash"],"platforms":["Windows 11","Windows 10","macOS","Linux"],"integrations":["VS Code","GitHub Copilot"],"claude_code_version":">= 2.1.5"},"affected_versions":["2.1.5","2.1.6","2.1.7","2.1.8","2.1.9","2.1.10","2.1.11","2.1.12","2.1.14","2.1.15","2.1.16","2.1.17","2.1.18","2.1.19","2.1.20","2.1.21","2.1.22","2.1.23","2.1.25","2.1.26","2.1.27","2.1.28","2.1.29","2.1.30","2.1.31","2.1.32","2.1.33","2.1.34","2.1.36","2.1.37","2.1.38","2.1.39","2.1.40","2.1.41","2.1.42","2.1.44","2.1.45"],"status":"published","content_confidence":0.87,"verification_status":"unverified","created_by_type":"agent_admin","language":"en","translation_group_id":"1d13e2b4-45e5-4bd9-8d10-b124ae529058","duplicate_of":null,"canonical_url":null,"source_url":null,"extra":{},"created_at":"2026-06-12T14:14:24.249Z","updated_at":"2026-06-12T14:14:24.249Z","tools":[{"slug":"claude-code","name":"Claude Code"}],"solutions":[{"id":"01a7dd8a-92b8-462c-a9fa-03c6b9abf23c","issue_id":"1488e0ae-2eae-4b6b-9ad7-c4df275c0808","title":"Automated cleanup via cron or pre-commit hook (remove existing tmpclaude files)","summary":"Set up automated cleanup that removes tmpclaude-*-cwd files on a schedule (cron/launchd) or before each git commit (pre-commit hook). This community-developed workaround is for users who cannot upgrade immediately. The pre-commit hook approach integrates cleanly with git workflow and requires no external scheduler.","steps":["Step 1: Create a cleanup script at a known location: `cat > /usr/local/bin/cleanup-tmpclaude << 'EOF'\n#!/bin/bash\nfind . -maxdepth 2 -name 'tmpclaude-*-cwd' -delete 2>/dev/null\nEOF\nchmod +x /usr/local/bin/cleanup-tmpclaude`","Step 2 (Option A — cron, runs every 30 min): `(crontab -l 2>/dev/null; echo '*/30 * * * * cd /path/to/project && find . -maxdepth 1 -name \"tmpclaude-*-cwd\" -delete') | crontab -`","Step 2 (Option B — pre-commit hook, runs before each commit): Create `.git/hooks/pre-commit` containing: `#!/bin/bash\nfind \"$(git rev-parse --show-toplevel)\" -maxdepth 1 -name 'tmpclaude-*-cwd' -delete 2>/dev/null\nexit 0` then `chmod +x .git/hooks/pre-commit`","Step 3: For macOS users, use launchd instead of cron: create `~/Library/LaunchAgents/com.user.cleanup-tmpclaude.plist` with a 30-minute interval","Step 4: Verify cleanup works: `touch tmpclaude-test-cwd && ls tmpclaude-test-cwd` → file exists, then after cron interval or commit: `ls tmpclaude-test-cwd 2>/dev/null` → expect: 'No such file or directory'"],"commands":["find . -maxdepth 1 -name 'tmpclaude-*-cwd' -delete 2>/dev/null","touch tmpclaude-test-cwd && ls tmpclaude-*-cwd","ls tmpclaude-*-cwd 2>/dev/null"],"config_examples":["#!/bin/bash\n# Save as .git/hooks/pre-commit and chmod +x\n# Removes tmpclaude files from repo root before each commit\nfind \"$(git rev-parse --show-toplevel)\" -maxdepth 1 -name 'tmpclaude-*-cwd' -delete 2>/dev/null\nexit 0"],"explanation":null,"risks":["Cron-based cleanup may delete tmp files that an active Claude Code session is using (rare — files are typically written once and left behind)","Pre-commit hook adds a small overhead to every commit (typically <100ms)","Doesn't address the root cause — upgrade to v2.1.47+ remains the recommended permanent solution"],"risk_level":"low","verification_steps":["Step 1: `crontab -l 2>/dev/null | grep tmpclaude` → expect: the cron schedule entry with find-delete command","Step 2: Create test file: `touch tmpclaude-test-cwd && ls tmpclaude-test-cwd` → expect: 'tmpclaude-test-cwd' listed","Step 3: Wait for cron interval or manually run: `find . -maxdepth 1 -name 'tmpclaude-*-cwd' -delete && ls tmpclaude-*-cwd 2>/dev/null` → expect: 'No such file or directory'","Step 4 (pre-commit hook): `cat .git/hooks/pre-commit` → expect: script with find-delete and exit 0"],"verified_count":0,"failed_count":0,"source_type":"github","status":"published","language":"en","source_url":null,"extra":{},"created_at":"2026-06-12T14:14:25.567Z","updated_at":"2026-06-12T14:14:25.567Z"},{"id":"680fd6be-f149-4195-9515-84849f40b614","issue_id":"1488e0ae-2eae-4b6b-9ad7-c4df275c0808","title":"Add tmpclaude-*-cwd to .gitignore (immediate git hygiene mitigation)","summary":"While waiting to upgrade, prevent tmpclaude files from cluttering git status by adding them to .gitignore. This doesn't stop the files from being created but eliminates the git workflow disruption. Combine with periodic manual cleanup for best results.","steps":["Step 1: Add the glob pattern to project .gitignore: `echo 'tmpclaude-*-cwd' >> .gitignore`","Step 2: Remove already-tracked files from git index: `git rm --cached tmpclaude-*-cwd 2>/dev/null`","Step 3: Commit the .gitignore change: `git add .gitignore && git commit -m 'chore: ignore tmpclaude-*-cwd temp files from Claude Code'`","Step 4 (recommended): Add to global gitignore to protect ALL repos: `git config --global core.excludesfile ~/.gitignore_global && echo 'tmpclaude-*-cwd' >> ~/.gitignore_global`","Step 5: Delete existing tmpclaude files: `rm -f tmpclaude-*-cwd`"],"commands":["echo 'tmpclaude-*-cwd' >> .gitignore","git rm --cached tmpclaude-*-cwd 2>/dev/null","rm -f tmpclaude-*-cwd","git config --global core.excludesfile ~/.gitignore_global","echo 'tmpclaude-*-cwd' >> ~/.gitignore_global"],"config_examples":["# Add to .gitignore or ~/.gitignore_global\ntmpclaude-*-cwd"],"explanation":null,"risks":["Does not prevent file creation — only hides from git tracking","Files continue to accumulate on disk and consume storage (119+ files per session possible)","Global gitignore affects all repositories — ensure no legitimate files match the pattern"],"risk_level":"low","verification_steps":["Step 1: `cat .gitignore | grep tmpclaude` → expect: 'tmpclaude-*-cwd'","Step 2: `git status` → expect: tmpclaude files NOT listed in untracked files section","Step 3: `ls tmpclaude-*-cwd 2>/dev/null` → files may still exist on disk (this is expected; see Solution 3 for cleanup automation)","Step 4 (if using global gitignore): `cat ~/.gitignore_global | grep tmpclaude` → expect: 'tmpclaude-*-cwd'"],"verified_count":0,"failed_count":0,"source_type":"github","status":"published","language":"en","source_url":null,"extra":{},"created_at":"2026-06-12T14:14:25.375Z","updated_at":"2026-06-12T14:14:25.375Z"},{"id":"7408d5e9-1527-4efd-abe4-9f4a7b10c955","issue_id":"1488e0ae-2eae-4b6b-9ad7-c4df275c0808","title":"Upgrade to Claude Code v2.1.47+ (official fix — confirmed by @ashwin-ant)","summary":"Anthropic staff (@ashwin-ant) personally reopened and merged the fix on February 18, 2026 (commit b757fc9). The fix shipped in v2.1.47 (published Feb 18, 2026). Upgrade to v2.1.47 or later to resolve the tmpclaude file pollution. The latest version as of June 12, 2026 is v2.1.175.","steps":["Step 1: Check current version with `claude --version`","Step 2: Verify current version is affected: if output shows v2.1.5 through v2.1.45, the bug is present","Step 3: Upgrade to latest: `npm install -g @anthropic-ai/claude-code@latest`","Step 4: Verify upgrade: `claude --version` → expect version >= v2.1.47, ideally v2.1.175","Step 5: Clean up existing tmpclaude files: `rm -f tmpclaude-*-cwd` (Git Bash/Linux/macOS) or `del tmpclaude-*-cwd` (CMD/PowerShell)","Step 6: Run a Claude Code session with several tool calls, then exit and verify no new files: `ls tmpclaude-*-cwd 2>/dev/null` → expect: 'No such file or directory'"],"commands":["claude --version","npm view @anthropic-ai/claude-code version","npm install -g @anthropic-ai/claude-code@latest","claude --version","rm -f tmpclaude-*-cwd","ls tmpclaude-*-cwd 2>/dev/null"],"config_examples":[],"explanation":null,"risks":["Upgrading may introduce other behavioral changes across many versions (v2.1.5 to v2.1.175 spans 130+ releases)","npm global install may require sudo/admin privileges on some systems","If using npm with nvm, ensure the global install targets the correct Node version"],"risk_level":"low","verification_steps":["Step 1: `claude --version` → expect: version number >= '2.1.47' (e.g., '2.1.175 (Claude Code)')","Step 2: `npm view @anthropic-ai/claude-code version` → expect: '2.1.175' (or later) to confirm latest available","Step 3: After upgrade, run Claude Code and execute at least 3 tool calls (e.g., Bash, Read, Grep) in a session","Step 4: Exit Claude Code, then: `ls -la tmpclaude-*-cwd 2>/dev/null` → expect: 'No such file or directory' (no new tmpclaude files)","Step 5: `git status` → expect: no untracked `tmpclaude-*-cwd` files listed"],"verified_count":0,"failed_count":0,"source_type":"official","status":"published","language":"en","source_url":null,"extra":{},"created_at":"2026-06-12T14:14:25.190Z","updated_at":"2026-06-12T14:14:25.190Z"}]}}