Skip to content
$ shellfirm
How It Works

The check pipeline

What happens between pressing Enter and your command running (or not).

Every line you run at a hooked prompt, and every command an AI agent hook sends, goes through the same steps. The command is only text at this point: nothing has run yet.

The steps

1. A hook hands over the command

The shell hook calls shellfirm pre-command -c '<line>' before your shell runs the line. Agent hooks call shellfirm check --hook claude-code (or cursor) with the agent's tool call. The MCP server's check_command tool runs the same steps.

2. The line is parsed like a shell would

shellfirm reads the line the way the shell will run it:

  • It splits compound lines (&&, ||, ;, |, newlines, subshells) and checks every part.
  • It expands aliases, history references and the shell functions you call (see Shell setup).
  • It follows commands hidden behind other commands: sudo / doas / run0, bash -c '…', xargs, env, version managers (nvm exec, mise exec), secret runners (doppler run --, op run --), npx package spellings, and remote runs such as ssh host CMD and heroku run CMD.
  • It tracks cd and variables on the line, so D=~ sh -c 'rm -rf "$D"' and cd ~/work/app && git push -f are checked against the real target.

3. Each part is matched against the checks

The active checks are the built-in ones (532 in 23 groups), your custom checks and any policy checks. A check is a regex anchored at the command name (so mygit push -f does not match git push -f, but sudo git push -f does) plus optional filters that drop false positives, such as a path that does not exist or a --dry-run flag.

4. The context is detected

shellfirm looks at where the command runs: an SSH session, root, the git branch (and whether the command moves a protected branch), the Kubernetes context and namespace, production environment variables, sensitive paths, and uncommitted work in a folder being deleted. A risky context raises the challenge. See Context-aware protection.

5. Policies and your settings are applied

  • The project policy (.shellfirm.yaml, merged up to the outermost repository root) and the org policy add checks, deny lists and stricter challenges. A command aimed at another repository gets that repository's policy too.
  • Your settings decide the rest: ignores_patterns_ids (never prompt), deny_patterns_ids (always block), min_severity (skip lower ones), and escalation overrides.
  • A policy always wins over a personal setting that would weaken it. A deny always wins over an ignore.

6. The blast radius is measured

For checks that support it, shellfirm counts what the command would affect: files and size, modified files, commits, Docker objects, Kubernetes resources. It all fits in one time budget per command (blast_radius_budget_ms, 400 ms by default). See Blast radius.

7. A decision is made

Who askedPossible decisions
Shell hook (you, in a terminal)Run without a challenge, show a challenge (Math, Enter or Yes), or block (deny list or policy)
Agent hook or MCPallow, ask (the agent's own prompt asks a human), or deny

The challenge is the strictest of every layer that applies. See Challenges. Agent decisions are explained in Agent decisions.

8. The decision is logged

Every command that matched a check gets one audit record after the outcome: allowed, denied, cancelled, skipped (below min_severity), asked (handed to an agent's prompt), or no-terminal. Commands that match nothing are not logged.

See the decision without running anything

shellfirm check runs steps 2 to 7 and prints the result. It shows both views: what the shell hook would do and what an agent hook would answer.

shellfirm check -c 'git push origin main --force'
Output
1 risky pattern(s) matched:

  [git:force_push] [HIGH] This force-pushes and can overwrite remote history.
    Blast radius: [PROJECT] — Force-pushes to origin/main
    > Safe alternative: git push --force-with-lease (Checks that your local ref is up-to-date before force pushing, preventing accidental overwrites of others' work.)

  Context: Critical (branch=main, target=main)

  Shell (you, in a terminal): would challenge (Yes, escalated from Math: protected branch `main`)
  AI agent (hooks, MCP): deny (blocked)
    why: Severity HIGH meets or exceeds agent auto-deny threshold HIGH

A matched check that does not apply is listed with the reason:

shellfirm check -c 'rm -rf ./does-not-exist'
Output
1 check matched, but none applies here:
  - fs-strict:recursive_deletion: skipped, does-not-exist does not exist

  Shell (you, in a terminal): runs without a challenge
  AI agent (hooks, MCP): allow

shellfirm pre-command -t -c '<cmd>' prints the shell hook's exact decision, including the effective challenge, without prompting:

Output
command: git push -f origin main
decision: challenge
matched:
  - git:force_push [HIGH] This force-pushes and can overwrite remote history.
denied: no
challenge: Yes (escalated from Math: protected branch `main`)
context: risk=Critical; branch=main, target=main
blast radius: [PROJECT] — Force-pushes to origin/main

See shellfirm check and shellfirm pre-command.

Limits

shellfirm checks the command line, not what a program does after it starts. It does not read the contents of scripts you run, and commands built at run time can only be checked as far as they are visible on the line. See Known limitations.