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.
Usage: shellfirm pre-command [OPTIONS] --command <command>Options
| Option | Description |
|---|---|
-c, --command <command> | The command to check |
-t, --test | Dry 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-context | Do 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, --help | Print help |
See the effective challenge with -t
-t is the quickest way to check your challenge settings, for example after
changing the accessibility settings.
$ 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 $?
65The same command after shellfirm config deny git:force_push:
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/mainThat run exits 77. A safe command:
$ shellfirm pre-command -t -c 'ls'
command: ls
decision: allow
matched: noneThat 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):
shellfirm: cannot prompt (no terminal); command blocked: fs:recursively_delete, fs-strict:recursive_deletion require the `Yes` challengeFor scripts and CI, use shellfirm check
instead.
Exit codes
| Code | Meaning |
|---|---|
| 0 | Allowed: no risky check matched, or the challenge was passed |
| 3 | Allowed after a passed challenge. Only when the caller sets SHELLFIRM_SIGNAL_PROMPTED=1 (or SHELLFIRM_DEFER_APPROVED=1) |
| 65 | Challenge cancelled or failed. With --test: the command would need a challenge |
| 74 | No terminal to prompt on; the command is blocked (fail closed) |
| 77 | Denied 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.
Related
- Challenge types: the banner, the challenge and the approved line
- Shell setup
- Exit codes