Team Collaboration: Shared Context and Rules
Two engineers on your team ask their AI assistant to add a new API endpoint. One gets a controller with try/catch and a custom error class; the other gets a bare async handler that throws raw errors. Folder layouts differ. Naming differs. The pull request review turns into a 40-comment style debate that has nothing to do with whether the feature works — because your conventions live in people’s heads, not in the repo.
The fix is not more review comments. It is moving the standards into version-controlled rule files that every team member’s AI loads automatically. When the conventions live next to the code, every engineer’s agent generates code that already looks like your codebase.
What You’ll Walk Away With
Section titled “What You’ll Walk Away With”- A committed rules file for each tool (
.cursor/rules/,CLAUDE.md,AGENTS.md) that enforces your conventions for the whole team - A copy-paste prompt that drafts that rules file by inspecting your existing code, so you are not writing it from a blank page
- A workflow for turning code-review decisions into permanent, machine-enforced rules
- An onboarding prompt a new hire pastes on day one to map the codebase themselves
- The failure modes (rule drift, conflicting files, bloated context) and how to avoid them
The Foundation: Version-Controlled Rules
Section titled “The Foundation: Version-Controlled Rules”The single most important practice for team alignment is to define your project’s standards in shared, version-controlled rule files that ship with the repo. All three tools read project-level instruction files; the only difference is the filename and a few mechanics.
Cursor reads rules from the .cursor/rules/ directory (one or more .mdc files). Commit this directory so every teammate’s Cursor picks up the same rules. Each rule file can be scoped with frontmatter: alwaysApply: true loads it into every request, or a globs pattern (e.g. src/api/**) loads it only when matching files are in context.
---description: API conventionsglobs: src/api/**alwaysApply: false---- All route handlers live in src/api/<resource>/route.ts- Wrap handlers in our asyncHandler() from src/lib/http.ts- Throw AppError (src/lib/errors.ts), never raw Error- Validate input with the matching Zod schema before any DB callClaude Code reads CLAUDE.md from the project root (and nested directories). Commit it to the repo. You can pull in other files with @path imports so a single CLAUDE.md stays small while referencing detailed standards.
# Project conventions
## API endpoints- Route handlers live in src/api/<resource>/route.ts- Wrap handlers in asyncHandler() from src/lib/http.ts- Throw AppError (src/lib/errors.ts), never raw Error- Validate input with the matching Zod schema before any DB call
See @docs/architecture.md for the full request lifecycle.Codex reads AGENTS.md files, starting at the repository root and walking down to the current directory. Commit AGENTS.md at the root for team-wide rules. For a sub-team with different conventions, drop an AGENTS.override.md in that directory — files closer to the working directory override broader guidance because Codex concatenates them root-first.
## API endpoints- Route handlers live in src/api/<resource>/route.ts- Wrap handlers in asyncHandler() from src/lib/http.ts- Throw AppError (src/lib/errors.ts), never raw Error- Validate input with the matching Zod schema before any DB callCodex stops adding files once the combined size hits project_doc_max_bytes (32 KiB by default), so split large guidance across nested directories rather than one giant root file.
Once these files are committed, a developer who clones the repo gets the conventions for free — their AI loads the rules and generates code consistent with your existing patterns from the first prompt. That is the entire point: reviews stop being about style, because the style is enforced before the code is written.
The Workflow: From Blank File to Enforced Standard
Section titled “The Workflow: From Blank File to Enforced Standard”You do not write a rules file from scratch. You let the AI draft it by reading the code you already have, then you edit and commit.
-
Generate a first draft from the codebase. Point the agent at representative directories and have it infer your actual conventions — the ones in the code, not the ones in the wiki nobody reads.
-
Review and pick the canonical pattern. The draft will surface inconsistencies (“two error-handling styles in src/api”). This is the valuable part — decide which one wins and make the rules file unambiguous.
-
Commit it to the right filename. Save as
.cursor/rules/conventions.mdc,CLAUDE.md, orAGENTS.mdper the tabs above (or all three, wrapping a shared doc). Commit and push so the whole team gets it on their next pull. -
Codify review decisions as they happen. The rules file is a living document. When a code review establishes a new standard, do not just leave it in a PR comment where it dies — add it to the rules file in the same PR.
Onboarding: Let New Hires Map the Codebase Themselves
Section titled “Onboarding: Let New Hires Map the Codebase Themselves”The fastest onboarding is not a senior dev answering the same questions every quarter. It is a new hire pasting a prompt and getting an accurate, rules-aware tour on demand. Because the agent reads the committed rules, the answers reflect your conventions, not generic advice.
The AI as a Collaboration Hub
Section titled “The AI as a Collaboration Hub”Shared rules align the code; integrations align the people. Codex’s multi-surface design is the strongest fit here: it connects to GitHub, Slack, and Linear, so the agent can act where your team already talks.
- Answer product questions in the open. A PM asks in a Slack channel how a feature behaves. Instead of a developer context-switching to read code, Codex (connected to the repo and Slack) can answer in-thread with a code-grounded explanation everyone sees — turning a DM into shared team knowledge.
- Tie work to tickets. With the GitHub and Linear integrations, Codex can open a PR from a task or summarize a change back onto the ticket, so the rationale lives where the work is tracked, not in someone’s terminal scrollback.
Cursor’s background agent and Claude Code’s headless mode (claude -p "..." in CI) cover the automation side: run the same rules-aware agent in a pipeline to flag convention violations on every PR. The principle is identical across all three — the agent is only as aligned as the committed rules it reads, so the rules file remains the source of truth.
When This Breaks
Section titled “When This Breaks”The rules file drifts from reality. Teams write a rules file once, the codebase evolves, and six months later the rules describe a pattern you abandoned. Re-run the “draft a rules file from existing code” prompt quarterly and diff it against the committed file — it surfaces exactly where reality moved on.
Conflicting instruction files. A root CLAUDE.md says one thing and a nested one says another; an AGENTS.override.md silently wins over the root AGENTS.md. When the AI ignores a rule, check whether a closer-scoped file is overriding it. Codex concatenates root-first (nearest wins); keep overrides deliberate and documented.
The rules file is too long, so it gets ignored or eats context. A 600-line rules file both burns context and buries the rules that matter. Codex hard-caps at 32 KiB by default. Keep the top-level file lean and push detail into referenced docs or scoped files (globs in Cursor, nested files in Codex, @imports in Claude Code).
Rules describe style but not “why.” “Use AppError” without a reason gets followed inconsistently. One-line rationales make rules stick and help the AI generalize to cases you did not enumerate.
Treating shared memory or a shared index as a rules substitute. Cursor maintains a per-project semantic index (and team plans can share it), but Claude Code and Codex navigate in real time with no pre-built shared index — so do not rely on “the AI already knows our patterns.” Committed rule files are the portable, tool-agnostic source of truth. See the indexing and memory guides below for what each tool actually persists.