Your first guardrail
By the end of this you’ll have a working guardrail that refuses a real agent action, and you’ll have watched it fire — because a rule that loads but never refuses is worse than no rule at all.
Before you start
Section titled “Before you start”You need the plugin, installed in the project you are working in — see Install for Codex and Cursor. In short, from the project’s root, in Claude Code:
claude plugin marketplace add sloprail/sloprail --scope projectclaude plugin install sloprail@sloprail-marketplace --scope projectThat registers the hooks, and the next session installs the sr* binaries
they call. From now on, every tool call and every turn-end
runs through sloprail.
1. Write the rule
Section titled “1. Write the rule”A guardrail is a folder. The folder name is the rule name. Create one:
mkdir -p .sloprail/file-guard/no-todo-in-committed-codeAdd its declaration — a file-guard, because we’re judging one file’s
state:
match: path endsWith ".ts"checks: - script: ./check.shAnd the check — a script whose exit code is the verdict (0 permits, non-zero refuses):
#!/usr/bin/env bash# .sloprail/file-guard/no-todo-in-committed-code/check.sh (chmod +x)# stdin is the payload: .changeset.files[] holds each committed file's path and newContentif jq -e 'any(.changeset.files[]; (.newContent // "") | contains("TODO(no-ship)"))' >/dev/null; then echo '{"reason": "A file in the committed range has a TODO(no-ship) marker — resolve it before committing."}' exit 1fi2. Prove it fires
Section titled “2. Prove it fires”This is the part most people skip, and it’s the whole point. Ask your agent
to write and commit a .ts file containing TODO(no-ship), then judge the
commits:
sr-checks run --base origin/main --head HEADThe rule refuses, and the reason you wrote is shown back to the agent.
(A file-guard judges the committed result; the Stop hook and CI only verify the
stored verdicts with sr-checks verify, without asking a model. The Stop hook shows
failures only; run sr-checks run before a PR is ready, because CI’s required sr-checks verify
refuses a range nobody has judged; the push gate ships off.) Run sr-checks run
in the foreground and wait: it prints progress (a heartbeat every 30s) and is safe to run
in parallel, in several worktrees at once. Judges share a machine-wide limit
(SLOPRAIL_JUDGE_SLOTS, default 8), an identical check is judged once, and a second run
of the same range waits and reuses the first’s verdicts.
A file-guard’s verdict only binds where it is enforced. Add a CI job that runs
sr-checks verify on every pull request (--base the target branch, --head
the PR head sha), and put the marker sr:ci verify in a comment beside that step (sr-mark apply ci --verify=<path>:<line> writes it; any provider:
GitHub Actions, GitLab CI, Azure Pipelines, Jenkins, …). Until a committed file
carries that marker, the shipped sloprail/gate/ci-verify-required refuses the
end of the agent’s turn (and sloprail/file-guard/ci-verify-step refuses a marked file that does not run sr-checks verify on pull requests) and prints a snippet per provider (it installs sloprail with the release’s install.sh, pinned to the installed plugin’s version); switch it off with
disabled: [sloprail/gate/ci-verify-required] in .sloprail/config.yaml.
Protect the default branch (require pull requests and up-to-date branches): verify on pull requests is the guarantee.
Now ask it to commit a .ts file without that marker. The run passes.
If both happened, your guardrail is real. If the bad file passed, your rule loaded but didn’t fire — which is the failure this whole product exists to prevent.
What you just learned
Section titled “What you just learned”- A guardrail is a folder under
.sloprail/, named for the rule. - It has a nature (here,
file-guard) that decides when it runs. - Its check is a script (exit code = verdict) or a judge.
- Loading is not firing — always confirm the refusal actually happens.
- The three rule kinds → — file-guard, gate, context, and when to use each.
- Guides → — real failures and the guardrails that catch them.