pi-steering-hooks is an open-source project that provides deterministic tool-call guardrails for the pi agent. Its core idea is: prompt-based rules (such as "never force push") work most of the time, while steering hooks work every time. Hooks intercept before a tool call is executed, deterministically block violations, and provide an override escape channel when the agent has a legitimate reason. This project is inspired by "Strands Agents: Steering Accuracy Beats Prompts".
Main capabilities
The project's main capabilities include:
- Evaluate rules on every bash, write, and edit call; if a rule matches, block the call and return the reason to the agent; the agent adjusts its approach after seeing the block message.
- Override mechanism: when a rule triggers, the agent can try retrying with an override annotation
# steering-override: <rule> — <reason>. Overrides are allowed through but are logged to the session for auditing. Rules marked asnoOverride: true(such asno-rm-rf-slash) cannot be overridden. - File-writing guardrails (new in version 0.3.0): guide the agent to use the write and edit tools (which show diffs and go through the LSP), rather than writing files invisibly via bash commands. File-writing rules have two structural escape channels to avoid blocking legitimate generation pipelines:
- Script mode: write
tools/refactor.pyorscripts/gen.sh, then run it. Writes by the child process are not checked. - Temporary directory: redirecting to
/tmp/、/dev/、dist/、build/、generated/、out/、reports/、coverage/、target/、.cache/is always allowed. - In addition, there is the standard per-command override mechanism (
# steering-override: <rule> — <reason>) for one-off situations.
- Script mode: write
Usage
- The extension registers a
tool_callhook. The hook evaluates whether a rule matches the tool input. - Configure rules or disable default rules via
steering.json. Configuration file locations are checked in order (first found wins):./steering.jsonat the project root, then the global~/.pi/agent/steering.json. - If you do not want to use the default rules, you can disable them via
steering.json. - Rules can use regular expressions (
pattern) or a test function (test) form; the two are mutually exclusive. If a rule has both or neither,compileRulethrows an error.buildRulesthrows at the first malformed rule;buildRuleSetskips it and returns{ rules, errors }, which is what the extension uses.readConfigreturns parse errors instead of logging them. Function-form rules can only be added in code and cannot be added fromsteering.jsonAdd (because it is JSON). - Programmatic API: the package exports its internal components so that other extensions can build on it.
Configuration and fault tolerance
- A broken configuration never prevents pi from starting. Files that are not valid JSON are skipped, and the next location (or the default rules) is used. Rules with invalid regular expressions, that have neither
patternnortestare skipped;rulesordisablenot being an array is ignored, so a string form ofdisabledoes not disable any rules. All other rules still apply. Each problem is displayed as a notification at session startup. In non-interactive TUI (print, json, and RPC modes), it is also printed to stderr. - If a rule throws an exception during evaluation, it is treated as a non-match and reported in the same way, once per rule per session.
heredoc handling
The project specifically points out the importance of heredoc-stripping: a simple if x > 80: scan of a python3 - <<'EOF' ... EOF containing > would incorrectly treat a Python comparison as a shell redirection to a file named 80: . The exported stripHeredocBodies helper function removes the heredoc body before the metacharacter scan (keeping the opening line, which often contains a real shell redirection). The same logic applies to stripQuotedStrings, used to handle grep '>' file -style false positives. This regression case is already covered in index.test.ts to prevent it from happening again.
Applicable scenarios and limitations
This project is suitable for development scenarios where you want to strictly constrain the tool-call behavior of the pi agent, especially when you need to prevent dangerous commands (such as force push, rm -rf /) or guide the way files are written. It achieves deterministic enforcement through hooks, consumes no tokens, and avoids prompt drift. In terms of limitations: rules can only intercept bash, write, and edit calls; function rules are limited to code additions; the configuration file must be in the specified location; and it is not applicable to projects that are not pi agents.