Open-source guardrail

git checkout used to discard working-tree changes

AgentTrail Guard blocks this by default: the call never runs, and your coding agent is told which guardrail stopped it.

Default action
Block
Severity
High severity
Library version
0.2.1Sep 29, 2026

What it catches, and what it misses

Written into the rule itself, next to what it matches, so you can judge it before you trust it.

Overwrites files in the working tree from the index or from another commit, discarding uncommitted edits. Matches the discard spellings only — git checkout -- <path>, a bare git checkout ., and the -f/--force forms. It deliberately does NOT match an ordinary branch switch (git checkout main, git checkout -b feature/x), which is the same command doing something else entirely. It also MISSES git checkout <commit> <path> written without the -- separator. Global flags between git and checkout are tolerated (git -C <dir> checkout -- ., --no-pager, -c k=v), and an absolute tool path such as /usr/bin/git still matches; a flag that itself runs a program is not read. A quoted MENTION is not a use: a search, a git commit -m message, an echo or a curl --data body that only names this command is left alone. That holds only while every shell metacharacter stays inside the quotes, so git commit -m "x" && … is still caught; and the carrier must be the first word, so sudo grep … is not exempt.

Tested on every build

The rule must match every command on the left and none on the right, or the library does not build. Catching the real thing is easy; staying quiet on the near-miss is the hard part.

Catches (6)

  • git checkout -- src/api.ts
  • git checkout -- .
  • git checkout .
  • git checkout -f
  • git -C /repo checkout -- src/api.ts
  • git --no-pager checkout -f

Stays quiet on (8)

  • git commit -m "docs: explain git checkout -- src/api.ts"
  • grep -rn "git checkout -- src/api.ts" docs/
  • echo "never run git checkout -- src/api.ts"
  • curl --data "we ran git checkout -- src/api.ts" https://api.example.com/comments
  • git checkout main
  • git checkout -b feature/new-thing
  • git checkout tags/v1.2.3
  • git checkout --track origin/release

What "block" means in each app

The guard runs as a hook in each app, and each app gives a hook different powers. Here is what this rule's default action does in each one.

Claude Code
The call never runs, and the agent is told which guardrail stopped it.
Cursor
The call never runs. Cursor shows no reason of its own, so the agent retells the guardrail's message in its own words.
Codex CLI
The command never runs, and Codex prints the guard's reason on screen.

Each app hands the guard a different set of calls: in a Cursor sandbox run mode, for one, some terminal commands run without reaching the guard at all. Read the notes for Cursor and for Codex CLI before you rely on a rule there.

Change what it does in one command

Turn it off, change its action, or silence it on one command shape. The narrow one is allow: the rule keeps catching everything else.

agenttrail-guard
$agenttrail-guard guardrails show wt.checkout-discard# everything about it
$agenttrail-guard guardrails set-action wt.checkout-discard ask# block, ask or warn
$agenttrail-guard guardrails allow wt.checkout-discard '<pattern>'# silence one shape
$agenttrail-guard guardrails disable wt.checkout-discard# turn it off

Put these guardrails in front of your agent.

AgentTrail Guard is free and open source. It checks every command and file change against the whole library before your agent runs it, on your machine, with no account.

bash
$npm i -g @agenttrail/guard
Read the source on GitHub