[BUG] Bash tool: Tilde expansion fails for paths with spaces when command contains a pipe
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?
When running a bash command that contains both a pipe (|) and a path with a tilde and space (e.g., ~/test/hello\ world/), tilde expansion fails and the command returns "No such file or directory".
Steps to reproduce:
#Ask claude code to run this, it works
ls -la ~/test/hello\ world/
#Ask claude code to run this, it fails
ls -la ~/test/hello\ world/ | head -15
#Error: ls: ~/test/hello world/: No such file or directory
The root cause issue after claude code debugged cli.js (which had the same issue):
For piped commands, the NJK function parses the command into tokens using shell-quote, then quotes each token individually before reassembling. When a path contains a space, shell-quote wraps it in single
quotes: '~/test/hello world/'. This traps the tilde inside single quotes, preventing shell expansion.
The final command passed to eval becomes:
eval "ls -la '~/test/hello world/' < /dev/null | cat"
Since tilde expansion doesn't occur inside single quotes in bash, the literal ~/test/hello world/ path is used instead of the expanded /Users/name/test/hello world/.
What Should Happen?
the bash command should do tilde expansion correctly and list the folder contents
Error Messages/Logs
Steps to Reproduce
#Ask claude code to run this, it works
ls -la ~/test/hello\ world/
#Ask claude code to run this, it fails
ls -la ~/test/hello\ world/ | head -15
#Error: ls: ~/test/hello world/: No such file or directory
Claude Model
Opus
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
2.1.22 (Claude Code)
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
Other
Additional Information
_No response_
This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