# Rules to guards

> Rules to guards is an open-source agent skill for developer tools. Finds the rules your coding agent keeps breaking and turns them into blocking hooks. It is available on Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, Windsurf and Goose.

- **Kind:** Skill
- **Pricing:** Open source
- **Platforms:** Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, Windsurf, Goose
- **Website:** https://github.com/RyanAlberts/best-of-Agent-Harnesses/tree/main/skills/rules-to-guards
- **Repository:** https://github.com/ryanalberts/best-of-agent-harnesses
- **GitHub stars:** 1,663
- **License:** MIT
- **Skill name:** rules-to-guards
- **Collection:** https://github.com/RyanAlberts/best-of-Agent-Harnesses
- **Categories:** [developer tools](https://ai-powered.com/categories/developer-tools)
- **Listing updated:** 2026-12-03

## About

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.

## What it can access

From a static check of the files on GitHub; nothing was run.

- [Runs Python scripts](https://github.com/RyanAlberts/best-of-Agent-Harnesses/tree/HEAD/skills/rules-to-guards)
- [Network calls found in its scripts](https://github.com/RyanAlberts/best-of-Agent-Harnesses/tree/HEAD/skills/rules-to-guards)
- [License: MIT](https://github.com/RyanAlberts/best-of-Agent-Harnesses/tree/HEAD/skills/rules-to-guards)

## Features

- **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

## Install

### Claude Code

This skill ships in the `harness-skills` plugin. In Claude Code, add the marketplace and install the plugin (it may include other skills too):

```sh
/plugin marketplace add RyanAlberts/best-of-Agent-Harnesses
/plugin install harness-skills@agent-harnesses
```

Or copy only this skill to `~/.claude/skills/rules-to-guards`:

```sh
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.

### Codex

Copy the skill folder to `~/.agents/skills/rules-to-guards` to use it in every repository:

```sh
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.

### Cursor

Copy the skill folder to `~/.cursor/skills/rules-to-guards` to use it in every project:

```sh
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.

### Gemini CLI

Run in a terminal (add `--scope workspace` to install it for the current workspace only):

```sh
gemini skills install https://github.com/RyanAlberts/best-of-Agent-Harnesses.git --path skills/rules-to-guards
```

Or copy the folder to `~/.gemini/skills/rules-to-guards` yourself.

### VS Code

For GitHub Copilot in VS Code, copy the skill folder to `~/.copilot/skills/rules-to-guards`:

```sh
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.

### Other agents

Get the folder:

```sh
git clone --depth 1 https://github.com/RyanAlberts/best-of-Agent-Harnesses.git
```

Then 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.

## 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.

## Alternatives

- [Guardrail tester](https://ai-powered.com/skills/guardrail-tester): Guardrail tester is an open-source agent skill for security.
- [Writing hooks](https://ai-powered.com/skills/writing-hooks-xiaolai): Writing hooks is an open-source agent skill for developer tools.
- [Runaway guard](https://ai-powered.com/skills/runaway-guard): Runaway guard is an open-source agent skill for developer tools.
- [Agents md checker](https://ai-powered.com/skills/agents-md-checker): Agents md checker is an open-source agent skill for developer tools.
- [Safe execution edho ferdian](https://ai-powered.com/skills/safe-execution-edho-ferdian): Safe execution edho ferdian is an open-source agent skill for developer tools.
- [Writing rules](https://ai-powered.com/skills/writing-rules-xiaolai): Writing rules is an open-source agent skill for developer tools.
- [Rules](https://ai-powered.com/skills/rules-xiaolai): Rules is an open-source agent skill for developer tools.
- [Config health](https://ai-powered.com/skills/config-health): Config health is an open-source agent skill for developer tools.

---
Source: https://ai-powered.com/skills/rules-to-guards
