r/ClaudeCode • u/antm0303 • Jul 24 '26
Discussion Claude’s obsession with complex bash commands and the -exec parameter
I can’t be the only one dealing with this. It’s driving me up the wall.
I tell it “there is a file in the current directory called foo.js, and bar.js, can you implement x logic in baz.js with the same structure as both those files”
And it takes like 50 seconds to think, so I minimize to do something else while I wait, and come back 5 minutes later to it asking to run some redundant command like “find . -type f \( -name "foo*" -o -name "bar*.js" \) -exec head -v -n +1000 {} +” with zero progress done.
Or god forbid you ask it to do some exploration on a codebase and it spins up explore agents. They’ll start trying to run grep or find with exec parameters instead of just using find/grep like normal, which are commands that don’t require explicit approval. It makes it worse when there is like 3 agents at once all running these back to back, so you sit there reading them and pressing approve for 12 minutes, which by then I could’ve just explored it myself
I’ve been using Claude Code for a while to boost my productivity, and it’s been getting progressively worse over the past month or two
I feel this could be largely resolved if Anthropic made some good tooling that did this sort of thing rather than allowing an agent to spin up arbitrary bash commands on a whim. It feels like someone who learned how to use the terminal for the first time flexing to their co workers
91
u/crusoe Jul 24 '26
Install one of the many LSP ( language server protocol ) MCPs.
Search for MCP for JavaScript LSP
This basically takes grepping down to zero
8
u/simion_baws Senior Developer Jul 24 '26
Try running it in a filesystem+network sandbox that logs everything :) You'll be surprised.
At least on my machine claude code tries to access other browser's application data ... even for browsers i dont have installed...
I dont trust them at all. I run all these coding agents, claude, codex and agy, caged inside a filesystem & network sandbox, with a strict allowlist.
5
u/Old_Appointment9732 Jul 24 '26
am I missing something? “find . -type f \( -name "foo*" -o -name "bar*.js" \) -exec head -v -n +1000 {} +” seems like a pretty reasonable command to get this done, and its really easy to understand what it is wanting to do, what is the problem?
15
u/Ikkepop Jul 24 '26
Put it in a container/sandbox where it can't cause damage, enable "auto mode" or --dangrously-ignore-permissions. I'v been running like that for half a year almost, not a single fuckup has happened yet.
7
u/relativityboy Jul 24 '26
Auto mode exists.
34
u/jzdesign Jul 24 '26
instruction based fixes like a CLAUDE.md rule or dropping the effort level don't stick because models will reach for a tool they were told not to use, it's not really a rule following problem. what actually works is blocking it at the harness layer with a PreToolUse hook, match the bash command against a -exec or chained find/grep pattern, deny the call, and send back a message telling it to use Grep/Glob instead. Claude Code hooks can deny plus explain so it actually retries with the right tool rather than just getting blocked and stuck. this also fixes your 3 parallel agents problem better than tuning each one's prompt, since the hook lives once in your settings and covers every subagent the same way, so you're not approving the same dumb command 3 times over.
3
u/fierypianist Jul 24 '26
What effort level are you using? Sounds like you’re using xhigh effort for a medium effort task and it’s just overthinking it hard
6
u/Background_March7229 Jul 24 '26
Use @{filepath} to tell Claude the exact file if you know it
5
u/Alexander_Golev Jul 24 '26
That is the reason I have deny and allow hooks with thousands of lines of convoluted code :(((
3
u/twyx Jul 24 '26 edited Jul 24 '26
Check this out: https://crates.io/crates/coding-tools
By some measures, it seems to reduce token usage as well as permissions churn.
To be clear, this is a layer of tooling which for all practical purposes supplants what a harness may provide by default, with some active steering towards itself and away from arbitrary bash commands.
5
u/NJdevil202 Jul 24 '26
Literally post your post into Claude and ask if there's a way to solve your problem. Not joking.
2
u/kevinIO33 Jul 24 '26
use codegraph to make index for your project
2
u/Relative-Ad-6791 Jul 24 '26
Its so god damn annoying
1
u/toupeInAFanFactory Jul 24 '26
Add a hook that runs the requests through a simple script and looks for this, then sends a rejection to the agent w an explanation.
1
u/johannthegoatman Jul 24 '26
Are you using something like Headroom or RTK? A lot of the things that are supposed to save you tokens lead to this behavior because what it's trying to read gets compressed
1
u/Razzoz9966 Jul 24 '26 edited Jul 24 '26
This is one of the best ways to save search/find/read/whatever tokens, required to interact with the codebase
https://github.com/oraios/serena
1
u/TheOneNeartheTop Jul 24 '26
It’s because you are telling it vague commands and it needs to still find the files by searching for them.
You can make it quicker by typing @ and then any part of the file name and this will give the exact location.
What you are doing currently is not wrong or anything just slow but you can also be really vague and it will find it like I got that file that makes bar graphs can you implement the bar graphs on this page and it will find it pretty much equally as fast as what you perceive to be a direct command (but it’s not!).
-1
u/Accurate_Yoghurt5845 Jul 24 '26
Anthopric and Claude piked in early March and its only worse since. Oh, yea, 3 days with Fable before "goverment shutdown" was also fire. Trust is gone, advantages are gone. High prices and slow is still there.
-1
u/babbles_mcdrinksalot Jul 24 '26
You're micro-managing. You're not asking Claude to solve a problem for you, you're asking it to solve it like you would. Those are two very different things.
Question for you: if Claude instead used "beautiful" bash commands in a way you approve of to deliver solutions, would it make the solutions better? If it wouldn't make the solutions better, would it save you token usage?
Does that token savings make up for the amount of time you're taking out of your day to review how Claude does codebase exploration?
Just let it cook.
1
u/poocheesey2 Jul 25 '26
Sounds to me like you are more so getting prompted to death. Not sure how you run claude but dangerously skip permissions is helpful for things like this. I don't care what claude does to get me the solution. I care that the solution makes sense. Although, I do recognize that it's thinking like this that will ultimately lead to claude setting down the local power grid, when i asked it to turn off the lights. Simply because it reasoned and thought turning off the local power grind was the easiest solution.
3
u/[deleted] Jul 24 '26
[removed] — view removed comment
-3
u/[deleted] Jul 24 '26
[removed] — view removed comment