Model frequently creates tmp scripts in random spots
What happened?
By restricting the model to shell execution via exclusion, it tends to generate multiple edit scripts across various directories. This creates significant overhead when trying to clean up the workspace for a clean commit.
What did you expect to happen?
The model writing to a tmp directory in project/.gemini/tmp
Client information
Running from main 3/23/26 11:50am
Login information
No response
Anything else we need to know?
No response
Sounds like a dup of https://github.com/google-gemini/gemini-cli/issues/20067 - I'm fighting with this by changing system prompt (you can also try to add similar text in GEMINI.md), though it is not fully working. Looks like Gemini models have to be better trained to use function calls / tools and not invent workarounds.
Hi @galz10 and @vsukhoml,
I've run into this exact issue when trying to automate the model for code generation and refactoring. Relying on the model to "behave" and keep its temporary scripts contained is difficult when it operates with a generic persona and broad tool access.
If you are working on an orchestration or programmatic script to wrap the CLI, you might be interested in a Python wrapper I've built called gemini-cli-headless (https://github.com/jarek108/gemini-cli-headless).
Instead of just hoping the model guesses the right temporary directory, the wrapper gives you two powerful levers to enforce it:
- Persona Control (system_instruction_override): You can completely replace the default system prompt to explicitly mandate how and where file creation should happen (e.g., strictly enforcing that all temporary scripts must be written to project/.gemini/tmp).
- Tool Restriction (allowed_tools): You can programmatically restrict the exact tools available to the model, preventing it from executing shell commands or writing files in ways you haven't explicitly whitelisted.
I detailed the architecture and why I think these programmatic controls are essential for headless orchestration in this discussion: Building a Zero-Trust Headless Orchestrator for Gemini CLI (https://github.com/google-gemini/gemini-cli/discussions/25659)
Agent behavior issue where it creates scripts unnecessarily.
Running the CLI for long unattended tasks hit this exact pattern. Two things actually cut it down for us:
-
A designated scratch dir declared in GEMINI.md ("all scratch and verification scripts go to .gemini/tmp, nowhere else"), plus a one-line cleanup step at the end of every task. The instruction alone didn't hold; adding the cleanup step did, because the model then has a concrete reason to track what it created.
-
On the incentive side, most stray scripts showed up when a single-file change needed verification and the only available route was "write a script somewhere". Once there was a proper verify loop (checks scoped to the workspace) the workaround urge mostly went away. Agree with @vsukhoml that pure restriction just relocates the workaround instead of removing it.