Platform detection fails for Cygwin/MSYS2: uses `nul` instead of `/dev/null` causing temp file pollution

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

Environment

  • OS: Windows 10/11
  • Shell: Git Bash (MSYS2) - version 5.2.37
  • Runtime: Deno
  • Claude Code Version: latest as of 2026-01-13

Problem Description

Claude Code creates tmpclaude-*-cwd files in workspace directory instead of system temp directory.

Critical finding: Even when TMP/TEMP/TMPDIR environment variables are set to /tmp, Claude Code ignores them and creates files in workspace root.

Verified behavior:

echo $TMP      # Shows: /tmp
echo $TEMP     # Shows: /tmp
echo $TMPDIR   # Shows: /tmp
# BUT temp files still created in workspace/.claude/

This indicates Claude Code's temp directory logic does NOT check environment variables.

Root Cause

Claude Code's temp file creation uses process.cwd() or similar instead of respecting process.env.TMP / process.env.TEMP / os.tmpdir().

Expected Behavior

  • Check TMP/TEMP/TMPDIR environment variables first
  • Fall back to os.tmpdir() if not set
  • Create temp files in system temp directory, not workspace

Proposed Fix

function getTempDirectory() {
    // Respect environment variables FIRST
    const tmp = process.env.TMP || process.env.TEMP || process.env.TMPDIR;
    if (tmp) {
        return tmp;
    }
    
    // Fall back to system temp
    return os.tmpdir();
}

// Usage in temp file creation:
const tempDir = getTempDirectory();
const tempFile = path.join(tempDir, `tmpclaude-${randomId}-cwd`);

Tested Workarounds

❌ DOES NOT WORK: Setting environment variables

# .claude/env.yml - DOES NOT FIX THE ISSUE
env:
  TMP: /tmp
  TEMP: /tmp
  TMPDIR: /tmp

Result: Variables are loaded but Claude Code ignores them.

✅ WORKS: Shell-level auto-cleanup (fish shell)

# ~/.config/fish/config.fish
function __cleanup_claude_temp --on-event fish_prompt
    if test -d .claude
        rm -f tmpclaude-*-cwd 2>/dev/null
    end
end

Result: Files are created then immediately deleted. Workspace stays clean.

✅ WORKS: .gitignore

tmpclaude-*
tmpclaude-*-cwd/

Result: Files ignored by git, but still pollute workspace.

Related Issues

  • #17925 - Temporary files not cleaned up on Windows (3 comments)
  • #17878 - Temp directories created in workspace root
  • #17600 - Official fix referenced

Impact

Affects ALL users running Claude Code with Git Bash (MSYS2), regardless of shell:

  • Git Bash users
  • MSYS2 users
  • Cygwin users (likely)
  • Any environment where temp files should go to /tmp

Severity: High - workspace pollution, potential git commit accidents, no effective workaround besides shell auto-cleanup.

This is a regression that started 2026-01-13 based on issue reports.

View original on GitHub ↗

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