Team rules
One versioned source of truth for how your team wants agents to work: conventions, code-review checks and the lessons you keep repeating. Every agent is checked against it, it learns from corrections and PR reviews, and your team approves each rule in a pull request.
The problem#
Most teams keep this in AGENTS.md or CLAUDE.md. Agents read those files, but nothing makes them follow every rule, and the lessons each developer teaches their agent stay on that developer’s machine.
- Each rule is usually followed, but rarely all of them. In OctoBench (Claude Code among the scaffolds) 80–86% of individual rule checks pass, but only 10–28% of tasks follow every rule, and compliance falls as sessions get longer.
- The files are advisory by design. Anthropic’s memory docs: Claude “treats them as context, not enforced configuration.” For anything that must always hold, they point to hooks.
- Stale files win. Agents followed an outdated instruction file over the actual code in 90% of choices (arXiv 2610.30571).
- Learnings are siloed. Claude Code’s auto memory is machine-local. Review bots keep their learnings in their own dashboards. Nothing keeps them in the repo, approved like code and checked.
The rule format#
Team rules are Claude Code’s own .claude/rules/*.md files. Claude Code loads each one when an agent touches a file that matches its paths: globs, including inside subagents. lucid reads two extra keys that Claude Code ignores:
---paths: ["src/api/**/*.ts"]forbid: 'console\.log\(' # lines an agent ADDS must not match (a string or a list)review: true # checked against the diff before the agent finishes a turn---# Log through logger, never consoleEvery API handler logs through src/lib/logger.ts so request ids are kept.| Key | Who reads it | What happens |
|---|---|---|
paths | Claude Code | The rule loads when an agent reads or edits a matching file. No paths: it loads in every session. |
forbid | lucid | When an edit adds a line that matches, the agent gets [lucid] team rule api/logging.md (…): this edit adds `console.log(id)`… with the edit’s result, and fixes it or says why it’s an exception. Lines that were already there never count. |
review | lucid | Before the agent ends a turn that touched matching files, it’s asked once to read its diff against these rules, fix what breaks one, and end with ✓ or ✗ per rule. |
Use forbid for what a pattern can say exactly (“never moment(”), and review for judgment (“every handler validates its input”, “migrations are reversible”). Most rules need neither: Claude Code loads them at the right moment on its own.
How rules get learned#
Proposals go to .lucid/proposed/ in the same format. Claude Code doesn’t load that folder, so a proposal does nothing until someone moves it into .claude/rules/ in a pull request. The PR diff is the rule, and the team reviews it like code.
| Source | How it gets proposed |
|---|---|
| A correction in chat | You tell Claude “no, we never…” or “from now on…”. Claude runs lucid learn "…" --paths 'src/**' --source chat on its own: every session tells it to, and a correction-shaped message gets a one-line reminder (at most three per session). |
| PR review comments | /lucid:learn pr 123 or /lucid:learn recent 30 reads review threads from humans and review bots with gh, keeps conventions that led to a code change, and weights themes that recur across PRs. |
| A swarm’s log | /lucid:dream proposes up to three lasting lessons from a finished swarm. |
| Your existing files | /lucid:learn import splits a long CLAUDE.md or AGENTS.md into path-scoped rule files and shows you the diff. |
Each proposal has a kind that decides its folder: architecture (how parts fit, and why) goes to .claude/rules/architecture/, review (what review catches) to .claude/rules/review/, and convention to .claude/rules/conventions/. When a feature merges, its dream proposes its lessons this way on its own (see Feature dreams).
/lucid:learn promote then goes through the proposals with you. It merges duplicates and adds forbid only when a grep of today’s code shows the pattern has no false positives. It moves the approved ones into .claude/rules/, refreshes AGENTS.md and suggests a PR. lucid never commits or pushes on its own. Claude Code asks before writing into .claude/, so you approve each rule file as it’s written.
lucid learn "Never use moment.js; use date-fns, it's already a dependency" --paths 'src/**' -e src/date.ts:3 --source pr#412lucid rules # every rule, with this machine's stats; proposals waitinglucid rules export # write the AGENTS.md block for other toolslucid rules export --check # in CI: fail if AGENTS.md has drifted from .claude/rules/Is each rule followed?#
lucid rules lists every rule with what happened on this machine. match counts edits to files under its paths, forbid counts pattern hits, unresolved counts hits still in the code when the turn ended, and review counts review rounds. Rules whose paths never matched an edit are listed as candidates to prune, and a rule with a broken regex is listed as skipped instead of breaking a hook.
Team rules in .claude/rules/: 2 · LUCID_RULES=on · stats from this machine- api.md [review]: Handlers validate their input (src/api/**) · match 2, review 1 · last 2026-11-18- logging.md [forbid]: Log through logger, never console (src/**) · match 2, forbid 1, unresolved 1 · last 2026-11-18Cautious by default#
- Nothing blocks a write. Pattern hits arrive as feedback with the edit’s result. They are never a denied tool call.
- Only added lines count, so legacy code never nags an agent.
- Every reminder is capped: a pattern hit twice per rule and file per session, the review once per turn (once per subagent), and the learn reminder three times per session.
- Rules can’t run code. lucid reads regexes, never shell commands from repo files, so a pull request can’t smuggle a command into your agents’ hooks.
- Proposals do nothing until a PR merges them.
- Observe first.
LUCID_RULES=observerecords the stats but shows agents nothing. Run a week that way, readlucid rulesfor false positives, then switch toon.offturns team rules off.
Codex, Copilot, Cursor and review bots#
lucid rules export writes the rules into a marked block in AGENTS.md, grouped by path, with each forbid pattern spelled out. Codex, GitHub Copilot, Cursor and many review bots read AGENTS.md, so they get the same rules. They don’t get lucid’s checks, which run inside Claude Code. Edit .claude/rules/, never the generated block, and run lucid rules export --check in CI to catch drift.
Rolling it out to a team#
- Everyone installs the plugin (Installation). To prompt teammates automatically, commit
extraKnownMarketplacesandenabledPluginsin the project’s.claude/settings.json. To force it for an organization, use managed settings. - Run
/lucid:learn importon your CLAUDE.md or AGENTS.md, and/lucid:learn recent 30on your merged PRs. Merge the rule files in one PR. - Set
LUCID_RULES=observefor a week, then readlucid rules. - Switch to
on. Promote new proposals with/lucid:learn promoteas they come in.
Seen in live runs#
These were headless claude -p sessions on Haiku, with the plugin loaded and nothing about lucid in the prompt:
- Rules. The prompt asked for
console.login an API handler. The pattern rule fired with the edit result. The review round then checked the diff, and the code ended up with the validation an API review rule asks for, which the prompt never mentioned. The agent keptconsole.logas a stated exception (“you asked for it by name”), andlucid rulesshowed it as unresolved. - Learning, unprompted. A repo with no
.lucid/. A user stated a team policy in passing. Claude ranlucid learnon its own. After the proposal was merged, a teammate’s session, with none of the first session’s memory, followed the policy.
What the benchmark shows: no adherence gain yet#
In 115 runs on Haiku and Opus, Claude followed every rule in every arm: 30 rules in one long CLAUDE.md, the same rules as native .claude/rules/ files, and the same files under lucid. That held in a 7-turn session where the rules mattered again after 80 KB of docs had been read. A teammate session also picked up a chat-stated policy in every run without lucid, because Claude wrote it into a CLAUDE.md itself. lucid cost 5–32% more per run, mostly for the review round.
So lucid didn’t make Claude follow rules better on these tasks. What it adds is a mechanical check that runs anyway, a per-rule record of what was caught, a reviewed path from correction to rule (Claude ran lucid learn unprompted in 11 of 13 runs), and one set of rules for every tool. Hundreds of rules, compacted sessions and large repos, where research finds agents slip, are untested. Full results.