Skip to content
$ shellfirm

Gemini CLI

A BeforeTool hook that checks Gemini CLI shell commands, file writes, edits and reads; risky ones ask, dangerous ones are denied.

Asking needs Gemini CLI 0.36.0 or later. Older versions ignore an ask, so the command runs (dangerous commands are still denied).

Connect

shellfirm connect gemini
Output
shellfirm — connecting Gemini CLI integration

  /home/dev/.gemini/settings.json:
    - add hooks.BeforeTool entry (matcher "^(run_shell_command|write_file|replace|read_file|read_many_files)$") running `shellfirm check --hook gemini --config-dir /home/dev/.config/shellfirm`
    ✓ written

Gemini CLI shell commands, file writes and reads are now checked by shellfirm (BeforeTool hook: risky -> ask, dangerous -> deny). Asking needs Gemini CLI 0.36.0 or later. Restart running Gemini CLI sessions.

What it installs

~/.gemini/settings.json
{
  "hooks": {
    "BeforeTool": [
      {
        "matcher": "^(run_shell_command|write_file|replace|read_file|read_many_files)$",
        "hooks": [
          {
            "name": "shellfirm",
            "type": "command",
            "command": "shellfirm check --hook gemini --config-dir /home/dev/.config/shellfirm",
            "timeout": 30000
          }
        ]
      }
    ]
  }
}
  • Gemini matchers are regular expressions, and its timeouts are milliseconds (30 s).
  • run_shell_command is checked as a shell command (with its dir_path); write_file and replace are checked as edits; read_file is checked like cat <path>, and a read_many_files call like a read of every path in include (or paths). A directory is read as everything in it (~/.ssh like ~/.ssh/*), and a directory or glob that holds or matches a key or credential file (~, ~/.kube, ~/.gnupg, ~/.ss?, ~/.aws/**, **/* from the home directory) like a read of that file. A call without a list of paths is denied.
  • The hook is named shellfirm: /hooks disable shellfirm turns it off (hooksConfig.disabled), and shellfirm status then says so. Running connect gemini again takes it out of that list in the file it writes.
  • hooksConfig.enabled: false turns every hook off; connect and status say so and leave the switch to you.
  • Your other settings and hooks are kept. Comments in the file are read, but not kept.

What Gemini sees

CommandAnswerEffect
No check matches (ls)nothingGemini's own approvals apply
Risky, below the auto-deny threshold (cat ~/.ssh/id_rsa, Medium){"decision": "ask", ...}Gemini shows its confirmation prompt with shellfirm's systemMessage
At or above the threshold, or deny-listed (git push -f origin main, High){"decision": "deny", ...}Blocked; the reason goes to the model

Real ask answer for cat ~/.ssh/id_rsa (the reason and systemMessage hold the same text):

Output
shellfirm flagged this command as risky; confirm before running.
[exfil:read_secret_file] [MEDIUM] This reads a private key or a credentials file. Shown on screen it can leak (screen sharing, terminal logs); run by an AI agent, the secret goes into the conversation and on to the model provider.
Reason: Matched risky pattern(s) (severity MEDIUM, below the auto-deny threshold HIGH); confirm before running
Safe alternative: read only what you need, not the secret itself (An SSH private key: `ssh-keygen -y -f <key>` prints just the public half. A credentials file: a command that hides the secret shows the same, e.g. `aws configure list`, `kubectl config view`, `gh auth status`, `npm config list`.)

Real deny answer for git push -f origin main:

{"decision":"deny","reason":"shellfirm BLOCKED this command.\n[git:force_push] [HIGH] This force-pushes and can overwrite remote history.\nContext: Critical (target=main)\nBLOCKED: Severity HIGH meets or exceeds agent auto-deny threshold HIGH\nSafe alternative: git push --force-with-lease (Checks that your local ref is up-to-date before force pushing, preventing accidental overwrites of others' work.)","systemMessage":"shellfirm BLOCKED this command. Severity HIGH meets or exceeds agent auto-deny threshold HIGH"}

If shellfirm cannot run, Gemini CLI blocks the call, except when shellfirm exits with status 1 (a missing binary or a crash is blocked).

Headless runs

In a headless run (gemini -p --yolo), Gemini CLI 0.69 waits for an answer to an ask that nobody can give: the command never runs, but the run does not end either. Give such runs a timeout, or set agent.auto_deny_severity: Medium so risky commands are denied instead of asked (see Agent decisions). Dangerous commands are denied and the run goes on.

gemini -y, gemini -yp x, gemini -p -y, --approval-mode yolo and npx @google/gemini-cli -y started by an agent, or a fresh GEMINI_CLI_HOME, ask first, like the other hook bypasses (see self-protection).

Options

OptionEffect
--scope user (default)~/.gemini/settings.json
--scope project./.gemini/settings.json; Gemini asks you to trust project hooks
--dry-runShow what would change, write nothing
--uninstallRemove shellfirm's entries only

Check the integration

Output
  Agent integrations:
    gemini (user): hook yes, file tools yes, fail-closed no, MCP n/a

connect gemini installs only the hook. To register shellfirm's MCP tools as well, see Other agents.