How to Give Claude Code, Cursor, and Codex the Architecture Context They Need 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. A practical guide to giving Claude Code, Cursor, and Codex reliable architecture context with AGENTS.md, project documentation, Agent Skills, MCP, and automated verification. 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. In this guide I ran into this problem while working on promo-code and referral functionality with an AI coding agent. The 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. That was the frustrating part. The agent could write the code, but it didn't understand why certain things belonged where they did. I had those decisions in my head. The repository didn't explain all of them. Coding 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. An 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. The 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. That 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. 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. Claude 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. For 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. I'd begin with one AGENTS.md at the root of the repository. Treat 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. For example, a repository might use a layout like this the application directories are illustrative : my-app/ ├── AGENTS.md ├── docs/ │ └── architecture/ │ ├── overview.md │ ├── boundaries.md │ ├── data-ownership.md │ ├── referrals-and-promotions.md │ └── decisions/ ├── src/ │ ├── app/ │ ├── features/ │ ├── server/ │ │ ├── services/ │ │ └── adapters/ │ └── shared/ └── package.json The root instruction file could be as simple as: Project Instructions Overview A SaaS application with referral and promotion functionality. Architecture - src/app contains routes and request entry points. - src/features contains product-specific functionality. - src/server/services contains application services. - src/server/adapters contains external provider integrations. - src/shared contains code shared between features. Important Boundaries - Keep business logic inside its owning feature. - Preserve documented dependency direction; do not introduce parallel implementations. - Read docs/architecture/referrals-and-promotions.md before changing referral rewards or promotion redemption. - Trace the existing lifecycle and tests before changing behavior. - Validate input at API and server action boundaries. Architecture Documentation - Overview: docs/architecture/overview.md - Dependencies: docs/architecture/boundaries.md - Data ownership: docs/architecture/data-ownership.md - Referral and promotions: docs/architecture/referrals-and-promotions.md - Decisions: docs/architecture/decisions/ Read the relevant document before changing an affected area. Verification Use the scripts defined in package.json. Run relevant tests and type checks after changing application code. Run architecture checks when changing module dependencies. Use 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. Avoid vague instructions such as: Follow clean architecture. Write maintainable code. Use appropriate abstractions. They sound sensible, but an agent has to guess what they mean in the context of your application. Compare this: Follow clean architecture. With: The referral feature owns attribution, conversion, eligibility, and reward issuance. The usage subsystem owns referral-credit consumption. Discount rewards use the existing promotion and redemption flow. Read the architecture notes before changing lifecycle behavior. The 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. That 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. Keep 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. All three tools support AGENTS.md , but their discovery rules are worth understanding. 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. 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. 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. By 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. For a repository-portable setup, you can also import the shared instructions from CLAUDE.md : @AGENTS.md Claude Code For changes involving multiple modules, inspect their dependencies before proposing an implementation. Direct 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. Official documentation: A 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. For the examples below, assume the referral feature lives under src/features/referrals/ . Claude 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/ : --- paths: - 'src/features/referrals/ / .ts' - 'src/features/referrals/ / .tsx' --- Referral Rules - Read docs/architecture/referrals-and-promotions.md before changing this area. - Follow its ownership boundaries and trace the affected lifecycle before editing. Claude Code loads the rule when it reads or edits matching files. Rules without a paths field are loaded as general project instructions. Organize .claude/rules/ by domain when the application has several areas with different conventions. Cursor uses .cursor/rules/ .mdc files. The same illustrative feature path can be expressed in its metadata: --- description: Referral attribution and reward lifecycle rules globs: src/features/referrals/ / .ts, src/features/referrals/ / .tsx alwaysApply: false --- The rule body can contain the same referral-specific guidance: Referral Rules - Read docs/architecture/referrals-and-promotions.md before changing the referral lifecycle. - Follow the documented module boundaries; do not add a parallel reward path. - Run the relevant lifecycle tests after the change. The 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. Cursor 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. Codex 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: src/ └── features/ └── referrals/ └── AGENTS.md The nested file could contain: Referral Feature Instructions - Read docs/architecture/referrals-and-promotions.md before changing this area. - Follow the documented ownership boundaries and trace the affected lifecycle before editing. Codex 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. This is the practical difference between the three approaches: | Tool | How scoped instructions are selected | |---|---| | Claude Code | Path patterns in .claude/rules/ | | Cursor | File globs in .cursor/rules/ | | Codex | Instruction files along the current working-directory path | The policy can stay the same across tools, but it has to live where each host will actually discover it. A directory tree is a starting point, not an architecture description. The 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. In 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. Those 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. A concise architecture note could describe the responsibilities without tying the explanation to particular source paths or function names: Referral Reward Architecture Responsibilities - The referral feature owns attribution, conversion processing, reward eligibility, and issuance. - The usage subsystem owns consumption of referral credits. - Referral credits remain separate from the main usage-credit balance. - Discount rewards use the promotion and redemption flow. - Payment confirmation triggers conversion processing; the referral feature remains responsible for reward eligibility and issuance. Boundaries - Do not create a parallel referral reward-issuance path. - Do not use the main usage-credit balance to represent referral credits. - Keep credit consumption in the established usage flow. - Keep promotion validation and redemption in the promotion flow. - Before changing lifecycle behavior, trace status transitions, retries, reversals, and duplicate-event handling, then preserve the behavior confirmed by the implementation and tests. Before changing a reward 1. Trace the confirmed-payment event into referral conversion. 2. Find the existing eligibility, issuance, and reversal behavior. 3. Trace how referral credits are consumed. 4. If the reward is a discount, inspect promotion creation and redemption. 5. Check transaction boundaries, retries, and lifecycle tests. For 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: ADR: Keep Referral Credits Separate from Main Usage Credits Context Referral rewards have their own eligibility and lifecycle. Credit-type rewards are consumed separately from the application's main usage-credit balance. Decision Keep referral-credit accounting separate and route consumption through the usage subsystem. Consequences - Referral reward issuance and usage-credit consumption have distinct owners. - Tests cover issuance and consumption as separate behaviors. - Changes to the main usage-credit balance do not redefine referral rewards. Keep 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. A 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. The 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. MCP 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. A 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. Code 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. I 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? | Context | Best place | Example | |---|---|---| | Rules that should influence most tasks | AGENTS.md or host project instructions | Extend the existing referral flow; preserve lifecycle behavior; run relevant tests | | Architectural reasoning and ownership | Version-controlled architecture docs and ADRs | Referral owns reward eligibility and issuance; usage owns credit consumption | | Current implementation details | Source code and reference implementations | Existing conversion, issuance, redemption, and test patterns | | Current structured project state | MCP resources and read-only tools | Enabled features, active providers, table metadata, environment contract | | Repeatable multi-step procedures | Agent Skills | Change a reward lifecycle, implement a migration, review a release | | Independent investigation | Subagents | Trace conversion and reward handling separately | | Lifecycle feedback | Hooks | Run a targeted check when an agent reaches a completion event | | Independent enforcement | Tests, linters, architecture checks, and CI | Fail a build when a required boundary or test is violated | Use 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. MCP servers can expose three useful kinds of capability: A 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. In 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: | Tool | Information it provides | |---|---| | codapult project status | Active adapters, enabled features, plugins, and Git status | | codapult db get table info | Column names, database types, and declared constraints for a selected table | The 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. In 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: { "adapters": { "database": "turso", "auth": "better-auth", "payments": "stripe" }, "features": { "enabled": "referrals", "promotions" }, "git": { "branch": "main", "dirty": true } } That 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. The 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: | Table | Fields that help explain its role | |---|---| | referral attribution | referralId , referredId , status , rewardAmount , rewardType , signedUpAt , convertedAt , rewardedAt , reversedAt | | referral reward | referralId , userId , type , amount , promotionId , usedAmount , status , issuedAt , reversedAt | | promotion discount rules | Unique code , productKey , discount mode and amount, activation dates, redemption limits, and redemptionCount | | promotion redemption redemption records | promotionId , userId , provider references, original/discount/final amounts, status , and completedAt | These 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. Both 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. Here, the table metadata narrows the search. It does not replace the next step: tracing the corresponding code and tests. MCP 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. Once 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. Some 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. For 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: change-referral-reward/ ├── SKILL.md └── references/ └── referral-reward-lifecycle.md Its SKILL.md might look like this: --- name: change-referral-reward description: Investigate or change referral attribution, reward eligibility, issuance, or reversal. Use when modifying the referral reward lifecycle. --- Change a Referral Reward Before changing code: 1. Read the repository's referral architecture document and the Skill's lifecycle notes. 2. Inspect attribution and reward schema; confirm foreign-key targets in the source definitions and migrations. 3. Trace the confirmed-payment event into attribution, eligibility, and issuance. 4. Trace referral-credit consumption and, when relevant, promotion creation and redemption. 5. Find tests for status transitions, retries, duplicate events, and any supported reversal path. After the change: - Extend the existing lifecycle and preserve its documented status and transaction semantics. - Reuse established validation and error-handling patterns. - Add or update focused tests for the affected lifecycle and edge cases. - Run the relevant tests and architecture checks. Write the description as a trigger: name the task, the area it affects, and the conditions that make the Skill relevant. For 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. The 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. Claude 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. The file format is shared, but each tool has its own discovery locations: | Tool | Project locations | |---|---| | Claude Code | .claude/skills/ | | Codex | .agents/skills/ | | Cursor | .agents/skills/ , .cursor/skills/ | Cursor 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. The 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. Subagents 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. The configuration differs by host, especially around permissions: Create .claude/agents/architecture-reviewer.md : --- name: architecture-reviewer description: Reviews code changes for architecture boundary violations. Use after implementation or before changing shared modules. tools: Read, Grep, Glob --- Review the project against its architecture documentation. Look for: - Dependencies in the wrong direction. - Direct imports of provider SDKs. - Duplicated business logic. - Changes to internal interfaces. - Missing architecture tests. Do not edit files. For each finding, include the file path, relevant symbol, the violated rule, and a suggested correction. Separate confirmed violations from possible risks. With only Read , Grep , and Glob listed, this reviewer can inspect the code without file-editing tools. Create .cursor/agents/architecture-reviewer.md : --- name: architecture-reviewer description: Reviews code changes for architecture boundary violations. readonly: true --- Review the changed files against the architecture docs. Check dependency direction, direct provider imports, cross-feature dependencies, and missing architecture tests. Do not modify files. Report only evidence-backed findings with file paths, relevant symbols, and a suggested correction. Cursor's readonly: true setting restricts file edits and state-changing shell commands for this subagent. Create .codex/agents/architecture-reviewer.toml : name = "architecture reviewer" description = "Reviews code changes for architecture violations." developer instructions = """ Review 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. """ That 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. For 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. Cursor 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. References: Hooks 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. The completion hook is also where the three tools differ: | Tool | Event | Stop-hook response | |---|---|---| | 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 | | Cursor | stop | followup message asks the agent to continue; it is consumed only when the run status is completed | | Codex | Stop | JSON on stdout with decision: "block" and reason asks Codex to continue rather than rejecting the user's turn | Implement 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. For the exact event schemas and response formats, see the official references: Codex 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. Some 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. The 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. Important constraints should be checked independently of the model. Depending on the boundary, that might mean: no-restricted-imports . For 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. Project-aware MCP exposes current project facts; an architecture guard checks whether code changes follow approved boundaries: | Question | Project-aware MCP | Architecture guard | |---|---|---| | What is in the project now? | Active providers, features, configuration, and schema | Observed modules, dependencies, and architecture facts | | Which boundaries should be enforced? | Provides project context for the decision | Checks the rules and contracts the team has approved | | Did this change respect those boundaries? | Can expose project checks | Reports violations against the active architecture policy | In 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. Use an architecture guard alongside tests, type checks, and CI. Each catches a different class of problem. Consider 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. The 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. For example: Trace how this project handles referral attribution and reward issuance. First, read the root project instructions and relevant architecture documents. Inspect the current Git status and diff. If project MCP tools are available, use read-only tools to inspect: - The project overview, active providers, and enabled features. - The schema metadata for referral attribution and referral reward. - Promotion metadata only if the reward or task uses a promotion. Then inspect the source code and identify: - Where referral attribution and conversion enter the application. - How reward eligibility is determined. - How reward issuance works and whether a reversal path exists. - How referral credits are kept separate from the main usage-credit balance and consumed through the usage subsystem. - Whether a discount reward creates a promotion and how redemption works. - How status transitions, retries, and duplicate events are handled. - Which existing implementations and tests cover the lifecycle. Confirm foreign-key targets in the source schema and migrations; table metadata identifies FK columns but not their targets. Do not modify files or call state-changing tools. For every conclusion, provide file paths, symbols, or tool evidence. Separate observed facts from assumptions. Project 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. Only 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: Based on the evidence, propose the smallest safe change to the existing referral reward lifecycle. 1. Identify the existing module and service that should own it. 2. List the files that need to change. 3. Identify affected statuses and lifecycle transitions. 4. Explain how referral credits remain separate from the main usage-credit balance and how the existing usage path consumes them. 5. Identify retry, duplicate-event, idempotency, and reversal risks. 6. Identify relevant tests and architecture checks. 7. If a discount reward is involved, explain how the promotion is created and which existing redemption path is reused. Do not write code or apply migrations yet. If a relationship or invariant cannot be confirmed, say so. Ground 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. Once 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. Extend 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. The 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: Review the changes against the project's architecture. Check: - Attribution, eligibility, and issuance remain in their established modules; any supported reversal path follows its documented owner. - Existing status transitions retain their documented meaning. - Retry and duplicate-event handling is understood and covered by tests; do not assume idempotency unless its guarantees are documented and verified. - Referral-credit issuance remains separate from the main usage-credit balance. - The established usage subsystem still consumes referral credits. - Any schema or migration change matches the intended relationship. - Relevant lifecycle tests and architecture checks actually pass. - If the change touches a promotion, redemption and amount handling remain correct. Do not modify files. Include exact file paths and evidence for every finding. Do not claim a check passed unless you actually ran it. A 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. The 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. An elaborate agent setup can become another system to maintain. Start with the smallest set of mechanisms that gives agents reliable context and repeatable checks: AGENTS.md that points to the right context. Add another mechanism only when a recurring problem gives it a clear job. More files, agents, hooks, and servers do not automatically produce better context. Treat 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. Run a periodic audit: Review the repository's agent instructions, skills, architecture documents, and tool-specific configuration. Do not modify anything. Find: - References to files or directories that no longer exist. - Contradictory architecture rules. - Skills that describe obsolete workflows. - Examples that don't match the current implementation. - Hooks that run obsolete or duplicate checks. - Configuration that the current agent version no longer supports. For every finding, include its source and explain why it matters. Review the findings before applying changes. Keep personal or session-specific memory separate from shared project knowledge. Team-wide architectural decisions belong in version-controlled files. When 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. That 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. Agent instructions and workflows MCP and practical implementation