Uncategorized 6 min read

Gemini CLI headless mode exits 55 until you trust the folder

Gemini CLI exits 55 in a script until the folder is trusted, then prints code instead of editing. Two settings fix both; 22 runs show it.

Two hands open a blank manila folder on a worn wooden desk beside a rain-streaked window, with a blank sheet of paper, a pencil and a mug of coffee.

Google’s own README for Gemini CLI now opens with a box that says “Read before installing.” Inside it, the free tier is gone, the tool is for organisations on Google Cloud, and a table points everyone else at a different program called Antigravity CLI. I installed 0.71.1 anyway, with an API key, and reran the key cases on 0.72.0 the morning it went stable, because the repo is still one of the busiest in the field and a script will happily call it.

In a script it fails twice before it does any work. First it refuses to start in a folder it does not trust, with exit code 55. Then, once trusted, its default approval mode has no edit tool at all, so the run prints the new function to the terminal, leaves the file alone, and exits 0. My verdict: Gemini CLI is a good headless agent if you set two things before the first run, and a quiet time-waster if you do not.

Terminal capture of Gemini CLI 0.71.1 headless runs: exit code 55 in an untrusted folder, and in a trusted one the default approval mode prints the function without changing util.py.
Left, the untrusted folder: exit 55 and an empty stdout. Right, the default approval mode: the code is printed, util.py is unchanged, and the run costs 112,708 to 435,653 tokens. Lines trimmed from the 2 December 2026 runs of 0.71.1.

What is Gemini CLI for?

Gemini CLI is Google’s terminal coding agent: you give it a sentence, it reads your folder, runs tools and edits files. It is Apache-2.0 licensed and the google-gemini/gemini-cli repository showed 109,502 stars when I read the GitHub API (api.github.com/repos/google-gemini/gemini-cli) at 05:05 UTC on 2 December 2026. Most of my runs used v0.71.1, the stable tag from 24 November. v0.72.0 went stable at 05:40 UTC on 2 December, and I ran the failing cases on it too; its release notes list no trust or approval change, and the runs agree.

Who it is for changed in June. Google’s transition post says that from 18 June 2026 Gemini CLI stops serving Google AI Pro and Ultra accounts and free Code Assist users, who move to Antigravity CLI. Enterprise Code Assist licences keep access, and the CLI “will remain accessible via paid Gemini and Gemini Enterprise Agent Platform API keys”. That leaves two groups: companies already paying Google Cloud, and developers with an API key who want an agent a shell script or CI job can call.

That second use is the one worth caring about. An interactive agent can ask you questions. A headless one cannot, and everything that goes wrong in this post comes from the questions Gemini CLI would have asked a person. Yesterday’s Codex CLI rule-file post had the same shape: a setting nobody told you about did the damage.

How do you set Gemini CLI up to run from a script?

It runs wherever Node runs. I used a Linux container with Node 22 and put the binary in a local folder so nothing touched the system:

$ npm i --prefix ./npm @google/gemini-cli@0.71.1
$ ./npm/node_modules/.bin/gemini --version
0.71.1

The key is one environment variable, GEMINI_API_KEY. Without it, three runs out of three ended with exit code 41 and this line, which names the three accepted variables:

Please set an Auth method in your .../.gemini/settings.json or specify one of the following environment variables before running: GEMINI_API_KEY, GOOGLE_GENAI_USE_VERTEXAI, GOOGLE_GENAI_USE_GCA

Every launch after that was headless: gemini -p "add a function double(x) to util.py that returns x times two" < /dev/null, in a fresh git folder holding one file, util.py, with add(a, b) in it. The CLI picked gemini-3.8-flash as its main model and gemini-3.5-flash-lite as a router, and I left both alone.

The config that matters is two lines. One goes in ~/.gemini/settings.json:

{ "general": { "defaultApprovalMode": "auto_edit" } }

The other is an environment variable on the command that needs it: GEMINI_CLI_TRUST_WORKSPACE=true. The --skip-trust flag does the same for one launch. The variable and the flag are named in the CLI’s own error message and on its trusted folders page; the next section shows why you want them in before the first run.

