GitHub Copilot CLI
A preToolUse hook that checks every GitHub Copilot CLI tool call; risky commands and edits ask, dangerous ones are denied.
Copilot CLI 1.0.4 or later. From 1.0.57 on, Copilot also denies a tool call when the hook crashes.
Connect
shellfirm connect copilotshellfirm — connecting GitHub Copilot CLI integration
/home/dev/.copilot/hooks/shellfirm.json:
- add hooks.preToolUse entry running `shellfirm check --hook copilot --config-dir /home/dev/.config/shellfirm`
✓ written
GitHub Copilot CLI tool calls are now checked by shellfirm (preToolUse hook: risky -> ask, dangerous -> deny; autopilot denies what would be asked). Needs Copilot CLI 1.0.4 or later. Restart running Copilot sessions.What it installs
shellfirm writes its own hook file ($COPILOT_HOME/hooks/ when COPILOT_HOME is set):
{
"version": 1,
"hooks": {
"preToolUse": [
{
"type": "command",
"bash": "shellfirm check --hook copilot --config-dir /home/dev/.config/shellfirm",
"powershell": "shellfirm check --hook copilot --config-dir /home/dev/.config/shellfirm",
"timeoutSec": 30
}
]
}
}There is no matcher: every tool call goes through the hook. shellfirm has an opinion only about bash / powershell (shell commands), write_bash / write_powershell (text typed into a running shell session, checked as a command; {enter} is a new line), create and edit (writes), view (checked like cat <path>) and apply_patch (checked file by file). Other tools get no answer.
Text typed into a running shell
Typed input with a key that edits the line or recalls history ({backspace},
{delete}, {left}, {home}, {up}, {down}, {tab}, ...; key names in
any case, {Enter} is {enter}), a raw control character other than a
newline (Ctrl-U, Backspace, an escape sequence, a tab), or bash history
expansion (!!, !$, !-1, !cmd) is denied: what it runs cannot be read
from the text. {ctrl+c} and {ctrl+d} end a line, and {esc} as the last
key (leaving a pager or menu) is allowed. Each write_bash call is checked on its own, so
a command typed across several calls (rm -rf , then ~/{enter}) is only
checked a piece at a time and can get through. Copilot CLI has no OS sandbox
shellfirm sandbox can configure; keep write_bash behind Copilot's own
permission prompt (--deny-tool) if that matters to you.
What Copilot sees
| Command | Answer | Effect |
|---|---|---|
No check matches (ls) | nothing | Copilot's own approvals apply |
Risky, below the auto-deny threshold (cat ~/.ssh/id_rsa, Medium) | {"permissionDecision": "ask", ...} | Copilot shows a prompt. Autopilot mode and the cloud agent deny it |
At or above the threshold, or deny-listed (git push -f origin main, High) | {"permissionDecision": "deny", ...} | Blocked |
Real deny answer:
{"permissionDecision":"deny","permissionDecisionReason":"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.)"}If shellfirm cannot run
Copilot denies the tool call when the hook exits non-zero (shellfirm missing or
crashing), so shellfirm status shows fail-closed yes. A hook that times
out is the exception: Copilot lets that call through.
Options
| Option | Effect |
|---|---|
--scope user (default) | ~/.copilot/hooks/shellfirm.json |
--scope project | ./.github/hooks/shellfirm.json; the Copilot cloud agent runs it too. No personal paths are recorded |
--dry-run | Show what would change, write nothing |
--uninstall | Remove shellfirm's hook file (at project scope, also the .github/hooks and .github directories it left empty) |
copilot --yolo, --allow-all-tools and --allow-all started by an agent, and a fresh COPILOT_HOME, ask first, like the other hook bypasses (see self-protection). disableAllHooks in Copilot's settings turns the hook off; shellfirm status and doctor report it.
Check the integration
Agent integrations:
copilot (user): hook yes, file tools yes, fail-closed yes, MCP n/aThe hook also reads the VS Code compatible PreToolUse input (tool_name, tool_input). To give Copilot in VS Code (agent mode) shellfirm's MCP tools, see Other agents.