claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

[BUG] Claude CLI fails to escape file paths with spaces in bash commands

Open andreassolberg opened this issue 6 months ago • 3 comments

Environment

  • Platform (select one):
    • [ ] Anthropic API
    • [ ] AWS Bedrock
    • [ ] Google Vertex AI
    • [x] Other: Claude CLI (Claude Code)
  • Claude CLI version: 1.0.16 (Claude Code)
  • Operating System: macOS 15.5 (24F74)
  • Terminal: Visual Studio Code integrated terminal

Bug Description

The Claude CLI fails to properly escape file paths containing spaces when executing bash commands (specifically grep). This causes the command to fail when working with files in directories that have spaces in their names, such as iCloud Drive paths.

Steps to Reproduce

  1. Ask Claude CLI: "can i delete jobs.html?"
  2. Claude CLI attempts to search for files using grep
  3. Grep command fails due to unescaped spaces in file path

Expected Behavior

The file path should be properly quoted/escaped so that grep treats it as a single argument, allowing the command to execute successfully.

Actual Behavior

The grep command fails with "No such file or directory" errors because the unescaped spaces cause the path to be split into multiple arguments:

grep -n "jobs\.html" /Users/andreas/Library/Mobile\ Documents/com~apple~CloudDocs/Documents/dataproject/index.js

Results in grep trying to search multiple separate paths instead of the single intended path.

Here is the exact output from Claude cli:

⏺ Bash(grep -n "jobs\.html" /Users/andreas/Library/Mobile\ Documents/com~apple~CloudDocs/Documents/dataproject/index.js)
  ⎿  Error: grep: /Users/andreas/Library/Mobile\: No such file or directory
     grep: Documents/com~apple~CloudDocs/Documents/dataproject/index.js: No such file or directory

Additional Context

This issue specifically affects iCloud Drive paths and other directory structures containing spaces. The path /Users/andreas/Library/Mobile Documents/com~apple~CloudDocs/Documents/dataproject/index.js exists but cannot be accessed due to improper quoting.

andreassolberg avatar Jun 06 '25 19:06 andreassolberg

🔧 Workaround: Symbolic Links for Paths with Spaces

While waiting for the official fix, here's a reliable workaround that works at the OS level:

The Problem

Claude Code fails to load directories with spaces in additionalDirectories because the path gets truncated at the first space character.

✅ Solution: Create Symbolic Links

I've created a comprehensive guide with platform-specific instructions:

📋 Complete Workaround Guide → Github Gist

The guide includes:

  • Quick reference for immediate implementation
  • Step-by-step instructions for macOS, Windows, Linux, and WSL
  • Common use cases (iCloud folders, Windows Documents, team folders)
  • Three configuration methods (settings files, CLI args, slash commands)
  • Verification steps to test the workaround
  • Troubleshooting section for common issues
  • Performance and security information
  • Alternative solutions comparison table
  • Related GitHub issues and technical context

Tested and Verified

I've tested this workaround in a development environment and confirmed it works across all platforms.


This workaround should work immediately while the development team implements a proper fix for the underlying issue.

brettdavies avatar Oct 23 '25 20:10 brettdavies

This issue has been inactive for 30 days. If the issue is still occurring, please comment to let us know. Otherwise, this issue will be automatically closed in 30 days for housekeeping purposes.

github-actions[bot] avatar Dec 11 '25 10:12 github-actions[bot]

We have the same issue working with Claude Code in a folder whose parent directory has spaces.

joelstein avatar Dec 11 '25 11:12 joelstein