Bug: unquoted TMPDIR path with spaces causes 'Permission denied' on every bash command (Windows)

Resolved 💬 5 comments Opened Feb 21, 2026 by drmirf Closed Mar 24, 2026

Environment

  • OS: Windows 11 (Git Bash / MSYS2)
  • Claude Code: 2.1.50
  • Username/path with space: C:\Users\Amir Faria

Problem

Every bash command executed by Claude Code produces this error after the command output:

/usr/bin/bash: line 1: /c/Users/Amir: Permission denied

The command itself succeeds, but the error is always appended.

Root Cause

In cli.js, the buildExecCommand function constructs the cwd capture like this:

P.push(`pwd -P >| ${j}`);

Where j is derived from os.tmpdir() via path.posix.join(convertedTmpdir, ...). On Windows, when the username contains a space (e.g., "Amir Faria"), os.tmpdir() returns C:\Users\Amir Faria\AppData\Local\Temp, and the resulting bash command becomes:

pwd -P >| /c/Users/Amir Faria/AppData/Local/Temp/claude-xxx-cwd

Bash splits on the space and tries to redirect to /c/Users/Amir (a directory), producing "Permission denied".

Fix

Quote the path:

P.push(`pwd -P >| '${j}'`);
// or better, using the existing W4 helper:
P.push(`pwd -P >| ${W4([j])}`);

Workaround

Set TMP and TEMP environment variables to a path without spaces:

# In ~/.bashrc
if [[ "$TMP" == *" "* ]] || [[ "$TEMP" == *" "* ]]; then
    export TMP="/c/Temp"
    export TEMP="/c/Temp"
    mkdir -p "$TMP" 2>/dev/null
fi

Or set Windows user environment variables:

[System.Environment]::SetEnvironmentVariable('TMP', 'C:\Temp', 'User')
[System.Environment]::SetEnvironmentVariable('TEMP', 'C:\Temp', 'User')

Requires restarting the terminal and Claude Code for the fix to take effect.

View original on GitHub ↗

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