[BUG] Inconsistent Grep Results Between Direct Execution and Script Execution
Resolved 💬 4 comments Opened Oct 7, 2025 by taiga371 Closed Jan 9, 2026
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?
Claude Code's Bash tool produces different results when executing the same grep command directly versus through a shell script, and local bash.
What Should Happen?
Direct execution should return the same results as shell script execution and local bash.
Error Messages/Logs
No error messages - silent incorrect behavior.
Steps to Reproduce
- Create a test file as follow.
implementation("line1")
implementation("line2")
implementation("line3")
testImplementation("line4")
testImplementation("line5")
runtimeOnly("line6")
compileOnly("line7")
developmentOnly("line8")
implementation("line9")
testImplementation("line10")
- Execute test command by claude code (Direct execution)
grep -E "implementation|testImplementation|testRuntimeOnly|runtimeOnly|compileOnly|developmentOnly" simple_test.txt
- return (incorrect)
runtimeOnly("line6")
compileOnly("line7")
developmentOnly("line8")
- Create a test shell script file as follow (test.sh)
#!/bin/bash
grep -E "implementation|testImplementation|testRuntimeOnly|runtimeOnly|compileOnly|developmentOnly" simple_test.txt
- Execut test shell script file by claude code (Shell script execution)
Bash(./test.sh)
- return (correct)
implementation("line1")
implementation("line2")
implementation("line3")
testImplementation("line4")
testImplementation("line5")
runtimeOnly("line6")
compileOnly("line7")
developmentOnly("line8")
implementation("line9")
testImplementation("line10"
Claude Model
Sonnet (default)
Is this a regression?
No, this never worked
Last Working Version
Unknown
Claude Code Version
2.0.9
Platform
Other
Operating System
Ubuntu/Debian Linux
Terminal/Shell
WSL (Windows Subsystem for Linux)
Additional Information
About claude code version :
First, I faced this problem on claude code 1.0.58. And upgrade to 2.0.9 but not fixed.
Workaround :
Execute complex grep commands through shell scripts rather than direct Bash tool execution:
# Instead of direct execution, create a script:
echo 'grep -E "pattern" file.txt' > temp_script.sh
chmod +x temp_script.sh
./temp_script.sh
More informatiln :
- Bug report generated by claude code : claude_code_bash_bug_report.md
- Test file generated by claude code : simple_test.txt simple_core_test.sh
This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