# Gemini CLI adapter

Shows the sessions of Gemini CLI in the notch: working, done at the end of a turn, and waiting for you while Gemini CLI asks you to confirm a tool.
Gemini CLI reports through hooks: each hook posts its event with `curl` to a Unix socket in your own folder, `~/Library/Application Support/Blossom/gemini/socket`, where this adapter listens. Blossom launches the adapter.
**A confirmation is answered in Gemini CLI, not in Blossom.** No hook of Gemini CLI can approve a tool call, so Blossom shows the session as needing you, with no request panel.
The hooks are an entry in a Gemini CLI settings file. You can try them in one session, or install them for every session.

You need:

- Blossom. It includes this adapter and the Bun that runs it; from a clone, `bun run build` makes one.
- Gemini CLI. Read from the source of `v0.71.1`, not run against a real Gemini CLI; hook payloads may change between releases.
- `curl`, which every hook runs as `/usr/bin/curl -q`, `ps`, which the hook of `BeforeAgent` runs as `/bin/ps`, and `bash`, which Gemini CLI runs every hook with. macOS ships them.
- `jq`, only to install or remove the hooks by hand.

How it is built, what was read and what is not verified is in [../../documentation/roadmap/gemini.md](../../documentation/roadmap/gemini.md).

## Connect from Blossom

The quickest way. Blossom finds Gemini CLI on your Mac, and connecting it is one click: "Continue" on the second step of the introduction, with Gemini CLI checked, or its switch in Settings > Agents. Blossom then adds this adapter to its configuration, starts it, and puts the hooks of `adapters/gemini/settings.json` in `~/.gemini/settings.json`, after the hooks you already have. Nothing of yours changes, and a file that does not exist is created with the hooks alone.

Before it writes over the file, Blossom keeps a copy of it in `~/Library/Application Support/Blossom/backups/gemini/`, named after the moment in UTC. It writes the new content to a file next to yours and moves it into place, so a failure halfway leaves your file as it was; a symbolic link stays a link. A file that is not plain JSON, such as one with comments, or that is read-only, Blossom leaves alone and says why in its row. Gemini CLI accepts comments in its settings; Blossom does not keep them, so a file with comments is connected by hand. Blossom does not follow `GEMINI_CLI_HOME`. Gemini CLI runs the hooks only in folders you trusted in it, which the row reminds you of. "Repair" in the row puts the hooks back when they are missing or not the ones this Blossom installs. "Disconnect", shown while the agent is off, takes the adapter out of Blossom and its hooks out of the file, and nothing else. What Blossom writes and why is in [the decision](../../documentation/decisions/connecting.md).

## Run Blossom with the adapter

From the root of the clone:

```sh
bun install && bun run bootstrap && bun run build
BLOSSOM_CONFIGURATION=adapters/gemini/configuration.json apps/macos/build/Build/Products/Debug/Blossom.app/Contents/MacOS/Blossom
```

`bootstrap` installs the toolchain the build needs; see [../../documentation/contributing.md](../../documentation/contributing.md).

The notch shows nothing until a session of Gemini CLI reports. Run one Blossom at a time: the adapter holds the socket, and the adapter of a second Blossom logs `cannot listen for the hooks of gemini cli` and exits.

### From Finder

An app opened from Finder reads `~/Library/Application Support/Blossom/configuration.json`. Name the adapter by its package, which Blossom includes, so neither a path nor Bun is needed:

```json
{ "adapters": [{ "package": "gemini" }] }
```

If the file already exists, add the adapter to its `adapters` list instead, next to the Claude Code adapter if it is there. Then open `apps/macos/build/Build/Products/Debug/Blossom.app`. The adapter runs from inside the app, so moving or updating the app changes nothing in the file; how Blossom finds a package is in [`../../documentation/architecture/adapters.md`](../../documentation/architecture/adapters.md).

## Try it in one session

Nothing is installed. With Blossom running, start Gemini CLI in any project with the hooks of the adapter as its system defaults, the settings layer with the lowest precedence:

```sh
GEMINI_CLI_SYSTEM_DEFAULTS_PATH="<absolute path of the clone>/adapters/gemini/settings.json" gemini
```

Gemini CLI adds the hooks of every settings layer together, so yours still run, and nothing else changes: the file holds only hooks. For that session it reads this file in place of `/Library/Application Support/GeminiCli/system-defaults.json`, which most Macs do not have; if yours does, its defaults are left out of that session.

