shellfirm connect
Install shellfirm's blocking hooks into nine AI coding agents, and register the MCP server where the agent supports it.
shellfirm connect sets up AI coding tools in one command. It installs an
agent hook that the agent runs before a tool call (shell commands and,
where the agent has them, file edits and reads), and for Claude Code, Cursor,
Windsurf and Cline it also registers the MCP server (tools the agent can
call). For Zed it registers the MCP tools only.
Usage: shellfirm connect [OPTIONS] [COMMAND]| Subcommand | What it installs |
|---|---|
claude-code | PreToolUse hook + MCP server |
cursor | beforeShellExecution, preToolUse and beforeReadFile hooks + MCP server |
codex | OpenAI Codex CLI PreToolUse hook (Codex 0.124.0 or later) |
gemini | Gemini CLI BeforeTool hook |
qwen | Qwen Code PreToolUse hook |
copilot | GitHub Copilot CLI preToolUse hook (Copilot CLI 1.0.4 or later) |
windsurf | Cascade hooks (pre_run_command, pre_write_code, pre_read_code) + MCP server |
cline | PreToolUse hook script + MCP server (Cline 3.36 or later; macOS and Linux) |
opencode | OpenCode plugin (tool.execute.before) |
zed | MCP tools only (advisory; no interception) |
MCP tools are advisory: the agent decides whether to call them. The hooks intercept commands automatically. Codex CLI, Windsurf, Cline and OpenCode hooks cannot ask, so shellfirm blocks risky commands there (with the reason and a safer alternative) instead of asking.
claude-code
Usage: shellfirm connect claude-code [OPTIONS]| Option | Description |
|---|---|
--no-fail-closed | Do not add "onFailure": "block" to the hook (for Claude Code older than 2.1.295). Also removes it from existing shellfirm hooks. Only claude-code has this flag; run by an agent, it needs approval (shellfirm-self:connect_fail_open). |
--hooks-only | Only the command-interception hook (no MCP) |
--mcp-only | Only the MCP server registration (no hook) |
--scope <scope> | user: your home directory (default); project: the current directory (for team rollout) |
--dry-run | Show what would change without writing anything |
--uninstall | Remove shellfirm's entries (only those; other config is kept) |
-h, --help | Print help |
| Scope | Hook | MCP server |
|---|---|---|
user | ~/.claude/settings.json ($CLAUDE_CONFIG_DIR/settings.json when set) | ~/.claude.json ($CLAUDE_CONFIG_DIR/.claude.json) |
project | ./.claude/settings.json | ./.mcp.json |
connect never writes Claude Code's managed settings file. To enforce the hook
for every user of a machine, put the entry there yourself: see
Managed settings.
shellfirm status lists it as claude-code (managed).
The hook runs shellfirm check --hook claude-code before every tool call
that runs a shell command (matcher Bash|PowerShell|Monitor). Risky commands
get an ask prompt, dangerous ones are denied, and everything else is left
to Claude Code's normal permission rules. A second PreToolUse entry (matcher
Write|Edit|MultiEdit|NotebookEdit) asks before the agent edits shellfirm,
project-policy, agent-settings, hook or shell startup files, or overwrites a
private key or credential file (shellfirm-self:credential_file_edit). A third
(matcher Read) asks before the agent reads a private key or a credentials
file.
Hooks are written with "timeout": 30 and "onFailure": "block": Claude
Code 2.1.295 and later then block the tool call when shellfirm is
missing, crashes or times out (fail closed; see onFailure in the
Claude Code hooks reference).
$ shellfirm connect claude-code
shellfirm — connecting Claude Code integration
/home/dev/.claude/settings.json:
- add hooks.PreToolUse entry (matcher "Bash|PowerShell|Monitor") running `shellfirm check --hook claude-code --config-dir /home/dev/.config/shellfirm`
- add hooks.PreToolUse entry (matcher "Write|Edit|MultiEdit|NotebookEdit") so edits to shellfirm, policy, agent-settings and shell startup files need approval
- add hooks.PreToolUse entry (matcher "Read") so reading a private key or a credentials file needs approval
✓ written
/home/dev/.claude.json:
- add mcpServers.shellfirm = {"type":"stdio","command":"shellfirm","args":["mcp","--config-dir","/home/dev/.config/shellfirm"],"env":{}}
✓ written
Claude Code Bash/PowerShell/Monitor commands are now checked by shellfirm before they run (risky -> ask, dangerous -> deny; everything else follows your normal Claude Code permissions). Restart running Claude Code sessions.The hook it wrote:
{
"hooks": {
"PreToolUse": [
{
"matcher": "Bash|PowerShell|Monitor",
"hooks": [
{
"type": "command",
"command": "shellfirm check --hook claude-code --config-dir /home/dev/.config/shellfirm",
"timeout": 30,
"onFailure": "block"
}
]
},
{
"matcher": "Write|Edit|MultiEdit|NotebookEdit",
"hooks": [
{
"type": "command",
"command": "shellfirm check --hook claude-code --config-dir /home/dev/.config/shellfirm",
"timeout": 30,
"onFailure": "block"
}
]
},
{
"matcher": "Read",
"hooks": [
{
"type": "command",
"command": "shellfirm check --hook claude-code --config-dir /home/dev/.config/shellfirm",
"timeout": 30,
"onFailure": "block"
}
]
}
]
}
}User-scope hooks record the configuration directory (--config-dir), so a
redirected HOME or XDG_CONFIG_HOME cannot swap in other settings.
Project-scope hooks do not pin it, and their backups go to
~/.cache/shellfirm/backups, not into the repository:
$ shellfirm connect claude-code --scope project --dry-run
shellfirm — connecting Claude Code integration (dry run)
Would create /home/dev/projects/webapp/.claude/settings.json:
- add hooks.PreToolUse entry (matcher "Bash|PowerShell|Monitor") running `shellfirm check --hook claude-code`
- add hooks.PreToolUse entry (matcher "Write|Edit|MultiEdit|NotebookEdit") so edits to shellfirm, policy, agent-settings and shell startup files need approval
- add hooks.PreToolUse entry (matcher "Read") so reading a private key or a credentials file needs approval
Would create /home/dev/projects/webapp/.mcp.json:
- add mcpServers.shellfirm = {"type":"stdio","command":"shellfirm","args":["mcp"],"env":{}}
Dry run: no changes were made. Run without --dry-run to apply.Upgrading a 0.3.10 hook
Re-running connect upgrades existing shellfirm hooks in place (also legacy
ones and ones with extra flags such as --log debug), removes duplicates and
writes a backup first:
$ shellfirm connect claude-code --hooks-only
shellfirm — connecting Claude Code integration
/home/dev/.claude/settings.json:
- upgrade 1 existing shellfirm hook(s) in place, replacing 1 legacy command line(s) with `shellfirm check --hook claude-code --config-dir /home/dev/.config/shellfirm` (timeout 30s, onFailure: block, pinned --config-dir)
- add hooks.PreToolUse entry (matcher "PowerShell|Monitor") running `shellfirm check --hook claude-code --config-dir /home/dev/.config/shellfirm`
- add hooks.PreToolUse entry (matcher "Write|Edit|MultiEdit|NotebookEdit") so edits to shellfirm, policy, agent-settings and shell startup files need approval
- add hooks.PreToolUse entry (matcher "Read") so reading a private key or a credentials file needs approval
✓ written (backup: /home/dev/.claude/settings.json.shellfirm-bak-20261027T223533Z-1)
Claude Code Bash/PowerShell/Monitor commands are now checked by shellfirm before they run (risky -> ask, dangerous -> deny; everything else follows your normal Claude Code permissions). Restart running Claude Code sessions.Restart running Claude Code sessions afterwards. Until you re-run connect,
the 0.3.10 hook line keeps working and shellfirm status reports it as a
legacy hook.
cursor
Usage: shellfirm connect cursor [OPTIONS]Options: --hooks-only, --mcp-only, --scope <user|project>,
--dry-run, --uninstall (as for claude-code; there is no
--no-fail-closed).
| Scope | Files |
|---|---|
user | ~/.cursor/hooks.json and ~/.cursor/mcp.json |
project | ./.cursor/hooks.json and ./.cursor/mcp.json |
The beforeShellExecution hook answers deny or ask for risky commands and
prints nothing for safe ones. A preToolUse hook (matcher Write|Delete)
denies agent edits of shellfirm, policy, agent-settings, hook and shell
startup files, and overwrites of private keys and credential files: Cursor
does not enforce ask for preToolUse, so you make such changes by hand. A
beforeReadFile hook denies agent reads of private keys and credential files
(Cursor can only allow or deny a read there; other reads get no answer).
$ shellfirm connect cursor --dry-run
shellfirm — connecting Cursor integration (dry run)
Would create /home/dev/.cursor/hooks.json:
- add hooks.beforeShellExecution entry running `shellfirm check --hook cursor --config-dir /home/dev/.config/shellfirm`
- add hooks.preToolUse entry (matcher "Write|Delete") so agent edits to shellfirm, policy, agent-settings and shell startup files are blocked
- add hooks.beforeReadFile entry so agent reads of private keys and credential files are blocked
Would create /home/dev/.cursor/mcp.json:
- add mcpServers.shellfirm = {"command":"shellfirm","args":["mcp","--config-dir","/home/dev/.config/shellfirm"]}
Dry run: no changes were made. Run without --dry-run to apply.Cursor hooks are not fail-closed
The hooks are not marked failClosed. Cursor counts "no output" as a failure
and would then block every safe command, so connect cursor leaves it off
(and removes it from older shellfirm hooks). If shellfirm is missing or times
out, Cursor lets the action through. shellfirm status shows
fail-closed no for Cursor; that is expected. shellfirm itself never exits
without a decision for risky input: a crash becomes a deny.
Re-run shellfirm connect cursor after upgrading: Cursor gains its
preToolUse hook (missing after 0.3.10) and its beforeReadFile hook (new in
0.4.2) only this way.
codex, gemini, qwen, copilot, opencode
Usage: shellfirm connect codex [OPTIONS]
Usage: shellfirm connect gemini [OPTIONS]
Usage: shellfirm connect qwen [OPTIONS]
Usage: shellfirm connect copilot [OPTIONS]
Usage: shellfirm connect opencode [OPTIONS]| Option | Description |
|---|---|
--scope <scope> | user: your home directory (default); project: the current directory (for team rollout) |
--dry-run | Show what would change without writing anything |
--uninstall | Remove shellfirm's entries (only those; other config is kept) |
-h, --help | Print help |
These install a hook only (no MCP server).
| Agent | user scope | project scope | Risky (ask) |
|---|---|---|---|
codex | ~/.codex/hooks.json ($CODEX_HOME/hooks.json) | ./.codex/hooks.json (loaded in trusted projects) | denied |
gemini | ~/.gemini/settings.json | ./.gemini/settings.json (Gemini asks you to trust project hooks) | asks (Gemini CLI 0.36.0 or later) |
qwen | ~/.qwen/settings.json | ./.qwen/settings.json (Qwen Code asks you to approve project hooks) | asks (headless runs deny) |
copilot | ~/.copilot/hooks/shellfirm.json ($COPILOT_HOME/hooks/) | ./.github/hooks/shellfirm.json (also run by Copilot cloud agent) | asks (autopilot and cloud agent deny) |
opencode | ~/.config/opencode/plugins/shellfirm.js ($XDG_CONFIG_HOME) | ./.opencode/plugins/shellfirm.js | denied |
codex
A PreToolUse hook (matcher Bash|apply_patch) runs shellfirm check --hook
codex before every shell command and apply_patch edit. Codex runs a new or
changed hook only after you trust it: the TUI lists it when it starts (or use
/hooks), and codex exec skips it until then. If shellfirm is missing or
times out, Codex runs the command. [features] hooks = false in
config.toml turns hooks off: connect, status and doctor say so. See Codex CLI.
$ shellfirm connect codex --dry-run
shellfirm — connecting Codex CLI integration (dry run)
Would create /home/dev/.codex/hooks.json:
- add hooks.PreToolUse entry (matcher "Bash|apply_patch") running `shellfirm check --hook codex --config-dir /home/dev/.config/shellfirm`
Dry run: no changes were made. Run without --dry-run to apply.gemini
A BeforeTool hook named shellfirm (matcher
^(run_shell_command|write_file|replace|read_file|read_many_files)$, timeout 30000 ms). Turn
it off with /hooks disable shellfirm (hooksConfig.disabled); running
connect gemini again takes it out of that list. hooksConfig.enabled: false
turns every hook off: connect and status say so and leave the switch to
you. See Gemini CLI.
$ shellfirm connect gemini --dry-run
shellfirm — connecting Gemini CLI integration (dry run)
Would create /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`
Dry run: no changes were made. Run without --dry-run to apply.qwen
A PreToolUse hook (matcher run_shell_command|write_file|edit|read_file|read_many_files;
read_many_files is a tool only in Qwen Code versions that still expose it).
See Qwen Code.
$ shellfirm connect qwen --dry-run
shellfirm — connecting Qwen Code integration (dry run)
Would create /home/dev/.qwen/settings.json:
- add hooks.PreToolUse entry (matcher "run_shell_command|write_file|edit|read_file|read_many_files") running `shellfirm check --hook qwen --config-dir /home/dev/.config/shellfirm`
Dry run: no changes were made. Run without --dry-run to apply.copilot
A preToolUse hook with no matcher: every tool call goes through it. Copilot
denies the tool call when the hook fails (shellfirm missing or crashing),
except on a timeout. See GitHub Copilot CLI.
$ shellfirm connect copilot --dry-run
shellfirm — connecting GitHub Copilot CLI integration (dry run)
Would create /home/dev/.copilot/hooks/shellfirm.json:
- add hooks.preToolUse entry running `shellfirm check --hook copilot --config-dir /home/dev/.config/shellfirm`
Dry run: no changes were made. Run without --dry-run to apply.opencode
A plugin that sends bash, write, edit, multiedit, read, apply_patch
and patch calls to shellfirm check --hook opencode and throws (which blocks
the call) unless shellfirm allows it. An allowed call with a warning (the
review note of an agent instruction edit) is shown as a toast. It also blocks when shellfirm cannot run. See
OpenCode.
$ shellfirm connect opencode --dry-run
shellfirm — connecting OpenCode integration (dry run)
Would create /home/dev/.config/opencode/plugins/shellfirm.js:
- add the OpenCode plugin running `shellfirm check --hook opencode --config-dir /home/dev/.config/shellfirm`
Dry run: no changes were made. Run without --dry-run to apply.windsurf, cline
Usage: shellfirm connect windsurf [OPTIONS]
Usage: shellfirm connect cline [OPTIONS]| Option | Description |
|---|---|
--hooks-only | Only the command-interception hook (no MCP) |
--mcp-only | Only the MCP server registration (no hook) |
--scope <scope> | user: your home directory (default); project: the current directory (for team rollout) |
--dry-run | Show what would change without writing anything |
--uninstall | Remove shellfirm's entries (only those; other config is kept) |
-h, --help | Print help |
| Agent | user scope | project scope |
|---|---|---|
windsurf | hooks in ~/.codeium/windsurf/hooks.json, MCP server in ~/.codeium/windsurf/mcp_config.json | hooks in ./.windsurf/hooks.json (the MCP registration is user-level only) |
cline | hook script ~/Documents/Cline/Hooks/PreToolUse, MCP server in Cline's cline_mcp_settings.json | hook script ./.clinerules/hooks/PreToolUse (the MCP registration is user-level only) |
In 0.4.1 and earlier, connect windsurf and connect cline registered the MCP
server only. Running them again keeps that entry and adds the hook;
--mcp-only keeps the old behaviour.
windsurf
pre_run_command, pre_write_code and pre_read_code hooks run shellfirm
check --hook windsurf, which blocks with exit code 2 and the reason on stderr.
Cascade hooks cannot ask, so risky commands are blocked like dangerous ones.
If shellfirm is missing, Cascade runs the action. See Windsurf.
$ shellfirm connect windsurf --dry-run
shellfirm — connecting Windsurf integration (dry run)
Would create /home/dev/.codeium/windsurf/hooks.json:
- add hooks.pre_run_command entry running `shellfirm check --hook windsurf --config-dir /home/dev/.config/shellfirm`
- add hooks.pre_write_code entry running `shellfirm check --hook windsurf --config-dir /home/dev/.config/shellfirm`
- add hooks.pre_read_code entry running `shellfirm check --hook windsurf --config-dir /home/dev/.config/shellfirm`
Would create /home/dev/.codeium/windsurf/mcp_config.json:
- add mcpServers.shellfirm = {"command":"shellfirm","args":["mcp","--config-dir","/home/dev/.config/shellfirm"]}
Dry run: no changes were made. Run without --dry-run to apply.cline
The script runs shellfirm check --hook cline before every tool call and
answers {"cancel": true} (which stops the task) for dangerous and risky
commands and edits: Cline hooks cannot ask. It also cancels when shellfirm
cannot run. In the VS Code extension, turn on Enable Hooks in Cline's
settings. An existing PreToolUse script that shellfirm did not write is never
replaced. See Cline.
$ shellfirm connect cline --dry-run
shellfirm — connecting Cline integration (dry run)
Would create /home/dev/.config/Code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json:
- add mcpServers.shellfirm = {"command":"shellfirm","args":["mcp","--config-dir","/home/dev/.config/shellfirm"]}
Would create /home/dev/Documents/Cline/Hooks/PreToolUse:
- add the Cline PreToolUse hook script running `shellfirm check --hook cline --config-dir /home/dev/.config/shellfirm`
Dry run: no changes were made. Run without --dry-run to apply.zed
Usage: shellfirm connect zed [OPTIONS]| Option | Description |
|---|---|
--dry-run | Show what would change without writing anything |
--uninstall | Remove shellfirm's entries (only those; other config is kept) |
Registers shellfirm's MCP tools (context_servers). Zed has no hook that runs
before a tool call, so commands are not intercepted. The file written on Linux
(for macOS and Windows paths, including the quoted
'/Users/me/Library/Application Support/shellfirm' config dir, see
Where the files are on each OS):
$ shellfirm connect zed --dry-run
Would create /home/dev/.config/zed/settings.json:
- add context_servers.shellfirm = {"command":"shellfirm","args":["mcp","--config-dir","/home/dev/.config/shellfirm"],"env":{}}Files, backups and safety
- Existing files are backed up first. Backups of user-scope files sit next to
the file, and the newest 3 shellfirm backups of each file are kept (only
files named
<file>.shellfirm-bak-<UTC stamp>count; a file of yours such assettings.json.shellfirm-bak-mineis neither counted nor deleted); project-scope backups go to~/.cache/shellfirm/backups. - A settings path that is not a regular file (a FIFO) is reported as an error instead of being read.
- JSON with comments is read, but the comments are not kept. The output says so before the change list.
- At
--scope project, a settings file (or a directory on its path) that is a symlink out of the project is refused, and nothing is written: a link planted in a repository must not make shellfirm change another agent's user settings.statusanddoctorreport such a link. - When a settings file cannot be written (read-only),
connectprints the error without the change list. connectprints a warning when the hook it installed is turned off in the agent's settings (Claude CodedisableAllHooks, orallowManagedHooksOnly: truein managed settings; Codex[features] hooks = false; GeminihooksConfig.enabled: false):
! The hook does not run yet: disableAllHooks is true in /home/dev/.claude/settings.json: Claude Code runs no hook (remove it or set it to false).Remove the integrations again (uninstall)
--uninstall removes only shellfirm's entries, with a backup. A file that
held only shellfirm's entries is deleted, and a project-scope uninstall also
removes the directories it left empty (.github/hooks and .github after
Copilot):
$ shellfirm connect claude-code --uninstall
shellfirm — removing Claude Code integration
/home/dev/.claude/settings.json:
- remove 3 shellfirm hook(s) from hooks.PreToolUse
- delete the file (only shellfirm's entries were in it)
✓ removed (backup: /home/dev/.claude/settings.json.shellfirm-bak-20261027T223533Z)
/home/dev/.claude.json:
- remove mcpServers.shellfirm
- delete the file (only shellfirm's entries were in it)
✓ removed (backup: /home/dev/.claude.json.shellfirm-bak-20261027T223533Z)
shellfirm removed from Claude Code.Related
- Claude Code
- Cursor, Zed and MCP clients
- Supported agents: one page per agent
- shellfirm sandbox: the agent's OS sandbox
- shellfirm mcp
- shellfirm check: the hook modes the hooks run