Audit a codebase and bind every claim it makes about itself to a mechanism that fails when the claim stops being true, so it is legible to people and AI agents.
复制下面这句话,粘贴给 Claude Code、Codex、Cursor 等 AI 编程工具,它会读取安装说明并在你确认后完成安装。
请阅读 https://ai.atlankj.com/install/asset/gh-context-architecture-68e994871670 ,按照其中的说明把「context-architecture」安装到你(当前 AI 工具)中。执行前先告诉我将运行的命令和写入的位置,等我确认。
查看 AI 将读取的安装说明正在读取 GitHub 原文…
内容来自 GitHub 原始文件,由原作者维护。在 GitHub 查看
This skill applies Context Architecture to a repository: it makes the repo's intent and behavior equally legible to people and AI agents, and binds every claim the repo makes about itself to a mechanism that fails when that claim stops being true. It works from the first commit (a repo can be born legible) and on a repo that grew without design (restructured in steps, never all at once). The job is to take the repo as it is and make it legible and self-verifying, without a big-bang rewrite.
Context Architecture treats the repository itself (its file tree, boundaries, conventions, and embedded context) as a designed artifact, not an accident of growth. Introduced by Sergio Azócar in October 2025. Canonical specification: https://context-architecture.dev
Design for a reader who retains nothing between sessions and knows only what the repository says out loud. An AI agent meets this exactly; a new human contributor approximates it. Agents keep memory now, but it is local, unverified, and unshared, so it is not the repository's truth; design as if it were absent.
Every claim a repository makes about itself must be bound to a mechanism that fails when that claim stops being true.
That is the whole architecture. Everything else is how you apply it.
A claim is anything the repository holds about itself, not just the shape of its folders. "Prices are computed in this module and nowhere else" is a claim. "This operation responds within a certain time" is a claim. "This data format does not break for the people already using it" is a claim. For each one, ask: is there a compiler, a linter rule, an automated test, or a review step (by a person or an agent) that breaks when that stops being true? If not, it is prose, and prose goes stale without anything noticing. A claim with no mechanism behind it is the violation.
The mechanism has to actually fail, not just exist. A performance test that never exercises the slow path does not satisfy the rule, it violates it. That a test can fail is a claim too: mutation testing checks it, a surviving mutant is a test that cannot fail. The rule applies to itself: the set of tests and rules that verify the repository is itself a set of claims, so it too is bound to a mechanism that fails if it is weakened.
Working with an agent is a continuous flow of code changes, and the rule lives inside it. When a change introduces a claim (a source of truth, an invariant, a convention), bind it to a mechanism in the same change; a change that touches existing code meets the mechanisms already there, so a violation goes red before it reaches production. It is not a one-time setup but a property maintained change by change, which is why the context grows with the system instead of falling behind. A claim left loose is caught in review, by a person or an agent, and bound before the change is accepted.
Context Architecture serves the whole autonomy spectrum. What changes across it is who consumes
the verification, not the verification. The same AGENTS.md and the same mechanisms work at every
level: inline (a person, or a classifier, approves each edit), async (a person reviews before
integrating), autonomous (a person sets the rules and does not watch each change), and orchestrated
(nobody in the middle). As of 2026 all four exist as products, and with several agents in parallel
the merge queue is where the mechanisms arbitrate. When there is a person, the mechanisms absorb the
routine checks; when there is no person, they are the reviewer.
Binding a claim is connecting it to something that fails when it stops being true. Context
Architecture names the kinds of mechanism; the repository picks the product (oxlint or eslint,
it makes no difference), and the infrastructure runs it on each change.
AGENTS.md that
mentions a deleted file turns the tests red.Where a mechanism fires is the infrastructure's choice: a hook the repository commits runs it in the agent's loop, the repository's rules run it at push, or CI runs it. Firing early does not replace the gate, because a hook can be switched off locally. The split is clean: Context Architecture decides what gets verified and guarantees the mechanism exists and fails. The infrastructure runs it.
Apply it to: repositories that absorb agent or multi-person work, refactors at scale, mechanical migrations, features with a clear spec. It applies from the first commit (a repository can be born legible) and to one that grew without design, restructured in steps.
Do not force it onto: throwaway projects, ill-defined problems, the first prototype of something not yet understood. The structuring work is an investment that pays back in proportion to how much agent or multi-person work the repo absorbs. On a throwaway, the cost outweighs the return. Say so when you see it.
Each principle is a property you can check, not an aspiration. Either it is true of the repository and bound to a mechanism, or it is not. If it cannot be bound to something that fails, it is not a principle.
01 · Structure Screams Intent. The file tree says what the system does, not what framework built
it. A billing/ folder names a business responsibility; a controllers/ folder names a technical
detail that could belong to any system. The framework lives one level down, inside the domain it
serves.
Mechanism: a linter rule that errors when a file lands in a folder that does not match its domain.
02 · Context Lives With Code. Context lives next to the code it describes, at every important
boundary, not in a separate wiki that goes stale. It holds only what the code cannot say on its own:
where the source of truth is, what invariants must be respected, what tech debt was accepted on
purpose, what behavioral limits apply.
Mechanism: a test that fails if an AGENTS.md mentions a file that no longer exists.
03 · Boundaries Are Explicit and Named. Each module and package is named for the responsibility
it owns. Folders like utils/, common/, or helpers/ collect anything, because the name rules
nothing out. Genuinely shared, domain-free code goes in a small shared/ with no dependencies
toward any domain. If you cannot name a boundary precisely, the boundary is usually drawn wrong.
Mechanism: a rule that forbids a module from importing across another boundary through paths that
are not allowed, and breaks the build when it happens.
04 · The Repo Is Legible at Every Zoom Level. Legibility works at every level. A clean tree with
functions named doStuff or data2 is legible at one level and illegible at the next. The same
discipline that names folders names functions, types, and variables.
Mechanism: linter rules on names and complexity limits.
05 · Capabilities Are Discoverable. The project's tools, scripts, and commands live in
predictable places with names that say what they do (package.json scripts, a scripts/ folder, a
skills folder). A capability an agent cannot find does not exist for that agent: it reimplements it.
The list of capabilities is generated from those predictable places, not written by hand.
Mechanism: the list generated from the conventional paths, and a test that fails if a real
capability does not appear in it.
06 · Intent Becomes Mechanism. Intent is written as a spec before the code, then turned into the code and into the tests and rules that enforce it, and the spec is removed once its content already lives there. What stays is the intent and its verification, not the code that satisfies it: as long as the tests pin down the behavior, that code can be regenerated. Mechanism: the tests, the types, and the rules the spec was turned into.
07 · Conventions Are Codified, Not Implicit. A convention that lives only in people's heads is invisible to an agent, and the agent will break it. Take it out of the culture and put it in the tools that review the code: linter rules, type constraints, automated validations in CI that state the rule and enforce it in the same place. Mechanism: the linter rules and the type constraints.
08 · Behavior Is Verifiable, Not Asserted. Every claim about how the system behaves (how long an operation may take, what data must not cross a boundary, what format must not break for the people already using it) is bound to an automated test that lives in the repository and goes red when the behavior strays. A time limit in a document goes stale; the same limit bound to a test that fails when it is exceeded is architecture. Mechanism: an automated behavior test (performance, data contract, security) that lives in the repository and fails when the behavior deviates.
09 · The Verification Surface Is Itself Bound. The set of tests and rules that verify the repository is, in turn, a set of claims, so it too is bound. An agent can rewrite the code freely, but it cannot weaken or delete a test, a rule, or a validation to get a change through. Without a person reviewing, this is the principle that matters most: the cheapest way to make a validation pass is to remove it. Mechanism: a validation that goes red if the set of tests and rules changes without the authorization the repository defined.
Run four phases in order. Phases 1 and 2 are read-only; do not edit until you have the audit and a prioritized plan. The work in phase 3 is incremental: one bounded change at a time, each landing with the mechanism that keeps it true.
Walk the repository and judge it against the nine principles. Read the top-level tree first, then the boundaries, then a sample of leaf files. For each principle, record a verdict (holds / partial / violated), the evidence (paths), and the mechanism that is (or should be) bound to it.
Use the five failure modes as diagnostic signals: each is what a cold reader does when a claim is not bound, and each points back at the principle that is loose. A better model lowers their frequency, it does not remove them, because the missing mechanism is in the repository, not the reader. When you see one of these in the repo's history (or imagine a cold agent producing it), name the unbound claim behind it:
Never propose a big-bang restructuring. Order the work by leverage and reversibility:
AGENTS.md at the root and the few highest-traffic
directories). Highest legibility gain per edit.utils//common/ only where it buys clarity;
keep a genuinely generic shared/ small).AGENTS.md beats a
full reshuffle.Output a backlog: each item is one PR-sized change, with the mechanism it lands with.
Each move pairs a claim with the mechanism that fails when the claim stops being true. A move without its mechanism is just documentation; do not land it that way.
Place an AGENTS.md at each meaningful boundary. Keep it short and specific to its scope. Put
in it only what cannot be learned by reading the code:
# AGENTS.md (<boundary name>)
<One line: what this boundary owns.>
## Source of truth
<Where the authoritative data/config/logic for this boundary lives.>
## Invariants
<Rules that must hold. Each should be bound to a mechanism; note which.>
## Gotchas / accepted tech debt
<What looks wrong but is intentional, and why.>
## The why a spec left behind
<Rationale the code cannot hold, moved here from a removed spec (principle 06).>
Bind each invariant to a mechanism, and add the mechanism in the same change, or the AGENTS.md is a new claim that can go stale.
Bind claims to mechanisms. The four kinds, each catching a kind of drift:
Detect and fix context rot. Find documentation that lies:
README, AGENTS.md/CLAUDE.md,
the path-scoped rule files (.claude/rules, .cursor/rules, .github/instructions), SKILL.md,
and design docs; verify each still exists / still runs. Dead references are the highest-priority fix.AGENTS.md against the code it sits beside: does it describe modules, exports, or flows
that no longer match? Correct the doc, then add the test that would have caught it.Name boundaries. Rename or split utils//common//core/ only where a precise name exists
(pricing-engine, auth-session, event-ingestion). If you cannot name a boundary precisely, that
is a signal the boundary is wrong, not an excuse to call it shared. Keep a genuinely generic
shared/ small and dependency-free.
Make capabilities discoverable. Move scripts/generators/commands to conventional, named
locations (package.json scripts, a scripts/ or skills/ directory). Where possible,
generate the capability index from the conventional paths rather than hand-keeping it, and test
that the index is complete. A hand-kept list is itself a claim that goes stale.
Context grows with the system only if write-and-verify runs on every change. Put the review
instruction where the repository's reviewers read it (the root AGENTS.md; a REVIEW.md if an agent
reviews pull requests) and wire the check that fails when a claim lands loose: the doc-reference test
as a required check, and where supported a hook that runs the tests before the turn ends. The
instruction says what to look for; the check stops the change. Bind the verification surface itself
(principle 09): a test over the lint and CI config, CODEOWNERS plus a ruleset over tests/ and that
config, and a check that can fail (mutation testing or a deliberate break). Promote a recurring
correction to a bound claim, not a note the agent keeps to itself.
Produce this before any edit:
# Context Architecture audit (<repo>)
## Summary
<2-3 sentences: where would a cold reader (a person or an agent) guess, and why.>
## Per-principle verdict
| # | Principle | Verdict | Evidence (paths) | Mechanism (bound / missing) |
|---|-----------|---------|------------------|------------------------------|
| 1 | Structure Screams Intent | holds / partial / violated | ... | ... |
| ... | | | | |
## Failure-mode signals
<For each signal observed: the failure mode, the unbound claim behind it, the principle it points at.>
## Context-rot found
<Dead references in docs: file, the false claim, the correct state.>
## Prioritized backlog
1. <PR-sized change>, lands with <mechanism>. Leverage: <why first>.
2. ...
AGENTS.md invariant, a README
promise, or a convention doc without the check that fails when it stops being true.Canonical specification, the nine principles in full, and the comparison with context engineering and harness engineering: https://context-architecture.dev. Raw, agent-readable: https://context-architecture.dev/llms.txt