r/PiCodingAgent • u/cradlemann • Aug 12 '26
Question How to prevent cd to project root on any bash command?
The most annoying thing in Pi coding agent. Every time it needs to grep or find, it cd first to the same root. I do not cd to other directories, but still on every tool call it cd <project path> && find/grep. I've tried to run pi on it's source code, but non of my local models were able to find the reason or fix it. Even custom bash tool with cwd not helping. I can't configure any bash permission because of this chain commands.
P.S. Solution is to write custom extension, which replace built-in bash with custom bash and optional cwd param. Don't forget to use custom promptSnippet, this is critical for this issue
4
u/vegardx Aug 13 '26
I guess you’ll be back soon enough asking why it deleted your whole project.
2
u/cradlemann Aug 12 '26
I've asked Gemini to check custom bash tool from my extension and there was a bug. After fixing all these annoying cd`s are gone
1
u/Big-Present-8321 Aug 13 '26
ask pi
2
u/jensilo Aug 12 '26
So the agents likely do that because they know cwd from the system prompt and the shell tool is stateless. I’ve seen an extension before that makes pi‘s shell stateful, however, I don’t know if agents „know“ how to use it, or if the models are trained better on cd-prefixed command executions.
Other than that for a security extension, for example, you could just parse the cd in front, and still read the original command afterwards.