Gemini CLI runs no hook in a folder it does not trust, so trust the folder when it asks.

What you should see:

- Nothing when the session opens. The Gemini CLI tile appears next to the notch with the first prompt.
- No badge while it works.
- The green badge when a turn ends.
- The amber badge while Gemini CLI asks you to confirm a tool. Answer in Gemini CLI. Blossom shows no request panel for it.
- The tile gone when the session closes.

## Install by hand

For a clone without the app, a settings file with comments, or a file Blossom leaves alone. The `hooks` of `adapters/gemini/settings.json` go into your `~/.gemini/settings.json`, next to the hooks you already have. If you set `GEMINI_CLI_HOME`, the file is `$GEMINI_CLI_HOME/.gemini/settings.json` instead: use that path in every command below. The commands below write a new file, and you put its content in place.

If `~/.gemini/settings.json` does not exist, there is nothing to merge. Copy the file of the adapter and stop here. The copy never overwrites a file that is there:

```sh
mkdir -p ~/.gemini && cp -n adapters/gemini/settings.json ~/.gemini/settings.json
```

Otherwise, from the root of the clone, write the merged settings to a new file that only you can read, like your settings. Each hook of the adapter is added after the hooks you have for the same event; nothing of yours changes.

```sh
(umask 077 && jq -n --slurpfile user ~/.gemini/settings.json --slurpfile blossom adapters/gemini/settings.json '
  ($user[0] // {}) | .hooks = reduce ($blossom[0].hooks | to_entries[]) as $event
    (.hooks // {}; .[$event.key] += $event.value)
' > ~/.gemini/settings.merged.json)
```

If `jq` printed an error, stop and delete the new file, which is empty: `rm ~/.gemini/settings.merged.json`. Gemini CLI accepts comments in its settings and `jq` does not, so a file with comments stops here too. Then add the six entries of `adapters/gemini/settings.json` under `hooks` by hand, or take the comments out first.

Otherwise review the new file. The only differences are added hooks named `blossom` that name the socket:

```sh
diff <(jq -S . ~/.gemini/settings.json) <(jq -S . ~/.gemini/settings.merged.json)
```

Keep a copy of your settings and put the new content in place. A backup that already exists is kept, so the first one survives. The second line does nothing when the new file is empty or not valid JSON, and it replaces the content of your file, not the file: a symbolic link and the mode of the file stay as they are.

```sh
cp -n ~/.gemini/settings.json ~/.gemini/settings.backup.json
jq -e . ~/.gemini/settings.merged.json > /dev/null && cp ~/.gemini/settings.merged.json ~/.gemini/settings.json && rm ~/.gemini/settings.merged.json
```

Install once. Running the commands again adds every hook a second time; Gemini CLI runs two identical hooks once, but remove first anyway.

A session started after that reports to Blossom, from its first prompt on, in every folder Gemini CLI trusts. A session that was already running when you installed is not expected to pick the hooks up.

## Remove by hand

