
Rules to guards
Finds the rules your coding agent keeps breaking and turns them into blocking hooks
Rules to guards is an open-source agent skill for developer tools. It is available on Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, Windsurf and Goose.
- Scripts
- Python
- Platforms
- Claude Code, Codex, Cursor
- GitHub stars
- 1.7K
- Last commit
- License
- MIT
- Listing updated
Similar skills
About Rules to guards
Rules written in AGENTS.md, CLAUDE.md or GEMINI.md are advice the agent can ignore, especially late in a long session. This skill extracts those rules, sorts them into ones that can be checked against a single tool call (shell commands, file paths, tool names) and ones that must stay as text, then counts how often recent Claude Code, Codex, Gemini CLI and OpenCode sessions broke each checkable rule.
For each broken rule the agent drafts a pattern with you, builds a small Python hook from it, and replays the recorded breaks and a sample of other recent calls through that hook. The replay shows how many breaks would be blocked and whether any ordinary calls would be wrongly stopped. Nothing is installed until the generate step is run with write enabled after the user agrees; the diff of each settings file is shown first, with secrets masked.
The scripts are Python 3 using only the standard library, run locally, and make no network calls. Rules are written in a rules.json file the user reviews, and the hook can be removed again with an uninstall command that leaves the hook file for the user to delete.
When your agent uses it
Rule enforcer that finds which written rules in AGENTS.md, CLAUDE.md, and GEMINI.md a coding agent keeps breaking, counts every violation in recent Claude Code, Codex, Gemini CLI, and OpenCode sessions, and turns each broken rule into a hook that blocks it, tested by replaying the past violations. Use when the user says the agent keeps breaking or disobeying a rule (such as "use pnpm, never npm"); asks how often agents violate their rules; wants a rule enforced by a hook instead of repeated in text; or wants to convert rules into hooks or permission rules. Runs locally: reads AGENTS.md-style rules and session transcripts, and changes settings only with --write after the user agrees.
From the skill's SKILL.md. Your agent reads this description to decide when to load the skill.
What it can access
- Runs Python scripts(see the files on GitHub)
- Network calls found in its scripts(see the files on GitHub)
- License: MIT(see the files on GitHub)
From a static check of its 9 files (225 KB) on GitHub on 3 December 2026. Nothing was run. Read the files before you install a skill: it can tell your agent to run anything its tools allow.
Check another skill before you install it.
Install
This skill ships in the harness-skills plugin. In Claude Code, add the marketplace and install the plugin (it may include other skills too):
/plugin marketplace add RyanAlberts/best-of-Agent-Harnesses
/plugin install harness-skills@agent-harnessesOr copy only this skill to ~/.claude/skills/rules-to-guards:
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/RyanAlberts/best-of-Agent-Harnesses.git "$tmp" &&
mkdir -p ~/.claude/skills &&
rm -rf ~/.claude/skills/rules-to-guards &&
cp -R "$tmp/skills/rules-to-guards" ~/.claude/skills/rules-to-guards &&
rm -rf "$tmp"For one project only, put the folder in .claude/skills/rules-to-guards inside it instead.
Copy the skill folder to ~/.agents/skills/rules-to-guards to use it in every repository:
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/RyanAlberts/best-of-Agent-Harnesses.git "$tmp" &&
mkdir -p ~/.agents/skills &&
rm -rf ~/.agents/skills/rules-to-guards &&
cp -R "$tmp/skills/rules-to-guards" ~/.agents/skills/rules-to-guards &&
rm -rf "$tmp"For one repository only, put the folder in .agents/skills/rules-to-guards inside it instead.
Copy the skill folder to ~/.cursor/skills/rules-to-guards to use it in every project:
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/RyanAlberts/best-of-Agent-Harnesses.git "$tmp" &&
mkdir -p ~/.cursor/skills &&
rm -rf ~/.cursor/skills/rules-to-guards &&
cp -R "$tmp/skills/rules-to-guards" ~/.cursor/skills/rules-to-guards &&
rm -rf "$tmp"For one project only, put the folder in .cursor/skills/rules-to-guards inside it instead.
Run in a terminal (add --scope workspace to install it for the current workspace only):
gemini skills install https://github.com/RyanAlberts/best-of-Agent-Harnesses.git --path skills/rules-to-guardsOr copy the folder to ~/.gemini/skills/rules-to-guards yourself.
For GitHub Copilot in VS Code, copy the skill folder to ~/.copilot/skills/rules-to-guards:
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/RyanAlberts/best-of-Agent-Harnesses.git "$tmp" &&
mkdir -p ~/.copilot/skills &&
rm -rf ~/.copilot/skills/rules-to-guards &&
cp -R "$tmp/skills/rules-to-guards" ~/.copilot/skills/rules-to-guards &&
rm -rf "$tmp"For one project only, put the folder in .github/skills/rules-to-guards inside it instead.
Get the folder:
git clone --depth 1 https://github.com/RyanAlberts/best-of-Agent-Harnesses.gitThen copy best-of-Agent-Harnesses/skills/rules-to-guards into your agent's skills folder as rules-to-guards. Agents that support SKILL.md read one folder per skill.
What it does
- Rule extraction
- Lists candidate rules from agent context files and sorts them by whether a hook can enforce them.
- Break counting
- Counts tool calls in recent agent sessions that violated each checkable rule.
- Replay testing
- Runs the generated hook against past breaks and recent normal calls before installing it.
- Hook generation
- Writes a blocking pre-tool hook and merges its entry into harness settings with a preview diff.
- Safe uninstall
- Removes only its own settings entries so existing hooks and formatting stay intact.
Good for
- Stop my agent from running npm in a repo that requires pnpm
- Count how often my agent broke the rules in AGENTS.md this month
- Block edits to generated files in dist using a hook
- Turn a no-force-push rule into a permission check that blocks git push --force
- Check which written rules still lack an enforcement hook
Rules to guards FAQ
What does the skill need to run?
Python 3.9 or newer on macOS or Linux, including WSL2. It uses only the standard library and makes no network calls.
Does Rules to guards change my settings on its own?
No. Generate only previews the hook file and a settings diff unless --write is given, and it writes only after the user agrees.
Which harnesses does Rules to guards support?
Counting covers Claude Code, Codex, Gemini CLI and OpenCode sessions. Hooks can be written for Claude Code, Codex, Gemini CLI and Cursor, with Cursor not verified on a real install.
Can Rules to guards enforce every rule in my context file?
No. Rules about order or style stay as text, since they cannot be checked from one tool call.
How do I install Rules to guards in Claude Code?
Copy the skill folder from GitHub to ~/.claude/skills/rules-to-guards to use it in all your projects, or to .claude/skills/rules-to-guards in one project. Or install the harness-skills plugin, which includes it: /plugin marketplace add RyanAlberts/best-of-Agent-Harnesses, then /plugin install harness-skills@agent-harnesses.
Does Rules to guards run scripts?
Yes. It runs Python scripts. Its scripts contain network calls. This comes from a static check of the files on GitHub; nothing was run. Read the files before you install it.
Which AI agents can use Rules to guards?
Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, Windsurf and Goose. Each reads skills in the SKILL.md format from its own folder; the install steps on this page list them.
What are the best alternatives to Rules to guards?
The closest alternatives to Rules to guards are Guardrail tester, Writing hooks, Runaway guard, Agents md checker and Safe execution edho ferdian.
Where this comes from
- Description: from the skill's own SKILL.md.
More from RyanAlberts/best-of-Agent-Harnesses

Shows which instruction files each coding agent loads and whether documented commands
- Open source
- 1.7K GitHub stars
- Developer tools

Audits an agent's claims that tests or builds passed against its session transcripts
- Open source
- 1.7K GitHub stars
- Developer tools

Checks if your agent's deny rules and hooks really block dangerous commands
- Open source
- 1.7K GitHub stars
- Security

Benchmarks Claude Code, Codex and Gemini CLI on tasks from your own git history
- Open source
- 1.7K GitHub stars
- Developer tools

Finds the Claude Code or Codex update where your agent's behavior started to change
- Open source
- 1.7K GitHub stars
- Developer tools

Halts a Claude Code or Codex session on loops, failure streaks or a spend cap
- Open source
- 1.7K GitHub stars
- Developer tools


