A fair question. zsh's preexec
or bash-preexec can call a
handler before each command too, and for most people that is simpler and sees more: it
runs inside your real shell, after alias and variable expansion. If that fits you, use it -
secure-terminal does not need to own this, and most of what the hook does, a shell
preexec does as well.
The terminal hook earns its place in exactly two cases a shell hook cannot cover:
A guard the command can't switch off
A shell preexec is shell state: a command can unset -f it,
redefine it, exec a different shell, or run in a subshell that never loaded it.
The terminal hook runs outside the shell, so the command it is about to judge cannot
disable the judge first.
Programs with no hook of their own
In CLI mode the terminal does the line editing, so it can gate input to any line-oriented
program - dash, a Python or psql REPL - none of which have a
preexec to hang a guard on.
Both come with costs, stated plainly: the hook is
fail-open by default (a convenience speed bump, not a hard boundary - set
command_hook_on_error=block to fail closed), it runs in CLI mode only, and it
sees the line you typed, not what the shell expands it to. If none of those two edges matter to
you, a shell preexec is the lighter choice - and either way, the terminal's real,
by-design guarantees are safe display and safe paste, not this.