Skip to content
$ shellfirm

shellfirm pre-command

The command the shell hooks call before each line runs. Shows the banner and challenge; `-t` reports the decision without prompting.

shellfirm pre-command checks one command line and, when it is risky, shows the banner and the challenge on your terminal. The shell hooks call it before every line you type. You rarely run it yourself, except with -t to see what the hook would do.

Output
Usage: shellfirm pre-command [OPTIONS] --command <command>

Options

OptionDescription
-c, --command <command>The command to check
-t, --testDry run: report the decision (matches, deny status, context, effective challenge) on stdout without prompting, and exit with the code a real run would use if nobody confirmed (0 = would run)
--no-contextDo not run any external command (git, kubectl, docker, du, find) to detect context or compute the blast radius. Context that can be read from files (git HEAD, kubeconfig) is still used. Same as SHELLFIRM_NO_CONTEXT=1
-h, --helpPrint help

See the effective challenge with -t

-t is the quickest way to check your challenge settings, for example after changing the accessibility settings.

Terminal
$ shellfirm pre-command -t -c 'git push -f origin main'
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
$ echo $?
65

The same command after shellfirm config deny git:force_push:

Output
command: git push -f origin main
decision: deny
matched:
  - git:force_push [HIGH] This force-pushes and can overwrite remote history.
denied: yes (`git:force_push` is on your deny list)
context: risk=Critical; branch=main, target=main
blast radius: [PROJECT] — Force-pushes to origin/main

That run exits 77. A safe command:

Terminal
$ shellfirm pre-command -t -c 'ls'
command: ls
decision: allow
matched: none

That run exits 0.

Without a terminal

pre-command needs a terminal to ask on. With no terminal (CI, a script, </dev/null) it prints the banner to stderr, blocks the command and exits 74 (fail closed):

Output
shellfirm: cannot prompt (no terminal); command blocked: fs:recursively_delete, fs-strict:recursive_deletion require the `Yes` challenge

For scripts and CI, use shellfirm check instead.

Exit codes

CodeMeaning
0Allowed: no risky check matched, or the challenge was passed
3Allowed after a passed challenge. Only when the caller sets SHELLFIRM_SIGNAL_PROMPTED=1 (or SHELLFIRM_DEFER_APPROVED=1)
65Challenge cancelled or failed. With --test: the command would need a challenge
74No terminal to prompt on; the command is blocked (fail closed)
77Denied by your deny list or a policy. With --test: the command would be denied

Shell hooks treat any other non-zero exit code as "do not run the command".

Do not export SHELLFIRM_SIGNAL_PROMPTED

The shell hooks set SHELLFIRM_SIGNAL_PROMPTED=1 for each call (bash, zsh, fish, elvish), so they can tell a passed challenge (exit 3) from a command that needed none (exit 0). They accept exit 3 in every shell. Do not export the variable in your shell profile or environment.