After an install by hand; after connecting from Blossom, Disconnect does it, and removing Blossom takes out the hooks of every tool, see [Removing it](../../documentation/privacy.md#removing-it). Write your settings without the hooks of the adapter to a new file. The command drops the hooks named `blossom` whose command names the socket, the groups and events they leave empty, and `hooks` when nothing is left in it. Every other hook stays as it is, and so does any key under `hooks` that is not a list of hooks.

```sh
(umask 077 && jq '
  def blossom: type == "object" and .name == "blossom" and ((.command | type) == "string" and (.command | contains("Application Support/Blossom/gemini/socket\"")));
  def grouped: type == "object" and (.hooks | type) == "array";
  def mine: grouped and (.hooks | length > 0 and all(.[]; blossom));
  def cleaned: map(if mine then empty elif grouped then .hooks |= map(select(blossom | not)) else . end);
  if (.hooks | type) == "object" and (.hooks | length) > 0 then
    .hooks |= with_entries(if (.value | type) == "array" and (.value | length) > 0 then (.value |= cleaned) | select(.value | length > 0) else . end)
    | if .hooks == {} then del(.hooks) else . end
  else . end
' ~/.gemini/settings.json > ~/.gemini/settings.cleaned.json)
```

If `jq` printed an error, or the new file is empty or holds only `null`, stop and delete it: `rm ~/.gemini/settings.cleaned.json`. A file with comments stops here too; then take the six entries named `blossom` out by hand.

Review it and put the new content in place, as when installing. The line that keeps a copy does nothing after an install made with the commands above: the backup is the one from before installing, and it is never overwritten.

```sh
diff <(jq -S . ~/.gemini/settings.json) <(jq -S . ~/.gemini/settings.cleaned.json)
cp -n ~/.gemini/settings.json ~/.gemini/settings.backup.json
jq -e . ~/.gemini/settings.cleaned.json > /dev/null && cp ~/.gemini/settings.cleaned.json ~/.gemini/settings.json && rm ~/.gemini/settings.cleaned.json
```

Check that nothing is left. This prints `0`:

```sh
jq '[.. | objects | select(.name == "blossom" and (.command | tostring | contains("Blossom/gemini/socket\"")))] | length' ~/.gemini/settings.json
```

An event that held an empty list in your settings before the install comes back without that key, and an empty `hooks` comes back without `hooks`: Gemini CLI reads both the same way.

A session that got the hooks from `GEMINI_CLI_SYSTEM_DEFAULTS_PATH` has nothing to remove.

## What to know

- **The name is the repository and the branch.** The hook of `BeforeAgent` adds the folder of the session, from `GEMINI_CWD`, when it is an absolute path of letters, digits, spaces and `+,./@_~-`, 256 characters at most; a folder with any other character names no session. The project is the repository and the branch of its folder, read from `HEAD` and the pointers of `.git` at most once every five seconds, without running `git`; the branch is the title, or the folder outside a repository. The hooks pass on no prompt, so the prompt never titles a session. Hooks installed before this version send no folder: connect Gemini CLI again. See [../../documentation/decisions/names.md](../../documentation/decisions/names.md).
- **Confirmations stay in Gemini CLI.** Gemini CLI decides whether to ask after its `BeforeTool` hook has run, and the `Notification` hook that comes with the dialog decides nothing, so no hook can approve a call. Blossom shows that the session needs you and you answer in Gemini CLI. Blossom never answers anything for Gemini CLI.
- **After you approve, the amber badge stays until the tool ends.** Nothing is reported between the answer and the end of the tool, so a long command keeps the session waiting in Blossom until it finishes. Another tool that Gemini CLI checks meanwhile does not end the wait either.
- **A tool that ends while you are asked ends the wait.** Gemini CLI can run calls side by side, and subagents run their own: when one of them ends while the dialog of another is still open, the session shows working although Gemini CLI still waits for you. Nothing in the hooks tells the calls apart.
- **After you deny, the amber badge stays until your next prompt.** Gemini CLI reports nothing when every tool of a batch was denied. It is your turn then, so the badge is not wrong, only less exact than green.
- **An interrupted turn stays working.** Gemini CLI reports nothing when you press `esc`, so the session shows working until your next prompt, or until it closes.
- **A failed turn shows as done.** When the request to the model fails, Gemini CLI reports the end of the turn as it does for a turn that worked. The red badge never shows for Gemini CLI.
- **Headless runs show.** A run of `gemini -p` reports like a session in the terminal: nothing in its hooks tells them apart. It shows while it runs and leaves when it ends.
- **Every notification makes the session wait.** The only kind Gemini CLI sends is the one of a confirmation, `ToolPermission`, and the hook does not pass the kind on. A later release that adds another kind would show it as waiting too.
- **`/resume` inside a session leaves the old tile.** Gemini CLI switches to the identifier of the resumed session and reports no end for the old one, so its tile stays, done or waiting, until Gemini CLI exits or you dismiss it. Read in the source, not tried. The same happens when you choose to keep using the fallback model after a quota error: Gemini CLI gives the session a new identifier then.
- **Only safe session identifiers report.** A hook sends the identifier only when it is at most 64 letters, digits, dots, dashes and underscores, as the identifiers Gemini CLI makes are. `--session-id` takes only letters, digits, `-` and `_`, so only a value longer than 64 characters does not report.
- **Untrusted folders do not report.** Gemini CLI runs no hook from a settings file, yours included, in a folder it does not trust. Hooks of extensions still run there.
- **Sandboxed sessions are not verified.** With `--sandbox`, Gemini CLI runs inside `sandbox-exec` or a container. A profile that keeps it from your folder, or a container, keeps the hooks from the socket, and the session does not show.
- **Gemini CLI shows the hook while it runs.** Its terminal names a running hook, here `blossom`, for three seconds at least. `hooksConfig.notifications` set to `false` in your settings hides those lines; the hooks still run. `/hooks disable blossom` turns them off, and Gemini CLI writes that into the settings of the project or your own; `/hooks enable blossom` turns them on again.
- **Without Blossom, Gemini CLI works as before.** With Blossom closed nothing listens on the socket: each hook gives up at once, prints nothing and ends without an error. That holds too when a Blossom that was killed left its socket behind.
- **The hooks print nothing.** Gemini CLI reads what a hook prints on standard output, and on standard error when standard output is empty, and takes text it cannot read as JSON as a message to show or a decision. Every command sends everything it runs, on both streams, to `/dev/null`, so neither a configuration file of `curl` nor whatever answers on the socket can make a hook say anything, and neither can tracing turned on through `SHELLOPTS` with an ordinary `PS4`. It names `/usr/bin/curl` and `/usr/bin/true` in full, so a program earlier in the `PATH` or a function exported into the environment does not run in their place. That was tested with the `bash` of macOS, 3.2; Gemini CLI runs the first `bash` in your `PATH`, and a newer one, such as Homebrew's, was not tried.
- **The hooks send nothing of what Gemini CLI tells them.** Gemini CLI gives a hook the whole event: your prompt, the input of a tool, the content of a file it writes, the output of a command. The hooks read none of it. Each sends the identifier of the session, which Gemini CLI puts in `GEMINI_SESSION_ID`, and the name of its own event, so a process that takes the socket learns no more than that. The hook of `BeforeAgent` adds where the session runs, below.
- **The hooks ignore your curl configuration.** `-q` keeps `curl` from reading `~/.curlrc`, `~/.config/curlrc` and the files that `CURL_HOME` and `XDG_CONFIG_HOME` point at. Without it a line of such a file could copy every payload, prompts included, to a file of its choice. Nothing you set there applies to the hooks.
- **The environment is trusted.** `bash` runs the file named in `BASH_ENV` before the command of a hook, and what it prints is read by Gemini CLI, and an exported function with a broken name makes `bash` print a warning. So does `SHELLOPTS=verbose`, which echoes the command to standard error, and tracing with a `PS4` that writes to a descriptor `bash` keeps for itself. Gemini CLI then shows that text; a decision it reads there still cannot approve a tool. Whoever sets the environment Gemini CLI starts in can already run anything in a hook.
- **A Blossom that does not answer costs a second.** When the adapter is alive but does not answer, with Blossom suspended for example, every event waits one second.
- **The first hook of a turn finds the terminal of its session.** Before it posts, the hook of `BeforeAgent` walks up its processes with `/bin/ps`, from the Gemini CLI process that runs the session, sixteen at most, for the terminal device and the processes above it, and reads the variables terminal programs and multiplexers set, such as `TERM_PROGRAM`, `__CFBundleIdentifier`, `TMUX_PANE` and `KITTY_WINDOW_ID`. Gemini CLI passes its environment to the hook, and none of those names is one it drops when it redacts. Each value is sent in a header only when it is short and of plain characters, and Blossom keeps it in memory, shows it nowhere, and uses it to bring that terminal forward when you ask. It adds about 50 ms to a prompt, and to no other hook. In a sandbox `/bin/ps` may be refused: the hook then sends what the variables say, or nothing, and prints nothing. Hooks connected before this version need Repair in Settings > Agents.
- **Every event runs `curl`.** A hook is a short process, and Gemini CLI waits for it: a few milliseconds per event. The adapter installs six hooks, and none on the events that run once per streamed chunk. The hooks do not read what Gemini CLI writes to them; Gemini CLI ignores the broken pipe that leaves.
- **A session whose Gemini CLI was killed leaves within seconds.** Every command names the process that started its shell, in the header `Blossom-Process`. `bash` sets `$PPID` itself and ignores a variable of that name in the environment. Gemini CLI runs as two processes: the one you start starts a second one, which runs the session and its hooks, unless `GEMINI_CLI_NO_RELAUNCH` is set. The hooks name that second one. Every five seconds the adapter asks the system whether that process still exists, and a session whose process is gone leaves the notch. The limits:
  - If the system has already given the identifier to another process, the session stays until that one ends too.
  - If a `bash` earlier in your `PATH` is a script that starts the real one without `exec`, the hooks name that script, which ends with the hook. The tile then leaves within five seconds of each event and comes back with the next.
  - With two Gemini CLI processes on one session, as after resuming it in a second terminal, the last one to report is the one watched.
- **A session shows up when it starts working.** An open session with nothing typed shows nothing. After `/clear` the tile leaves and comes back with the next prompt, and a resumed session comes back with its next prompt.
- **Subagents are part of their session.** Their tools report as the session working, and their confirmations as the session needing you. How many run is not known.
- **The socket is yours alone.** It lives in a folder only your user can open, and the adapter refuses to start when that folder is a symbolic link or belongs to someone else. Another user of the Mac can neither post events nor take the place of the adapter. A process that runs as you still can: it can make a session look working, done, waiting or closed, or, by listening on the socket while Blossom is closed, learn which sessions run and when. It cannot answer anything, because the hooks print nothing, and it reads no prompt, because the hooks send none. That is the trust your own Gemini CLI settings file already has: such a process can also rewrite `~/.gemini/settings.json`. See the decision in [../../documentation/decisions/socket.md](../../documentation/decisions/socket.md).
- **The hooks find the socket through `$HOME`.** The adapter derives the same path from the home folder of the user. A session started with another `HOME` does not report, and works as without Blossom. `GEMINI_CLI_HOME` changes where Gemini CLI keeps its files, not where the hooks look.

## Checks by hand

The adapter was tested with its hook commands run by `bash` against the socket, with what they send, and with sequences of events read from the source of Gemini CLI, never captured from a run: it is not run against a real Gemini CLI. Each check below needs Gemini CLI installed and signed in. Write down what the line in italics asks.

Prepare once. Run Blossom with the adapter, then, in another terminal:

```sh
cd "$(mktemp -d)"
GEMINI_CLI_SYSTEM_DEFAULTS_PATH="<absolute path of the clone>/adapters/gemini/settings.json" gemini
```

Trust the folder. The notch shows nothing yet: the tile appears with the first prompt. In each check, "ask" means type the prompt.

1. **A turn.** Ask `hi`. *Does the tile appear with the prompt, with no badge, and turn green when the answer ends?*
2. **A confirmation.** Ask `run the shell command touch probe.txt`. *Does the badge turn amber when the dialog appears in the terminal?* Approve it there. *Does the amber badge leave when the command has run, and turn green when the answer ends?*
3. **A denial.** Ask `run the shell command touch denied.txt` and deny it in the terminal. *Does the badge stay amber, and leave with your next prompt?*
4. **A long command.** Ask `run the shell command sleep 20` and approve it. *Does the amber badge stay for the twenty seconds?*
5. **An interrupt.** Ask `count from 1 to 300, one number per line` and press `esc` halfway. *Does the tile stay without a badge, and turn green only after the next prompt?*
6. **A failure.** Start another session with `--model nonexistent-model-xyz` and ask `hi`. *Does the tile turn green, as expected, and not red?*
7. **Clear.** In the first session, run `/clear`. *Does the tile leave at once, and come back with the next prompt?*
8. **Quit.** Run `/quit`. *Does the tile leave at once?* Start again and quit with two `ctrl+c`. *The same?*
9. **A Gemini CLI that is killed.** Start two sessions the same way in two terminals and ask `hi` in both. `ps -ax -o pid,ppid,command | grep '[g]emini'` lists their processes, two per session: run `kill -9` on the one of the second session whose parent is another `gemini` process, the one that runs the session. *Does its tile leave within about five seconds?* Leave the first idle for a minute. *Does its tile stay the whole minute?* It must: a tile that leaves and comes back with the next prompt means the hooks name a process that is not Gemini CLI.
10. **Quitting Blossom.** Quit Blossom and ask `hi`. *Does Gemini CLI keep working, with no hook warning in the terminal?*
11. **An untrusted folder.** Start a session in another new folder and do not trust it. Ask `hi`. *Does no tile appear?*
12. **A subagent.** Ask `use the codebase investigator to find where this folder's files are listed`. *Does one tile stay, with no second one, and turn green once?*
13. **Installed for every session.** After installing as above, start `gemini` in a trusted folder without `GEMINI_CLI_SYSTEM_DEFAULTS_PATH` and ask `hi`. *Does the tile appear?* Remove as above. *Does a new session no longer show?*
14. **The terminal of a session.** Send a prompt from Terminal, one from iTerm and one inside tmux. *Does each prompt start as quickly as before, and does the terminal show no hook warning?*
