Extract and index AI coding instructions from rules files (CLAUDE.md, AGENTS.md, .cursorrules, etc.).
You've written the rules. There's a CLAUDE.md at the root, an AGENTS.md for Codex, a .cursorrules file, and whatever else lives under .cursor/rules/ or .github/instructions/. But when you open an agent session and say "review this PR," it doesn't see all of them.
repo-rules-agent builds one queryable index from every rules file in your repo. A query scoped to the work in front of you — e.g. --task code-review --lang py --severity must — returns the ~15 rules that actually apply, not 8,000 tokens of rules files.
Four stages: discover → extract → index → query.
- Discover sweeps ~40 known rules-file conventions across four priority tiers — root files, tool-specific paths, rules directories with globs, and a recursive
**tier. It resolves@include-style directives, so aCLAUDE.mdthat's just a pointer toAGENTS.mdcounts as one source, not two. - Extract sends each file to an LLM via the OpenAI tool-calling protocol. The model fills a pydantic-validated schema — see Rule Model. Large files are chunked on Markdown headings via chonkie.
- Index merges near-duplicates by text similarity and flags potential conflicts — similar rules with contradictory severities — for human resolution.
- Query returns rules scoped to the current task. Filter by task, language, severity, scope; output as a table, JSON, or a prompt-ready block.
uv— Python package managergit— used for blob SHA computation during indexing- Ollama — required if you use the default local provider; not needed if you configure OpenAI, Anthropic, or another hosted provider
# Install dependencies
uv syncThe tool works with any OpenAI-compatible API provider. By default, it connects to a local Ollama instance; OpenAI and Anthropic are also supported.
Copy .env.example to .env and uncomment the provider you want to use:
cp .env.example .env
# Edit .env with your API keysThe .env file is gitignored and loaded automatically at startup via python-dotenv. Shell environment variables take precedence over .env values, so you can always override a .env setting with an explicit export.
Local (Ollama — default, no API key needed):
ollama pull glm-4.7-flash:latest
uv run repo-rules-agent index /path/to/repoLocal models vary in tool-calling reliability; for the highest-quality extraction, use OpenAI or Anthropic.
Anthropic (add to .env):
RULES_AGENT_LLM__BASE_URL=https://api.anthropic.com/v1
RULES_AGENT_LLM__API_KEY_ENV=ANTHROPIC_API_KEY
RULES_AGENT_LLM__EXTRACTION_MODEL=claude-haiku-4-5
ANTHROPIC_API_KEY=sk-ant-...
OpenAI (add to .env):
RULES_AGENT_LLM__BASE_URL=https://api.openai.com/v1
RULES_AGENT_LLM__API_KEY_ENV=OPENAI_API_KEY
RULES_AGENT_LLM__EXTRACTION_MODEL=gpt-4o-mini
OPENAI_API_KEY=sk-proj-...
All LLM settings can also be changed in src/rules_agent/config.toml.
Check which files would be processed without extracting:
uv run repo-rules-agent discover /path/to/repoExtract rules from all discovered files. The index is written to a per-user cache directory by default (invisible to the repo), and query reads from the same place.
# Index the current repo (writes to the cache; prints the resolved path)
uv run repo-rules-agent index /path/to/repo
# Override the output path
uv run repo-rules-agent index /path/to/repo -o rules-index.jsonFilter and format rules from the cached index. With no positional argument, query reads the cached index for the current directory.
# Table format (default)
uv run repo-rules-agent query --task code-review
# JSON format
uv run repo-rules-agent query --task code-review --format json
# Prompt format (for injection into LLM prompts)
uv run repo-rules-agent query --task code-review --format prompt
# Filter by language
uv run repo-rules-agent query --task code-review --lang py
# Filter by severity
uv run repo-rules-agent query --severity must
# Query an explicit index file instead of the cache
uv run repo-rules-agent query rules-index.json --task code-reviewPrint rule counts per file plus breakdowns by severity, task, and language. Use this for overview questions instead of piping query into a script.
# Summary for the cached index of the current directory
uv run repo-rules-agent stats
# Or pass an explicit index file
uv run repo-rules-agent stats rules-index.jsonuv run repo-rules-agent cache path # where the cwd's index lives
uv run repo-rules-agent cache list # all cached indices, newest first
uv run repo-rules-agent cache clear --all # wipe the cacheScore how well the LLM extracted rules using a judge model:
# Evaluate from an existing index (requires --repo to read source files)
uv run repo-rules-agent eval rules-index.json --repo /path/to/repo
# Or run the full pipeline (discover → extract → eval) from a directory
uv run repo-rules-agent eval /path/to/repo
# Save results to file
uv run repo-rules-agent eval rules-index.json --repo /path/to/repo -o eval-results.json
# Use a different judge model
uv run repo-rules-agent eval /path/to/repo --judge-model gpt-4o-miniThe judge scores each file on precision (no hallucinated rules), recall (no missed rules), and F1.
The bundled SKILL.md works with any agent that speaks the open skill format — Claude Code, OpenAI Codex CLI, and Cursor. Only the destination directory differs.
# Claude Code (default), repo-local
uv run repo-rules-agent install-skill
# Claude Code, user-wide
uv run repo-rules-agent install-skill --scope user
# Codex CLI (user-scope only — Codex doesn't support project-scope skills)
uv run repo-rules-agent install-skill --target codex --scope user
# Cursor, repo-local
uv run repo-rules-agent install-skill --target cursor
# All supported agents at once
uv run repo-rules-agent install-skill --target all --scope user| Target | Project scope | User scope |
|---|---|---|
claude (default) |
.claude/skills/repo-rules/SKILL.md |
~/.claude/skills/repo-rules/SKILL.md |
codex |
n/a | ~/.codex/skills/repo-rules/SKILL.md |
cursor |
.cursor/skills/repo-rules/SKILL.md |
~/.cursor/skills/repo-rules/SKILL.md |
all |
claude + cursor (codex skipped) | claude + codex + cursor |
Files are discovered in priority order:
| Tier | Files |
|---|---|
| 1 | Root files: AGENTS.md, CLAUDE.md, CONTRIBUTING.md, .cursorrules, etc. |
| 2 | Tool dirs: .claude/CLAUDE.md, .github/copilot-instructions.md |
| 3 | Rules dirs: .cursor/rules/.mdc, .github/instructions/.md |
| 4 | Recursive: **/CLAUDE.md, **/AGENTS.md, */.rules/ |
Each extracted rule includes:
title: Concise rule title with key technical contextdescription: 2-3 sentence description (what, when, why)category: open string. Preferred values surface in the tool schema as examples —crash_or_hang,logic_error,performance,security,error_handling,readability,code_style,maintainability,testability,best_practice— but any lowercase_snake_case identifier is accepted, so models can return values likearchitectureortype_safetywithout the rule being droppedtasks: code-review, code-generation, code-questionslanguages: ts, py, go, etc. or "all"scope: repo, directory, file-patternseverity: must, should, cansource_file: Origin file for tracing
# Format code
make format
# Run tests
make test
# Format + test
make checkPlease open issues and feature requests here: https://github.com/unblocked/repo-rules-agent/issues
Copyright © NextChapter Software