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 geminishellfirm — 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
{
"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_commandis checked as a shell command (with itsdir_path);write_fileandreplaceare checked as edits;read_fileis checked likecat <path>, and aread_many_filescall like a read of every path ininclude(orpaths). A directory is read as everything in it (~/.sshlike~/.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 shellfirmturns it off (hooksConfig.disabled), andshellfirm statusthen says so. Runningconnect geminiagain takes it out of that list in the file it writes. hooksConfig.enabled: falseturns every hook off;connectandstatussay 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
| Command | Answer | Effect |
|---|---|---|
No check matches (ls) | nothing | Gemini'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):
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
| Option | Effect |
|---|---|
--scope user (default) | ~/.gemini/settings.json |
--scope project | ./.gemini/settings.json; Gemini asks you to trust project hooks |
--dry-run | Show what would change, write nothing |
--uninstall | Remove shellfirm's entries only |
Check the integration
Agent integrations:
gemini (user): hook yes, file tools yes, fail-closed no, MCP n/aconnect gemini installs only the hook. To register shellfirm's MCP tools as well, see Other agents.