Shared rules and conventions for AI coding assistants.
Provides a structured set of rules covering language, naming, git workflow, security, testing, documentation, and more — applied consistently across all supported AI assistants.
| Key | Assistant | Config file | Import support |
|---|---|---|---|
claude |
Claude Code | agents/claude/CLAUDE.md |
native |
codex |
Codex | agents/codex/AGENTS.md |
flat file |
gemini |
Gemini | agents/gemini/GEMINI.md |
native |
ai-rules/
├── agents/
│ ├── claude/
│ │ └── CLAUDE.md # Claude Code entry point (imports the core only)
│ ├── codex/
│ │ ├── AGENTS.md # Codex entry point (flat file, generated via `ai-rules generate`)
│ │ └── AGENTS.src.md # Template of the Codex flat file (core and scoped rules)
│ └── gemini/
│ ├── GEMINI.md # Gemini entry point (flat file, generated from GEMINI.src.md)
│ └── GEMINI.src.md # Template of the Gemini flat file (core, rules and skill texts)
├── core/ # Always-loaded core rules (5 files, ≤ 200 lines / 10 KiB)
├── rules/ # Scoped rules (14 files, `paths:` frontmatter, loaded when a matching file is touched)
│ ├── naming.md
│ ├── tdd.md
│ ├── testing.md
│ ├── dependencies.md
│ ├── compatibility.md
│ ├── docs.md
│ ├── changelog.md
│ ├── versioning.md
│ ├── shell.md
│ ├── cli.md
│ ├── logging.md
│ ├── error-handling.md
│ ├── api.md
│ └── ci.md
├── skills/ # Skills (ai-rules-<topic>/SKILL.md), loaded on demand; see docs/skills.md
│ # (scripts such as releasing/scripts/extract-changelog.sh ship with their skill)
├── templates/ # On-demand references, not auto-loaded
│ └── ci-triggers.md # experimental CI triggers pattern
├── hooks/
│ └── pre-tool-guard.py # Claude Code PreToolUse hook on Bash (logic in src/ai_rules/guard.py)
├── docs/
│ ├── metrics/ # Context-cost measurements per version (baseline-0.6.1.md, 0.7.0.md, 0.8.0.md, 0.9.0.md)
│ ├── specs/ # Specifications (0001-pre-tool-guard.md)
│ ├── skills.md # How to write a skill (format, description style, derived skills)
│ └── sources.md # Register of the standards and upstream projects relied on, with review dates
├── scripts/
│ ├── measure-context.sh # Size of each rule-loading layer (bytes, lines, ~tokens)
│ └── check-sources-age.sh # Lists the sources of docs/sources.md that are due for a review
├── bin/
│ └── ai-rules # Development entry point
├── src/ai_rules/ # Python CLI package
├── tests/ # Test suite (pytest, 477 tests)
├── .github/workflows/
│ ├── ci.yml # CI pipeline (lint + test + coverage)
│ └── sources-review.yml # Monthly check of docs/sources.md; opens an issue when sources are due
├── agents.toml # Agent registry and link declarations
├── THIRD_PARTY.md # Notices for the upstream projects some skills are derived from
└── pyproject.toml # Python package definition
git clone git@github.com:eviweb/ai-rules.git
# Install with pipx (isolated, globally available)
pipx install ./ai-rules
# Or with uv (for development)
cd ai-rules
uv syncbin/ai-rules-wrapper is a bash entry point that works from any directory,
including when installed via symlink. It resolves the repository root
automatically (no AI_RULES_HOME required):
ln -s /path/to/ai-rules/bin/ai-rules-wrapper ~/.local/bin/ai-rulesIf you prefer to set AI_RULES_HOME explicitly (e.g. in your shell profile),
the wrapper will use it instead of auto-detection:
export AI_RULES_HOME=~/path/to/ai-rulesai-rules [OPTIONS] COMMAND [ARGS]
Options:
-V, --version Show version and exit.
-v, --verbose Enable verbose output.
-q, --quiet Suppress non-error output.
--debug Enable debug mode.
--no-color Disable colored output.
--no-log Disable file logging.
--log-dir PATH Override the default log directory.
--help Show this message and exit.
Commands:
list List available agents.
status Show installation status for one or all agents.
install Install rules for one or all agents.
update Update installation and regenerate flat files for one or all agents.
remove Remove rules for one or all agents, restoring original configuration.
generate Generate flat rule files for agents without native import support.
verify Verify flat rule files are in sync with current rules.
skills Inspect and verify the skills shipped by this repository.
# List configured agents
ai-rules list
# Check installation status (also reports whether the personal model tier
# mapping ~/.config/ai-rules/model-tiers.md exists and was checked within
# 90 days; a warning only, never a failure)
ai-rules status
ai-rules status claude
# Skills: list, check the format rules (exit 1 on any problem), deployment state
ai-rules skills list
ai-rules skills verify
ai-rules skills status
# Install all agents
ai-rules install
# Install a specific agent
ai-rules install claude
# Dry run
ai-rules install --dry-run
# Update after pulling new rules (redeploys symlinks + regenerates flat files)
ai-rules update
# Remove all agents, restoring original configuration
ai-rules remove
ai-rules remove codex
# Regenerate flat files for agents without native import support
ai-rules generate
ai-rules generate codex
# Verify flat files are in sync (useful in CI)
ai-rules verify
# Shell completion (bash/zsh/fish)
ai-rules --install-completionCompletion covers commands and options, and the agent argument of install, remove, update, status, generate, verify and skills status (keys read from agents.toml, with the agent's display name as help in zsh and fish). Paths such as --log-dir are completed by the shell. Completion stays silent when agents.toml cannot be found. --install-completion also edits your shell startup file (with a dotfiles-managed .bashrc that means an uncommitted change in your dotfiles); to avoid that, write the script yourself, for bash ai-rules --show-completion bash > ~/.local/share/bash-completion/completions/ai-rules (loaded on demand by the bash-completion package).
For each declared link in agents.toml, ai-rules install:
- Creates a symlink in the agent's
install_dir - Backs up any existing non-symlink file before replacing it
- Applies config patches (updates specific keys in existing config files)
- Merges settings files key by key (see below)
- Skips links that are already correctly in place
- Links skill folders one by one (see below)
| Symlink | Source |
|---|---|
~/.claude/CLAUDE.md |
agents/claude/CLAUDE.md |
~/.claude/rules |
rules/ |
~/.codex/AGENTS.md |
agents/codex/AGENTS.md |
~/.gemini/GEMINI.md |
agents/gemini/GEMINI.md |
Config patches applied:
| File | Key | Value |
|---|---|---|
~/.codex/config.toml |
project_doc_max_bytes |
131072 |
Settings merge ([[agents.*.settings_merge]] in agents.toml):
| File | Fragment | Keys owned by ai-rules |
|---|---|---|
~/.claude/settings.json |
settings.json |
permissions.allow, permissions.ask, permissions.deny, hooks |
~/.claude/settings.json is a regular file, not a symlink: Claude Code writes its own keys into it (plugins, /permissions, theme), which would otherwise land in this repository. ai-rules adds its list entries and scalars (allow, ask and deny rules; git commit, git push, rm, npx and chmod ask first, destructive variants such as rm -r, git push --force, git reset --hard and git clean are denied, --force-with-lease still asks), never touches other keys, and records what it added in $XDG_STATE_HOME/ai-rules/state/claude-settings.json. ai-rules update retires entries that left the fragment. A legacy symlinked install is migrated automatically: the content is backed up to $XDG_STATE_HOME/ai-rules/backups/claude/ and replaced by a regular file with the same content.
Skill directories ([[agents.*.skill_dirs]] in agents.toml): each sub-folder of source that holds a SKILL.md is linked to <install_dir>/<target>/<folder name>, one symlink per skill, so skills you write yourself live in the same directory and are never touched. ai-rules update unlinks the skills that were deleted from the repository (only symlinks pointing into the source directory are considered ai-rules', never other entries); a real folder with the same name is backed up first. status lists one line per skill (ok, not installed, symlink mismatch, exists (not a symlink), stale). Claude Code links them under ~/.claude/skills/ and Codex under ~/.agents/skills/ (the user skills directory Codex scans); a target starting with ~ or an absolute path is not relative to install_dir. Gemini has no skills yet (phase 6).
The permission rules above match every subcommand of a compound command, but not the same program invoked in another form. ai-rules install also links hooks/pre-tool-guard.py to ~/.claude/hooks/ai-rules-pre-tool-guard.py and registers it as a PreToolUse hook on Bash (only the hooks.PreToolUse list is merged; your own hooks are left alone). Before each shell command of the agent it:
- denies a recursive
rmhidden inbash -c,sh -c,evalor a path such as/bin/rm;sudoanddoasat any level (thesudorule does not see insidebash -c); force-push behind global options (git -C x push --force) or as a+refspec;git reset --hard,git clean,git checkout --and forced branch deletion in the same forms; - asks for
find -delete,find -exec rm,shred,git push --force-with-lease, and inline Python, Perl, Ruby or Node code that uses a deletion or process primitive (rmtree,unlink,remove,rmdir,os.system,subprocess,rm -); - lets the agent run
git commitonly asgit commit -s -F .private/COMMIT_MESSAGEwith a non-empty reviewed message and nogit -csetting that would skip your commit hooks, signature or identity (core.hooksPath,commit.gpgSign,user.*); you still confirm it.
It never allows anything, so it can only make the rules stricter. It needs python3 (standard library only, about 20 ms per command); if python3 is missing or the hook fails, Claude Code shows a hook error and the permission rules still apply. ai-rules status claude shows its link, registration and python3. To turn it off, remove its entry from hooks.PreToolUse in ~/.claude/settings.json (an ai-rules update adds it back). Specification: docs/specs/0001-pre-tool-guard.md.
ai-rules remove is the inverse of install:
- Removes symlinks owned by ai-rules
- Restores the most recent backup if one exists
- Reverts config patches (restores
.bakbackup, or removes the patched key) - Reverts settings merges: removes only the entries ai-rules added and restores the scalars it replaced (the file is deleted if it ends up empty)
- Unlinks the skills deployed by ai-rules and restores a backed-up folder of the same name; other skills are left alone
~/.claude/CLAUDE.mdimports only the core (@../../core/<name>.md): five files, always in context. Claude Code resolves a relative import against the real path of the file that holds it, and~/.claude/CLAUDE.mdis a symlink into this repository, so the paths are written relative toagents/claude/(checked by a test).@core/…would look foragents/claude/core/and silently load nothing.~/.claude/rules/holds the topic rules. Each has apaths:frontmatter, so Claude Code loads it only when it reads or writes a matching file (patterns are relative to the session's working directory). A rule is never imported: an@importalways loads its file. The tests enforce both.- Task-type material (project start, quality dimensions, review, pull requests and issues) lives in skills, loaded on demand; Codex and Gemini receive the same texts in their generated flat files (Gemini has no skills; Codex has native skills for them).
- Always-on cost:
CLAUDE.mdand the core are about 12 KB (about 4.2k tokens, measured) plus the listing of the sixteen skills (about 1.5k, capped at 5 KiB by a test). Estimate it withscripts/measure-context.shand confirm with/context. - Migration from 0.8.x: run
ai-rules updateto link the twelve new skills;rules/release.mddisappears with therules/link, and release notes are extracted withskills/ai-rules-releasing/scripts/extract-changelog.shinstead ofscripts/extract-changelog.sh. - Migration from 0.7.x: run
ai-rules update. The~/.claude/core(0.8.0-dev builds only),~/.gemini/coreand~/.gemini/ruleslinks are not used and can be deleted by hand.
Codex and Gemini load a single flat file. Each is generated from its template
(flat_source in agents.toml: agents/codex/AGENTS.src.md,
agents/gemini/GEMINI.src.md) with every @core/, @rules/ and @skills/
line resolved inline, frontmatter removed and each scoped rule introduced by a
one-line "Applies when working on" note. Codex gets the core and the scoped rules
(its native skills carry the rest); Gemini, which has no skills, also gets the
skill texts. Regenerate after updating any rule or skill:
ai-rules generate codex
# or simply:
ai-rules update codexVerify the flat file is in sync (e.g. in CI):
ai-rules verifyai-rules follows the XDG Base Directory Specification. All files it writes on the user's machine respect XDG defaults:
| Purpose | Path | Default |
|---|---|---|
| Backups (link files) | $XDG_STATE_HOME/ai-rules/backups/<agent>/backup-<ts>/ |
~/.local/state/ai-rules/backups/<agent>/backup-<ts>/ |
| Backups (config patches) | $XDG_STATE_HOME/ai-rules/backups/<agent>/ |
~/.local/state/ai-rules/backups/<agent>/ |
| Logs | $XDG_STATE_HOME/ai-rules/logs/ |
~/.local/state/ai-rules/logs/ |
Log filename format: ai-rules-YYYY-MM-DD.log. File logging is enabled by default; disable with --no-log or override the directory with --log-dir <path>.
If upgrading from a version that stored backups in the agent install dirs (~/.claude/backup-*/, ~/.codex/*.bak), run ai-rules update once to migrate them automatically.
ai-rules follows the strict profile defined in core/git.md: every change goes through a pull request, merged with a merge commit (gh pr merge --merge) so that commit signatures are preserved, with CI required on main. Releases are bumped only in the release commit (VERSION is the single source of the version).
# Install with dev dependencies
uv sync --extra dev
# After changing VERSION, refresh the installed metadata so `--version` matches
# (plain `uv sync` keeps the stale metadata of the editable install)
uv sync --extra dev --reinstall-package ai-rules
# Install git hooks (regenerates flat files automatically on commit)
ln -sf ../../scripts/pre-commit .git/hooks/pre-commit
# Run tests
tests/run-tests.sh
# or
uv run pytest -v| Platform | Status |
|---|---|
| Ubuntu 22.04 LTS | supported |
| Ubuntu 24.04 LTS | supported (primary) |
| Termux (Android) | supported |
Requires Bash 5+ and zsh for shell scripts. No sudo needed — all files are installed in user directories.