What goes wrong with Gemini CLI in a script?

Two things, and the second one is quiet.

An untrusted folder ends the run with exit 55

A fresh folder is untrusted. Three runs out of three, in 10 to 11 seconds, printed this and stopped:

Gemini CLI is not running in a trusted directory. To proceed, either use `--skip-trust`, set the `GEMINI_CLI_TRUST_WORKSPACE=true` environment variable, or trust this directory in interactive mode.

Exit code 55, empty stdout, util.py untouched. The message is clear, but the number is not where a script author looks: the headless mode page lists exit codes 0, 1, 42 and 53, and neither 41 nor 55 is among them. The trust page also says “The Trusted Folders feature is disabled by default.” The 0.71.1 bundle says otherwise: its folderTrust.enabled setting has default: true, and FatalUntrustedWorkspaceError calls super(message, 55). A GitHub issue from 22 November, #30402, reports the same mismatch, still open this morning.

The trust page adds that an untrusted folder ignores the project’s .gemini/settings.json and .env and keeps tool auto-acceptance off. Sensible on a laptop, a trap for a CI runner that checks out a fresh clone every build.

The default approval mode has no edit tool, and the run still exits 0

With the folder trusted, I ran the same sentence five times in the default approval mode. Zero of five wrote the file. Three finished with exit 0 and the same message in three wordings: no file-modification tool in this session. One of them said:

File modification tools are not available in this session. You can update `util.py` with:

followed by a code block holding the finished function. The other two were still running at the 290-second mark when the timeout ended them, one of them mid web search for “gemini-cli” “skip-default”, my scratch folder’s name. That is the part that costs money. The three finished runs took 119, 194 and 143 seconds and spent 112,708, 373,209 and 435,653 tokens: each called invoke_agent once, and the two biggest read 7 to 9 files and listed the folder 6 to 7 times and ran a web search before giving up on editing. A CI log shows a green job, a plausible summary, and a repo where nothing changed.

With --approval-mode auto_edit the same task wrote the function in 3 of 3 runs, in 37 to 47 seconds and 31,000 to 41,089 tokens. Putting the setting in settings.json with the trust variable did the same in 3 of 3, in 23 to 41 seconds. The default itself is described in the settings schema: “‘default’ prompts for approval, ‘auto_edit’ auto-approves edit tools”. A headless run cannot answer a prompt, so the prompt becomes a refusal.

Mettons that you run it on a hundred pull requests a day. At the cheapest of my default runs that is 11.3 million tokens for no edits.

What did I actually run?

Twenty-two headless runs on 2 December 2026, seventeen on 0.71.1 and five on 0.72.0, one task each, a fresh git folder for every run.

SetupExit codeutil.py changedTokens
no GEMINI_API_KEY41, 3 of 3non/a
key, folder untrusted55, 3 of 3non/a
--skip-trust, default approval0 in 3, timed out in 20 of 5112,708 to 435,653
--skip-trust --approval-mode auto_edit0, 3 of 33 of 331,000 to 41,089
trust variable and defaultApprovalMode in settings.json0, 3 of 33 of 337,548 to 62,215
0.72.0, key, folder untrusted55, 3 of 3non/a
0.72.0, --skip-trust, default approval0, 1 of 10 of 1256,455
0.72.0, --skip-trust --approval-mode auto_edit0, 1 of 11 of 147,196

Every working run made one replace call on util.py and added four or five lines. The CLI’s JSON output (-o json) reports the tool counts per run, and every finished default run called invoke_agent where none of the seven working runs did.

Use Gemini CLI if you hold an API key and want a scriptable agent, and put both settings in the image or the runner’s environment on day one. If your plan was the free Google login, that door is closed and Antigravity CLI is the program Google built for it. Nothing moved between 0.71.1 and 0.72.0, so an edit tool that arrives with a warning instead of a silent refusal is the only change I would call a fix.

Dominic Plouffe

CTO of Trellis, with exits at FuseTalk, 360pi and DeadHeat. I write about making agents and big data work together safely, and I'm building yaaf, an open-source platform for running teams of AI agents that actually finish the job: dplouffe.ca/yaaf