r/OpenSourceAIAllowed • • 18d ago

Made an open-source tool that stops coding agents from running the commands you can't undo. Would love feedback

So this started because my coding agent ran prisma db push --force-reset on a database to get past a migration error. Its reasoning was basically "it's only dev data." Which, fair, but still.

That's the thing with agents like Claude Code, Cursor and Codex. They run shell commands with your permissions, way faster than you can check them, and 99% of the time that's great. The other 1% is git reset --hard over a day of work, or rm -rf on the wrong path, or casually reading your .env.

So we built AgentTrail Guard. It's open source (Apache-2.0), runs locally, and checks each command before the agent runs it. If it matches one of the rules, it gets blocked, or it asks you first, or it just warns you. Everything else goes through like normal.

npm install -g @agenttrail/guard
agenttrail-guard init --agent claude    # or cursor, or codex

It's plain rule matching, not another AI, so you can actually read every rule and see why something fired. We put all 74 of them in a browsable list here if you want to see what it catches without installing anything: https://www.agenttrail.sh/guardrails

The bit I'd actually try first is agenttrail-guard scan --agent claude. It goes through your old sessions and shows what would have been caught. Kind of eye-opening.

It's not perfect. It only sees what goes through the agent's hooks, and if it crashes it lets things through rather than blocking your work. It'll definitely miss stuff, which is why I'm posting.

If you try it, I'd love to hear what it flagged that it shouldn't have, or what your agent has done that it didn't catch. PRs for new rules are very welcome.

Code's here: https://github.com/agenttrailhq/guard

2 Upvotes

2 comments sorted by

2

u/Benjino16 15d ago

Hi, really cool project I may test it if I find the time to. Besides I would have these 3 questions:

  1. What setup were you running when the prisma reset happened (agent, model, permission mode)? in my experience claude code catches this kind of thing pretty well when I am using auto mode, before stuff like database resets or force pushes happens, since a classifier model already detects critical tool calls and specifically asks the user...

  2. Where does this add the most over those built-in checks? Is it mainly a predictable, rule-based layer on top of a probabilistic classifier?

  3. I think the more fundamental fix (that I want to raise awareness) is isolation: run agents in a devcontainer with a dedicated DB, plus branch protection that blocks force pushes and requires CI (https://code.claude.com/docs/en/devcontainer). Same goes for secrets: a .env in a dev environment generally shouldn’t hold production, staging or critical infrastructure keys in the first place, just scoped dev credentials that are cheap to rotate. Would you see this as a complement to that? I could see it covering things that isolation doesn’t but it could also slow down or make fast dev more annoying since it not context based.

One example: I had a project where I locally often reset my db and fill it with seed data for dev purposes but the agent continued to flag it and I had to manually approve it most of the time (but for the same session it remembered my decision). Does "guard" have something like this? Can I allow a command for a session?

On thing I noticed so far:
- dropdb devdb get flagged
- rm database.db (sqlite) does not get flagged

but isn’t the purpose of the tool mostly to prevent harming tool calls in the local environment?

1

u/samc621 15d ago

Thanks, and these are fair questions.

Setup: Claude Code in auto mode, on Opus 5. It was a test repo we set up on purpose: Prisma over a local SQLite database, to experiment with these guardrails.

Where it adds the most: you've basically got it. It's a predictable, rule-based layer. It uses no model, so the same command gets the same answer every time, and each decision names the rule that fired. It also works on Cursor and Codex, and scan replays your past sessions to show what would have fired. The classifier is better at things no rule anticipated, because Guard only catches what a rule matches. I'd run both.

Isolation: do that as well. It's the strongest way to limit what an agent can reach: a devcontainer with a dedicated DB, branch protection and scoped dev credentials. I see Guard as a different layer. An agent still needs real access to be useful, so Guard checks what it does with that access inside the boundary, like wiping uncommitted work in a mounted repo or skipping commit hooks. You're right that it isn't context-aware, though. It never sees your connection string, so it can't tell a throwaway DB from one that matters.

Allowing a command for a session: no, there's no per-session allow today. The closest is a lasting exception for one rule and one command shape:

agenttrail-guard guardrails allow dd.database-drop "dropdb devdb"

That rule keeps firing on everything else, and guardrails set-action <id> ask turns a block into a prompt. For your reset-and-seed loop, prisma migrate reset is already ask-only rather than a block, because that's a normal thing to do many times a day on a scratch DB. A session-scoped allow is a good idea, though, and I'll think about it.

rm database.db: that's a real gap. There's no rule for deleting SQLite files, and plain rm isn't flagged, only rm -rf and a few specific paths. You're right that this is the kind of local damage it's meant to stop. You can add your own rule today, but it should ship by default, so I'll look at adding one.

Thanks again for the feedback!