{"slug": "how-to-give-claude-code-cursor-and-codex-the-architecture-context-they-need", "title": "How to Give Claude Code, Cursor, and Codex the Architecture Context They Need", "summary": "A practical guide recommends giving coding agents such as Claude Code, Cursor, and Codex explicit architecture context through a root AGENTS.md file, version-controlled architecture documentation, Agent Skills, MCP, and automated verification checks. The author, writing from experience on promo-code and referral functionality, reports that an agent without that context created duplicate modules, placed files in the wrong locations, and ignored established dependency conventions, with similar problems recurring in later sessions. The guide argues that repository access alone does not convey why a system was designed as it is, and that constraints need automated checks so a change can be verified against existing boundaries.", "body_md": "A practical guide to giving Claude Code, Cursor, and Codex reliable architecture context with AGENTS.md, project documentation, Agent Skills, MCP, and automated verification.\n\n*A reliable coding agent needs more than repository access. This guide shows how to combine project instructions, architecture documentation, reference implementations, Agent Skills, MCP, and automated checks so Claude Code, Cursor, and Codex can work with the architecture already in place.*\n\n**In this guide**\n\nI ran into this problem while working on promo-code and referral functionality with an AI coding agent.\n\nThe agent started creating duplicate modules, putting files in the wrong places, and ignoring dependency conventions that were already established in the project. I cleaned things up manually, but a later session brought similar problems back.\n\nThat was the frustrating part. The agent could write the code, but it didn't understand why certain things belonged where they did.\n\nI had those decisions in my head. The repository didn't explain all of them.\n\nCoding agents can search a codebase, follow imports, inspect implementations, and change dozens of files. Finding an implementation, however, does not reveal why the system was designed that way.\n\nAn agent may copy an exceptional implementation and treat it as a pattern, introduce a second service for an existing responsibility, or place business logic in a route handler because that is where it found a similar operation.\n\nThe damage is often cumulative. A change can compile and pass the tests while introducing another responsibility or blurring an existing boundary. As those decisions accumulate, the codebase becomes harder to maintain.\n\nThat experience changed what I thought useful project context needed to do. A longer prompt wasn't the answer. The repository needed to explain the decisions behind its structure—and give the agent a way to check whether a change still respected them.\n\n`AGENTS.md` is a useful starting point: it records durable project rules and points to deeper sources. Architectural decisions belong in version-controlled documentation, implementation details live in source code, changing project facts can be exposed through MCP, and important constraints need automated checks.\n\nClaude Code, Cursor, and Codex support many of the same mechanisms, with different discovery and configuration rules. I'll use the referral-reward flow from my project as the running example, bringing in promotions only where they are part of that flow.\n\nFor a runnable companion example of the instruction files, architecture docs, Agent Skill, and checks discussed here, see the [Architecture Context Starter](https://github.com/vladzdev/architecture-context-starter), which uses a small order-processing module separate from the Codapult referral workflow in this article.\n\nI'd begin with one `AGENTS.md` at the root of the repository.\n\nTreat it as an entry point for someone joining the project: summarize what the application does, how the code is organized, which conventions matter, and where to find deeper explanations.\n\nFor example, a repository might use a layout like this (the application directories are illustrative):\n\n```\nmy-app/\n├── AGENTS.md\n├── docs/\n│   └── architecture/\n│       ├── overview.md\n│       ├── boundaries.md\n│       ├── data-ownership.md\n│       ├── referrals-and-promotions.md\n│       └── decisions/\n├── src/\n│   ├── app/\n│   ├── features/\n│   ├── server/\n│   │   ├── services/\n│   │   └── adapters/\n│   └── shared/\n└── package.json\n```\n\nThe root instruction file could be as simple as:\n\n```\n# Project Instructions\n\n## Overview\n\nA SaaS application with referral and promotion functionality.\n\n## Architecture\n\n- `src/app` contains routes and request entry points.\n- `src/features` contains product-specific functionality.\n- `src/server/services` contains application services.\n- `src/server/adapters` contains external provider integrations.\n- `src/shared` contains code shared between features.\n\n## Important Boundaries\n\n- Keep business logic inside its owning feature.\n- Preserve documented dependency direction; do not introduce parallel implementations.\n- Read `docs/architecture/referrals-and-promotions.md` before changing referral rewards or promotion redemption.\n- Trace the existing lifecycle and tests before changing behavior.\n- Validate input at API and server action boundaries.\n\n## Architecture Documentation\n\n- Overview: `docs/architecture/overview.md`\n- Dependencies: `docs/architecture/boundaries.md`\n- Data ownership: `docs/architecture/data-ownership.md`\n- Referral and promotions: `docs/architecture/referrals-and-promotions.md`\n- Decisions: `docs/architecture/decisions/`\n\nRead the relevant document before changing an affected area.\n\n## Verification\n\nUse the scripts defined in package.json.\nRun relevant tests and type checks after changing application code.\nRun architecture checks when changing module dependencies.\n```\n\nUse the repository's existing structure. Keep detailed architectural explanations in version-controlled documentation. Give each area or decision a clear source of truth, and let the root file point to the relevant documents. Host-specific rules can surface the right guidance where the work happens.\n\nAvoid vague instructions such as:\n\n```\nFollow clean architecture.\nWrite maintainable code.\nUse appropriate abstractions.\n```\n\nThey sound sensible, but an agent has to guess what they mean in the context of your application.\n\nCompare this:\n\n```\nFollow clean architecture.\n```\n\nWith:\n\n```\nThe referral feature owns attribution, conversion, eligibility, and\nreward issuance. The usage subsystem owns referral-credit consumption.\nDiscount rewards use the existing promotion and redemption flow.\nRead the architecture notes before changing lifecycle behavior.\n```\n\nThe second version is more useful because it names the owners and the boundary instead of asking the agent to interpret a broad principle. The architecture document can then explain the rationale and show how referral, usage-credit, and promotion responsibilities fit together.\n\nThat distinction matters, but instructions are still guidance, not enforcement. An `AGENTS.md` rule cannot prevent an agent from crossing a dependency boundary. Use host permissions to restrict what an agent can do, and automated checks for code constraints that must hold on every change.\n\nKeep `AGENTS.md` focused so high-value instructions leave room for task-specific context. Codex also caps the combined project-instruction files through `project_doc_max_bytes`, which defaults to 32 KiB. This limit applies to instruction discovery, separately from the model's context window. You can raise it in `config.toml`; for larger repositories, nested files are often easier to maintain.\n\nAll three tools support `AGENTS.md`, but their discovery rules are worth understanding.\n\n**Codex** builds its instruction chain at session start, starting with global guidance and then checking each directory from the repository root to the current working directory. In each directory, `AGENTS.override.md` takes precedence over `AGENTS.md`; Codex includes at most one of the two. Nested files are discovered along that startup path, not by matching every file the agent later opens.\n\n**Cursor** supports `AGENTS.md` in the root and nested directories. It also has `.cursor/rules/` for instructions that need more specific file matching or other rule configuration.\n\n**Claude Code** has its own `CLAUDE.md` format and can also read `AGENTS.md` directly. At session start, it reads applicable `AGENTS.md` files in the working directory and its ancestors, including `.claude/AGENTS.md`. As it opens files in subdirectories with the Read tool, it can load those directories’ `AGENTS.md` files when they have no `CLAUDE.md`, `.claude/CLAUDE.md`, or `CLAUDE.local.md` of their own.\n\nBy default, Claude reads the Claude instruction files or the `AGENTS.md` files for a given scope, not both. A `CLAUDE.md`, `.claude/CLAUDE.md`, or `CLAUDE.local.md` in the working directory or an ancestor makes Claude use the Claude instruction files for that scope. Set Project instructions to `claude-md-and-agents-md` in `/config` to load both formats.\n\nFor a repository-portable setup, you can also import the shared instructions from `CLAUDE.md`:\n\n```\n@AGENTS.md\n\n## Claude Code\n\nFor changes involving multiple modules, inspect their\ndependencies before proposing an implementation.\n```\n\nDirect `AGENTS.md` support requires Claude Code v2.1.277 or later. Some sessions, including certain Amazon Bedrock or telemetry-disabled setups, require v2.1.281 or later. In an interactive session, Claude reports at startup whether `AGENTS.md` was loaded.\n\nOfficial documentation:\n\nA root file that tries to explain every corner of the system quickly becomes noise. I keep area-specific guidance close to the code it governs: referral lifecycle rules, promotion validation, migration requirements, and provider conventions should appear when that work is relevant, not in every unrelated task.\n\nFor the examples below, assume the referral feature lives under `src/features/referrals/`.\n\nClaude Code stores project rules in `.claude/rules/`. A rule can target files with `paths` frontmatter. For example, assume a project keeps its referral feature under `src/features/referrals/`:\n\n```\n---\npaths:\n  - 'src/features/referrals/**/*.ts'\n  - 'src/features/referrals/**/*.tsx'\n---\n\n# Referral Rules\n\n- Read `docs/architecture/referrals-and-promotions.md` before changing this area.\n- Follow its ownership boundaries and trace the affected lifecycle before editing.\n```\n\nClaude Code loads the rule when it reads or edits matching files. Rules without a `paths` field are loaded as general project instructions.\n\nOrganize `.claude/rules/` by domain when the application has several areas with different conventions.\n\nCursor uses `.cursor/rules/*.mdc` files. The same illustrative feature path can be expressed in its metadata:\n\n```\n---\ndescription: Referral attribution and reward lifecycle rules\nglobs: src/features/referrals/**/*.ts, src/features/referrals/**/*.tsx\nalwaysApply: false\n---\n```\n\nThe rule body can contain the same referral-specific guidance:\n\n```\n# Referral Rules\n\n- Read `docs/architecture/referrals-and-promotions.md` before changing the referral lifecycle.\n- Follow the documented module boundaries; do not add a parallel reward path.\n- Run the relevant lifecycle tests after the change.\n```\n\nThe `globs` field determines which files trigger the rule. With `alwaysApply: false`, this is a file-scoped rule rather than an instruction included in every session.\n\nCursor also supports rules that are always applied, selected manually, or loaded based on their descriptions. Save project rules in `.cursor/rules/` with the `.mdc` extension.\n\nCodex scopes instructions by directory ancestry rather than file globs. A feature-specific `AGENTS.md` can sit inside the relevant feature directory. In the example project, that might look like this:\n\n```\nsrc/\n└── features/\n    └── referrals/\n        └── AGENTS.md\n```\n\nThe nested file could contain:\n\n```\n# Referral Feature Instructions\n\n- Read `docs/architecture/referrals-and-promotions.md` before changing this area.\n- Follow the documented ownership boundaries and trace the affected lifecycle before editing.\n```\n\nCodex includes this file when the feature directory is on the session's startup path. For work launched from the repository root, explicitly direct Codex to read it when the task spans multiple areas.\n\nThis is the practical difference between the three approaches:\n\n| Tool | How scoped instructions are selected | \n|---|---|\n| Claude Code | Path patterns in `.claude/rules/` | \n| Cursor | File globs in `.cursor/rules/` | \n| Codex | Instruction files along the current working-directory path | \n\nThe policy can stay the same across tools, but it has to live where each host will actually discover it.\n\nA directory tree is a starting point, not an architecture description.\n\nThe referral work I mentioned earlier is a good example. The flow touches attribution records, reward records, usage-credit code, and sometimes a promotion used as the reward. An agent can find all of those files and still miss the important part: which subsystem owns each step, and where one responsibility ends and the next begins.\n\nIn this implementation, a confirmed payment triggers referral conversion. The referral feature decides eligibility and issues rewards; the usage subsystem consumes credit-type rewards separately from the main usage-credit balance; discount-type rewards go through promotion creation and redemption. The payment event starts the process, but it does not make Billing the owner of reward eligibility or issuance.\n\nThose distinctions need to be recorded somewhere more durable than a prompt. The schema maps the data; architecture documentation explains ownership and dependency rules. Tests and source code then show whether the documented lifecycle matches what the application actually does.\n\nA concise architecture note could describe the responsibilities without tying the explanation to particular source paths or function names:\n\n```\n# Referral Reward Architecture\n\n## Responsibilities\n\n- The referral feature owns attribution, conversion processing,\n  reward eligibility, and issuance.\n- The usage subsystem owns consumption of referral credits.\n- Referral credits remain separate from the main usage-credit balance.\n- Discount rewards use the promotion and redemption flow.\n- Payment confirmation triggers conversion processing; the referral feature remains responsible for reward eligibility and issuance.\n\n## Boundaries\n\n- Do not create a parallel referral reward-issuance path.\n- Do not use the main usage-credit balance to represent referral\n  credits.\n- Keep credit consumption in the established usage flow.\n- Keep promotion validation and redemption in the promotion flow.\n- Before changing lifecycle behavior, trace status transitions, retries, reversals, and duplicate-event handling, then preserve the behavior confirmed by the implementation and tests.\n\n## Before changing a reward\n\n1. Trace the confirmed-payment event into referral conversion.\n2. Find the existing eligibility, issuance, and reversal behavior.\n3. Trace how referral credits are consumed.\n4. If the reward is a discount, inspect promotion creation and redemption.\n5. Check transaction boundaries, retries, and lifecycle tests.\n```\n\nFor bigger or long-lived decisions, use an Architecture Decision Record (ADR). It should record an intentional policy, its rationale, and the consequences for future changes. For example:\n\n```\n# ADR: Keep Referral Credits Separate from Main Usage Credits\n\n## Context\n\nReferral rewards have their own eligibility and lifecycle. Credit-type\nrewards are consumed separately from the application's main usage-credit\nbalance.\n\n## Decision\n\nKeep referral-credit accounting separate and route consumption through\nthe usage subsystem.\n\n## Consequences\n\n- Referral reward issuance and usage-credit consumption have distinct owners.\n- Tests cover issuance and consumption as separate behaviors.\n- Changes to the main usage-credit balance do not redefine referral rewards.\n```\n\nKeep the historical decision separate from the current implementation. An ADR explains what was decided and why; the architecture documentation should describe how the system works today. If the implementation changes, update the current documentation too.\n\nA reference implementation often explains a convention better than another paragraph of instructions. For a referral-reward change, I would rather have the agent trace the existing conversion, eligibility, issuance, and credit-consumption paths—and any supported reversal path—than hand it a long list of guessed file names. If the reward is a discount, the trace should include promotion creation and redemption.\n\nThe useful output is a short map of the entry points, symbols, and tests the agent actually found. A developer can verify that map and add a few stable references to the project documentation. That gives the next session a reliable starting point without pretending that source paths never change.\n\nMCP becomes useful when project facts change independently of the documentation or take several steps to reconstruct from source files. In a real project, that might mean checking which modules are enabled, which authentication or payment adapter is active, what the declared database schema looks like, or which environment variables the application expects. Copying all of that into Markdown creates another source that can drift.\n\nA project can expose those facts through MCP in a structured form. The agent gets a focused view of the current state and, where appropriate, access to project-aware operations.\n\nCode search is useful for finding implementations. MCP is useful when a project deliberately exposes current facts in a stable, structured shape—for example, enabled features, table metadata, active provider choices, or project-check results. The two complement each other: MCP narrows the investigation, while source code explains how the project actually behaves.\n\nI use two questions to decide where a piece of context belongs: how often does it change, and what does the agent need to do with it?\n\n| Context | Best place | Example | \n|---|---|---|\n| Rules that should influence most tasks | `AGENTS.md` or host project instructions | Extend the existing referral flow; preserve lifecycle behavior; run relevant tests | \n| Architectural reasoning and ownership | Version-controlled architecture docs and ADRs | Referral owns reward eligibility and issuance; usage owns credit consumption | \n| Current implementation details | Source code and reference implementations | Existing conversion, issuance, redemption, and test patterns | \n| Current structured project state | MCP resources and read-only tools | Enabled features, active providers, table metadata, environment contract | \n| Repeatable multi-step procedures | Agent Skills | Change a reward lifecycle, implement a migration, review a release | \n| Independent investigation | Subagents | Trace conversion and reward handling separately | \n| Lifecycle feedback | Hooks | Run a targeted check when an agent reaches a completion event | \n| Independent enforcement | Tests, linters, architecture checks, and CI | Fail a build when a required boundary or test is violated | \n\nUse these sources as a sequence: project instructions point to the relevant context, MCP provides selected current facts, and source code plus tests show how those facts affect behavior. An MCP server is most useful when agents repeatedly need structured, changing information or access to project operations. For a small repository whose relevant state is already captured in reliable files and scripts, a separate MCP integration may add little value.\n\nMCP servers can expose three useful kinds of capability:\n\nA well-designed server follows that distinction: reusable context belongs in resources, user-invoked workflows can be prompts, and operations belong in tools with permissions that match their effects. Tool annotations such as `readOnlyHint` and `destructiveHint` can help a client classify an operation, but the specification treats them as hints, not guarantees. Clients should not rely on annotations from untrusted servers, and annotations never replace server-side authorization.\n\nIn my project, Codapult MCP is the concrete example of project-aware context. Distributed with `@codapult/cli`, it exposes several tools; two read-oriented ones are especially relevant to the referral workflow here:\n\n| Tool | Information it provides | \n|---|---|\n| `codapult_project_status` | Active adapters, enabled features, plugins, and Git status | \n| `codapult_db_get_table_info` | Column names, database types, and declared constraints for a selected table | \n\nThe server also exposes project resources and tools for other development tasks. The [Codapult MCP reference](https://codapult.dev/docs/developer-tools/mcp) describes the complete interface.\n\nIn the Codapult project used for this example, the captured `codapult_project_status` response returned Turso as the database adapter, Better Auth for authentication, Stripe for payments, and `referrals` and `promotions` among the enabled features. At the time of capture, it also reported the `main` branch and a dirty working tree. This is a selective excerpt from that response:\n\n```\n{\n  \"adapters\": {\n    \"database\": \"turso\",\n    \"auth\": \"better-auth\",\n    \"payments\": \"stripe\"\n  },\n  \"features\": {\n    \"enabled\": [\"referrals\", \"promotions\"]\n  },\n  \"git\": {\n    \"branch\": \"main\",\n    \"dirty\": true\n  }\n}\n```\n\nThat snapshot answers a few questions before the agent starts searching: which providers are configured, whether referrals and promotions are enabled, and whether the working tree is already dirty. The last point matters. Before editing, the agent should inspect the actual status and diff rather than treating the snapshot as permission to overwrite existing work.\n\nThe project also exposes table metadata through `codapult_db_get_table_info`. The responses identify Turso and return metadata from the project's declared schema. The fields below are a compact view of the actual results:\n\n| Table | Fields that help explain its role | \n|---|---|\n| `referral_attribution` | `referralId` ,`referredId` ,`status` ,`rewardAmount` ,`rewardType` ,`signedUpAt` ,`convertedAt` ,`rewardedAt` ,`reversedAt` | \n| `referral_reward` | `referralId` ,`userId` ,`type` ,`amount` ,`promotionId` ,`usedAmount` ,`status` ,`issuedAt` ,`reversedAt` | \n| `promotion`*(discount rules)* | Unique `code` ,`productKey` , discount mode and amount, activation dates, redemption limits, and`redemptionCount` | \n| `promotion_redemption`*(redemption records)* | `promotionId` ,`userId` , provider references, original/discount/final amounts,`status` , and`completedAt` | \n\nThese results describe the schema declared by the project. Use a live-schema comparison when you need to inspect the database itself. Foreign keys are marked as `FK`; confirm their target tables and columns in the schema definitions and migrations. Application code and tests establish status meanings, lifecycle transitions, retries, and duplicate-event handling.\n\nBoth referral tables expose reward-related fields: `rewardAmount` and `rewardType` appear on the attribution record, while `amount`, `type`, `usedAmount`, and `promotionId` appear on the reward record. I would not infer a bug or duplication from that overlap alone. It gives the agent a useful question to answer by tracing the writes and reads: which operation updates each field, and which record is authoritative at each stage of the lifecycle? The implementation and tests provide that answer.\n\nHere, the table metadata narrows the search. It does not replace the next step: tracing the corresponding code and tests.\n\nMCP configuration differs between Claude Code, Cursor, and Codex. Use the server's setup instructions for the client and version in your environment. Codapult's [AI Agents & IDEs guide](https://codapult.dev/docs/developer-tools/ai-agents-and-ides) documents the client-specific setup.\n\nOnce connected, I would start with read-only inspection. Project-status and schema tools help establish what is enabled and what data exists. Only after that should an agent use tools that generate files, change configuration, or modify a database.\n\nSome workflows come up often enough that repeating their steps in prompts becomes wasteful. They also need more detail than belongs in a root instruction file. An Agent Skill packages that procedure in a reusable directory with a `SKILL.md` entry point and, when useful, reference material and scripts. [Agent Skills](https://agentskills.io/specification) defines the open format.\n\nFor example, an investigation of referral attribution or a change to reward issuance and reversal has a predictable sequence. That checklist belongs in a Skill rather than in a new prompt every time:\n\n```\nchange-referral-reward/\n├── SKILL.md\n└── references/\n    └── referral-reward-lifecycle.md\n```\n\nIts `SKILL.md` might look like this:\n\n```\n---\nname: change-referral-reward\ndescription: >\n  Investigate or change referral attribution, reward eligibility, issuance,\n  or reversal. Use when modifying the referral reward lifecycle.\n---\n\n# Change a Referral Reward\n\nBefore changing code:\n\n1. Read the repository's referral architecture document and the Skill's lifecycle notes.\n2. Inspect attribution and reward schema; confirm foreign-key targets in the source definitions and migrations.\n3. Trace the confirmed-payment event into attribution, eligibility, and issuance.\n4. Trace referral-credit consumption and, when relevant, promotion creation and redemption.\n5. Find tests for status transitions, retries, duplicate events, and any supported reversal path.\n\nAfter the change:\n\n- Extend the existing lifecycle and preserve its documented status and transaction semantics.\n- Reuse established validation and error-handling patterns.\n- Add or update focused tests for the affected lifecycle and edge cases.\n- Run the relevant tests and architecture checks.\n```\n\nWrite the description as a trigger: name the task, the area it affects, and the conditions that make the Skill relevant.\n\nFor longer workflows, keep the entry file reasonably short and move detailed explanations into `references/`. Scripts can handle checks that should produce the same result regardless of which model runs them.\n\nThe benefit is not simply shorter context. The agent can see that a workflow exists, then load its detailed steps when the task actually calls for them.\n\nClaude Code adds host-specific options, such as running a Skill in a forked context. Keep the shared `SKILL.md` portable and use host-specific options where they improve a Claude-only workflow.\n\nThe file format is shared, but each tool has its own discovery locations:\n\n| Tool | Project locations | \n|---|---|\n| Claude Code | `.claude/skills/` | \n| Codex | `.agents/skills/` | \n| Cursor | `.agents/skills/` ,`.cursor/skills/` | \n\nCursor also discovers Skills from `.claude/skills/` and `.codex/skills/` for compatibility. Choose one canonical copy for each Skill in a shared repository; duplicate copies across these locations can cause the same workflow to appear more than once. Codex scans `.agents/skills/` from the current working directory up to the repository root, while Cursor also discovers Skills in nested project directories. This is useful in monorepos where a Skill belongs to one package rather than the whole repository.\n\nThe shared format does not make every client behave identically. For a workflow that needs to work in all three tools, keep the core `SKILL.md` portable and check each client's documented metadata and discovery rules. Host-specific features are worth adding when they solve a real problem, not simply because the option exists.\n\nSubagents make sense when a task contains investigations that can be carried out independently and return concrete findings. I would not split a small change just to use them; coordination can cost more than it saves. For a substantial referral-reward change, though, one read-only agent can trace attribution and conversion while another examines issuance, credit consumption, and any supported reversal path. The main agent can then compare the findings. Promotion validation belongs in that investigation when the reward uses a discount.\n\nThe configuration differs by host, especially around permissions:\n\nCreate `.claude/agents/architecture-reviewer.md`:\n\n```\n---\nname: architecture-reviewer\ndescription: >\n  Reviews code changes for architecture boundary violations.\n  Use after implementation or before changing shared modules.\ntools: Read, Grep, Glob\n---\n\nReview the project against its architecture documentation.\n\nLook for:\n\n- Dependencies in the wrong direction.\n- Direct imports of provider SDKs.\n- Duplicated business logic.\n- Changes to internal interfaces.\n- Missing architecture tests.\n\nDo not edit files.\n\nFor each finding, include the file path, relevant symbol,\nthe violated rule, and a suggested correction.\n\nSeparate confirmed violations from possible risks.\n```\n\nWith only `Read`, `Grep`, and `Glob` listed, this reviewer can inspect the code without file-editing tools.\n\nCreate `.cursor/agents/architecture-reviewer.md`:\n\n```\n---\nname: architecture-reviewer\ndescription: >\n  Reviews code changes for architecture boundary violations.\nreadonly: true\n---\n\nReview the changed files against the architecture docs. Check dependency direction, direct provider imports, cross-feature dependencies, and missing architecture tests.\n\nDo not modify files. Report only evidence-backed findings with file paths, relevant symbols, and a suggested correction.\n```\n\nCursor's `readonly: true` setting restricts file edits and state-changing shell commands for this subagent.\n\nCreate `.codex/agents/architecture-reviewer.toml`:\n\n```\nname = \"architecture_reviewer\"\ndescription = \"Reviews code changes for architecture violations.\"\n\ndeveloper_instructions = \"\"\"\nReview the changed code against the architecture docs. Do not edit files. Check dependency direction, provider imports, cross-feature dependencies, and missing architecture tests. Return evidence-backed findings with paths and symbols; separate confirmed violations from possible risks.\n\"\"\"\n```\n\nThat instruction is a request, not a permission boundary. Codex subagents inherit the parent session's sandbox and approval settings, so a custom agent file cannot make one subagent more restricted than its parent.\n\nFor a read-only CLI review, start the parent session with `codex --sandbox read-only --ask-for-approval never` and delegate from there. This confines local file and command operations, but it does not make external MCP tools read-only. Disable state-changing MCP tools or restrict them separately, and check the client's approval behavior and the server's authorization. The parent session is read-only too, so use this setup for review rather than implementation.\n\nCursor subagents share the parent checkout by default; for parallel editing, ask Cursor to give each worker an isolated branch and environment using a local Git worktree or a cloud workspace. A read-only reviewer can use the shared checkout.\n\nReferences:\n\nHooks attach checks or feedback to specific moments in an agent's run. They are useful for quick, predictable feedback—for example, when an agent finishes a task or is about to perform a sensitive operation. Keep them narrow: a Stop hook can ask an agent to revisit something, but it is not a substitute for a test suite or a CI check that independently evaluates the result.\n\nThe completion hook is also where the three tools differ:\n\n| Tool | Event | Stop-hook response | \n|---|---|---|\n| Claude Code | `Stop` | `decision: \"block\"` with a`reason` tells Claude why it must continue;`hookSpecificOutput.additionalContext` also continues the conversation, but appears as non-error hook feedback | \n| Cursor | `stop` | `followup_message` asks the agent to continue; it is consumed only when the run status is`completed` | \n| Codex | `Stop` | JSON on stdout with `decision: \"block\"` and`reason` asks Codex to continue rather than rejecting the user's turn | \n\nImplement the response format each host expects; the event names and payloads are not interchangeable. Claude Code exposes `stop_hook_active` and applies the same loop protections to `decision: \"block\"` and `additionalContext`, including an eight-consecutive-continuation cap. Cursor limits automatic follow-ups to five per script by default; `loop_limit` changes that cap. Check the current host documentation for the exact response schema.\n\nFor the exact event schemas and response formats, see the official references:\n\nCodex Stop hooks expect JSON on stdout when the hook exits successfully; plain-text output is not valid for that event. A pre-tool or permission hook is a better fit when a check must happen before an operation. Hook configuration and scripts deserve the same review as other project automation. Critical rules still need independent enforcement through permissions, server-side authorization, tests, and CI.\n\nSome constraints should not depend on whether an agent remembers an instruction. Deterministic checks can evaluate them on every change. Architecture documents explain the boundary, MCP supplies selected current project facts, and verification checks the resulting code against the rule.\n\nThe referral example shows why these roles are separate. MCP can report the active providers and expose the declared schema for attribution and rewards. Source code and tests reveal what the records mean in practice: which subsystem owns each lifecycle transition, when a reward can be issued, whether a reversal path exists, and how retries or provider callbacks are handled. A promotion needs to be traced as well when the reward depends on one.\n\nImportant constraints should be checked independently of the model. Depending on the boundary, that might mean:\n\n`no-restricted-imports`.\nFor JavaScript and TypeScript projects, [Codapult Guard](https://github.com/codapult/codapult-guard) is one example of a dedicated architecture guard. It maps project structure and dependencies, lets a team define the boundaries it wants to preserve, and checks later changes against that policy.\n\nProject-aware MCP exposes current project facts; an architecture guard checks whether code changes follow approved boundaries:\n\n| Question | Project-aware MCP | Architecture guard | \n|---|---|---|\n| What is in the project now? | Active providers, features, configuration, and schema | Observed modules, dependencies, and architecture facts | \n| Which boundaries should be enforced? | Provides project context for the decision | Checks the rules and contracts the team has approved | \n| Did this change respect those boundaries? | Can expose project checks | Reports violations against the active architecture policy | \n\nIn Codapult, the published CLI brings project-introspection tools and Guard's architecture checks into the same MCP integration. One gives the agent structured information about the current project; the other checks changes against approved architecture rules. The same separation applies to any project: discovering current structure and enforcing dependency policy are different tasks.\n\nUse an architecture guard alongside tests, type checks, and CI. Each catches a different class of problem.\n\nConsider a change to referral reward eligibility, issuance, or reversal. The important thing is not to give the agent every available mechanism at once. It is to bring each source of context in when it can answer a specific question. A promotion enters the investigation only when the reward or requested change depends on one.\n\nThe root instructions should point to the architecture documents that matter for this change. If an MCP server is configured, inspect current project state before searching through source files; it can narrow the investigation, but it cannot explain the implementation on its own.\n\nFor example:\n\n```\nTrace how this project handles referral attribution and reward issuance.\n\nFirst, read the root project instructions and relevant architecture\ndocuments. Inspect the current Git status and diff.\n\nIf project MCP tools are available, use read-only tools to inspect:\n- The project overview, active providers, and enabled features.\n- The schema metadata for referral_attribution and referral_reward.\n- Promotion metadata only if the reward or task uses a promotion.\n\nThen inspect the source code and identify:\n- Where referral attribution and conversion enter the application.\n- How reward eligibility is determined.\n- How reward issuance works and whether a reversal path exists.\n- How referral credits are kept separate from the main usage-credit\n  balance and consumed through the usage subsystem.\n- Whether a discount reward creates a promotion and how redemption works.\n- How status transitions, retries, and duplicate events are handled.\n- Which existing implementations and tests cover the lifecycle.\n\nConfirm foreign-key targets in the source schema and migrations;\ntable metadata identifies FK columns but not their targets.\nDo not modify files or call state-changing tools.\nFor every conclusion, provide file paths, symbols, or tool evidence.\nSeparate observed facts from assumptions.\n```\n\nProject status, schema metadata, source code, and architecture documentation answer different questions. The agent should reconcile them and surface any disagreement before proposing a change. For a larger task, a read-only subagent can independently trace the reward lifecycle or provider callback and return the relevant files, symbols, and evidence.\n\nOnly after the investigation is complete would I ask for a plan. At this point, the agent should be able to point to existing owners and behavior rather than proposing a design from assumptions. Ask for the smallest change that fits that evidence:\n\n```\nBased on the evidence, propose the smallest safe change to the\nexisting referral reward lifecycle.\n\n1. Identify the existing module and service that should own it.\n2. List the files that need to change.\n3. Identify affected statuses and lifecycle transitions.\n4. Explain how referral credits remain separate from the main usage-credit\n   balance and how the existing usage path consumes them.\n5. Identify retry, duplicate-event, idempotency, and reversal risks.\n6. Identify relevant tests and architecture checks.\n7. If a discount reward is involved, explain how the promotion is created\n   and which existing redemption path is reused.\n\nDo not write code or apply migrations yet.\nIf a relationship or invariant cannot be confirmed, say so.\n```\n\nGround the plan in existing services and interfaces. Review proposed schema or migration diffs before applying them, and integrate any generated scaffolding with the project's established services and validation patterns.\n\nOnce the plan has been reviewed, the agent can implement it using the Skill's checklist and, where useful, a subagent's independent findings. MCP generation tools may provide conventional scaffolding, but that output still has to be fitted into the feature's existing services, data model, and tests.\n\nExtend the existing referral implementation and preserve its status semantics and transaction boundaries. Keep verified idempotency behavior intact. Referral-credit issuance must remain separate from the main usage-credit balance, with consumption handled by the established usage subsystem. If a discount reward is involved, reuse the existing promotion and redemption flow. If the schema, documentation, and implementation disagree, report the discrepancy rather than silently choosing one.\n\nThe implementation is not the point at which the task is finished. Run the relevant tests and architecture checks, then have a separate reviewer inspect the diff:\n\n```\nReview the changes against the project's architecture.\n\nCheck:\n- Attribution, eligibility, and issuance remain in their established modules; any supported reversal path follows its documented owner.\n- Existing status transitions retain their documented meaning.\n- Retry and duplicate-event handling is understood and covered by tests; do not assume idempotency unless its guarantees are documented and verified.\n- Referral-credit issuance remains separate from the main usage-credit balance.\n- The established usage subsystem still consumes referral credits.\n- Any schema or migration change matches the intended relationship.\n- Relevant lifecycle tests and architecture checks actually pass.\n- If the change touches a promotion, redemption and amount handling remain correct.\n\nDo not modify files.\n\nInclude exact file paths and evidence for every finding.\nDo not claim a check passed unless you actually ran it.\n```\n\nA hook can trigger fast checks as the task finishes. A separate reviewer can look for design mistakes. CI checks the result regardless of who wrote the code. Each has a different job, and none makes the others redundant.\n\nThe sequence is research, a bounded plan, implementation, and verification. The tools help collect and check evidence; engineering judgment is still needed to decide what the evidence means for the change.\n\nAn elaborate agent setup can become another system to maintain. Start with the smallest set of mechanisms that gives agents reliable context and repeatable checks:\n\n`AGENTS.md` that points to the right context.\nAdd another mechanism only when a recurring problem gives it a clear job. More files, agents, hooks, and servers do not automatically produce better context.\n\nTreat changes to architecture documentation as part of the code change. If a provider is replaced, update its documentation. If a module is removed, clean up references to it. If a rule no longer applies, delete it rather than leaving an agent to work out whether it's still relevant.\n\nRun a periodic audit:\n\n```\nReview the repository's agent instructions, skills,\narchitecture documents, and tool-specific configuration.\n\nDo not modify anything.\n\nFind:\n- References to files or directories that no longer exist.\n- Contradictory architecture rules.\n- Skills that describe obsolete workflows.\n- Examples that don't match the current implementation.\n- Hooks that run obsolete or duplicate checks.\n- Configuration that the current agent version no longer supports.\n\nFor every finding, include its source and explain why it matters.\n```\n\nReview the findings before applying changes.\n\nKeep personal or session-specific memory separate from shared project knowledge. Team-wide architectural decisions belong in version-controlled files.\n\nWhen I first cleaned up the referral work, I treated it as an implementation problem: move the misplaced files, remove the duplicates, and restore the dependency conventions. The next session exposed what that cleanup had missed. The code had changed; the reasoning behind those boundaries had not made it into the repository.\n\nThat is what I want the setup to change. Instructions should point to the rules; architecture documents should explain ownership; source code should show what actually runs; MCP should expose selected current facts and project operations; and automated checks should catch violations that cannot depend on memory. A new session does not need the whole system loaded at once. It needs a reliable way to find the right evidence—and a way to verify a change against the decisions that matter.\n\n**Agent instructions and workflows**\n\n**MCP and practical implementation**", "url": "https://wpnews.pro/news/how-to-give-claude-code-cursor-and-codex-the-architecture-context-they-need", "canonical_source": "https://codapult.dev/blog/architecture-context-claude-code-cursor-codex", "published_at": "2026-11-25 00:00:00+00:00", "updated_at": "2026-11-25 06:12:49.288275+00:00", "lang": "en", "topics": ["ai-agents", "ai-tools", "developer-tools", "agent-protocols"], "entities": ["Claude Code", "Cursor", "Codex", "MCP", "Agent Skills", "Architecture Context Starter"], "also_reported_by": [], "takeaway": "Give coding agents a root AGENTS.md entry point plus version-controlled architecture docs, reference implementations, Agent Skills, MCP-exposed project facts, and automated checks, so agents stop duplicating modules and violating dependency conventions.", "recommendation": {"advice": "Add a root AGENTS.md summarizing layout and conventions, put architectural decisions in version-controlled docs, and add automated checks so agent changes are verified against existing boundaries.", "playbook": "coding-agents", "playbook_url": "https://wpnews.pro/playbooks/coding-agents"}, "alternates": {"html": "https://wpnews.pro/news/how-to-give-claude-code-cursor-and-codex-the-architecture-context-they-need", "markdown": "https://wpnews.pro/news/how-to-give-claude-code-cursor-and-codex-the-architecture-context-they-need.md", "text": "https://wpnews.pro/news/how-to-give-claude-code-cursor-and-codex-the-architecture-context-they-need.txt", "jsonld": "https://wpnews.pro/news/how-to-give-claude-code-cursor-and-codex-the-architecture-context-they-need.jsonld"}}