Performance
What the shell hook costs per command and at shell startup, measured, and how to measure it on your machine.
The shell hook starts one short-lived shellfirm process for each line you press Enter on. For a safe line that is all: no context lookups (git, kubectl), no blast-radius measurement, no prompt. Only a line that matches a check does more work, and that work has a time budget.
Measured numbers
| What | Time |
|---|---|
A safe line (ls -la, git status, kubectl get pods) through the hook (shellfirm pre-command) | 2.3 to 2.6 ms |
The same with shellfirm check -c "ls -la" | 2.7 ms |
Starting any process (/bin/true), for comparison | 0.3 ms |
A risky line up to the prompt (git reset --hard in a repository, with git context and blast radius) | about 5.4 ms |
| bash startup, without → with the hook | 0.7 → 8.9 ms (+8 ms) |
| zsh startup, without → with the hook | 1.0 → 10.9 ms (+10 ms) |
| fish startup, without → with the hook | 3.0 → 6.7 ms (+4 ms) |
How these were measured: shellfirm 0.4.0 release build, in a Debian 12 arm64 container (6 CPUs) under Docker Desktop on an Apple Silicon Mac. Each number is the average of a shell loop of 50 runs (20 for startup and the risky line). Startup is bash -i -c exit (and the zsh and fish equivalents) with an rc file that holds only the hook line, against the same shell with no rc file. Your numbers depend on your machine, but the shape is the same: a few milliseconds per Enter, and about 10 ms once per new shell.
Installed with npm: add about 17 ms
With npm install -g @shellfirm/cli, the shellfirm command on your PATH is a small Node.js script that starts the native binary. Every call then also starts Node.js. We ran the unmodified launcher from the @shellfirm/cli package under Node.js 22 in the setup above, with a do-nothing program in place of the binary: it took 16.8 ms per call, against 0.3 ms for starting the same program directly. So a safe line costs about 19 ms instead of 2 to 3 ms.
To avoid it, install the native binary directly: Homebrew, cargo install shellfirm --locked or a release binary. See Installation.
Risky lines: the impact budget
Before it shows a challenge, shellfirm can measure what the command would affect (files under a folder, uncommitted changes, branches). That measurement has one time budget for the whole command, 400 ms by default:
shellfirm config impact-budget # show the current value
shellfirm config impact-budget 1000 # allow up to 1 s (at most 5000)
shellfirm config impact-budget 0 # turn the measurement offWhen the budget runs out, the banner says so (more than 120,000 files (stopped counting), skipped, no time left) and the challenge is shown anyway. Before a slow measurement you may briefly see shellfirm: checking impact… (Ctrl-C cancels). See Blast radius.
Context lookups that run a program (git, kubectl) have their own short timeouts. If one does not answer in time, shellfirm treats the context as elevated rather than waiting. See Context-aware protection.
Measure it yourself
Time 100 safe lines through the same entry point the hook uses:
time (for i in $(seq 100); do shellfirm pre-command --test -c "ls -la" >/dev/null; done)real 0m0.257s
user 0m0.121s
sys 0m0.136sThat is 2.6 ms per line. Shell startup, with and without the hook:
printf 'eval "$(shellfirm init bash)"\n' > /tmp/rc-hook
time (for i in $(seq 20); do bash --rcfile /tmp/rc-hook -i -c exit; done 2>/dev/null)
time (for i in $(seq 20); do bash --norc -i -c exit; done 2>/dev/null)Divide real by the number of runs. --test reports the decision without prompting, so it is safe to loop.
Embedded hooks
Nushell, Elvish and Xonsh get the hook embedded in the rc file (152, 333 and 380 lines). They are read at startup like any other rc code. For Nushell we measured nu --config <file> --env-config <empty file> -c exit, 50 runs, with an empty config file and with a config file that holds only the hook (shellfirm init nu > hook.nu): 14.1 → 16.3 ms (+2 ms) in the setup above. The bash, zsh, fish and Oils hooks are one line that runs shellfirm init <shell> at startup and evaluates its output; that is part of the startup times above.