Cortex / index
AGENTS.md1 starsChanged 2 months agoMITView on GitHub
Turns a repository into a structural map, then into one ranked report. lib/ holds the logic; the cortex-*.mjs files at the top are the CLIs that skills invoke. Each lib/ module's header comment holds the rules for that module alone — read it before editing the module. - Nothing here may modify a target repository, except by writing under .cortex/. findings returns data; /cortex-scaffold is the separate skill that applies changes. This separation is what makes "the user decides" structural…
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about checking a change actually works.
Of the AGENTS.md files we read, the 11,773 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository50 other files it gives its agents.
- AGENTS.mdAGENTS.md
- core/AGENTS.mdAGENTS.md
- mcp/AGENTS.mdAGENTS.md
- tools/AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- analyze-specSkill
- auditSkill
- captureSkill
- catch-me-upSkill
- connect-brainSkill
- cortex-auditSkill
- cortex-briefSkill
- cortex-enrichSkill
- cortex-impactSkill
- cortex-installSkill
- cortex-nextSkill
- cortex-profileSkill
- cortex-reviewSkill
- cortex-scaffoldSkill
- cortexSkill
- cortex-skillsSkill
- cortex-viewSkill
- dailySkill
- diagnosing-bugsSkill
- domain-modelingSkill
- dreamSkill
- grillingSkill
- handoffSkill
- improve-codebase-architectureSkill
- install-projectSkill
- level-upSkill
- migrate-engineSkill
- onboardSkill
- optimize-contextSkill
- optimize-promptSkill
- plugin-syncSkill
- reindexSkill
- resolving-merge-conflictsSkill
- resumeSkill
- scan-projectsSkill
- setup-pluginsSkill
- shipSkill
- site-syncSkill
- skill-auditSkill
- skill-creatorSkill
- team-addSkill
- team-initSkill
- weekly-reviewSkill
- wizardSkill
- writing-for-agentsSkill
The file
We split this AGENTS.md into the rules it gives an agent
4 rules. About 0 are common, 1 is distinctive, and 3 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 40
The index is deterministic: No LLM, no network, no clock, no randomness.
- Distinctive: line 92
Do not add a second.
- Very specific: line 105
A path alias is read from the repo, never guessed: Never widen this into inferring an alias from directory names — the value of an edge is …
- Very specific: line 210
Every CLI but cortex-memory.mjs earns a tools/test/cortex-*.test.sh against a real git fixture, by the rule: does it print a sentence a …
≈ “Common” is an estimate: at least 1 in 5 of the 16,595 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
index/ — the indexer, findings and enrichment
Turns a repository into a structural map, then into one ranked report. lib/ holds the logic; the
cortex-*.mjs files at the top are the CLIs that skills invoke. Each lib/ module's header comment
holds the rules for that module alone — read it before editing the module.
Invariants
- Nothing here may modify a target repository, except by writing under
.cortex/.findingsreturns data;/cortex-scaffoldis the separate skill that applies changes. This separation is what makes "the user decides" structural rather than a promise a model has to keep — if you add a write to a source file here, you have broken the product's central claim. Four named exceptions. The first,cortex-stamps.mjs update, rewrites a file Cortex itself stamped, and only in stateupdate— untouched since it was recorded, re-renderable, template changed./cortexruns it only for the paths the user confirmed. The rule lives in the code (planUpdates), not in the skill, because a guarantee belongs to the act (ADR 0016). Never widen it toedited,conflictorreview. And never from an older plugin: when the record'scortexis newer than the runningVERSION, its templates are the older ones, every untouched file reads asupdate, and applying it puts the older template back.planUpdatesrefuses the whole plan then, and takesrunningas a required argument so the check cannot be forgotten; status,diffandnext.mjsname it with the two plugin-update commands (olderPlugin).cortex: null(adopted only) and equal versions never warn. The second,cortex-shared-plugin.mjs --write, adds two entries to.claude/settings.jsonon a team's repo (spec S6). It merges and never replaces: it inserts text in the file's own style, leaving every other byte where it was, and keeps an entry already there whatever it says. It refuses a file that does not parse. The parser must agree the result is exactly the original plus the two entries, or nothing is written. Do not re-serialise the file, which reflows every inline array a team wrote.--auto-updateadds"autoUpdate": trueonly on acortexentry this run adds. An entry already there keeps itsautoUpdate— true, false or unset — because the committed value outranks each teammate's own/plugintoggle, and someone chose it. Without the flag the key is never written. The third,cortex-section.mjs --replace, rewrites one section ofCLAUDE.md, and only in stateoutdated(below). Every byte outside the section stays where it was, and the result is read back as exactly one section holding exactly the new text before it is written. Never widen it toedited. The fourth,ensureGitignored(lib/generated.mjs), appends the generated directories a target's.gitignorelacks when a CLI writes under that repo's.cortex/— append only, never.cortex/memory/(it is committed), and nothing at all when--outpoints elsewhere. - Tests that count loop rows delete
CORTEX_PROFILEat the top of the file, because a developer on a work profile must get CI's answers. Which repo is a team's isteamServed(lib/shared-plugin.mjs). - The index is deterministic. No LLM, no network, no clock, no randomness. Same tree, same
bytes. This is what makes it safe in CI and cheap on every install;
build.test.mjsasserts two runs agree exactly. - A stamped file's state, adoption and the hash rule are
lib/stamps.mjs's header. Where each loop file lands isLOOP_STAMPSinlib/loop.mjs— do not keep a second list. - A section Cortex appends to a shared file (
current·outdated·edited·kept) is defined in the headers oflib/section.mjs,lib/sections.mjsandlib/shipped-sections.mjs. Recomputing the roster from the agents would not do:rosterFor(lib/team.mjs) writes a Cortex-stamped agent as`tester`and an existing one as`tester` (tester), so every stamped section would readedited. - Every CLI here opens through
lib/open.mjs, and declares its flags rather than testing for them — all butcortex-memory.mjs, which takes a subcommand and a--rootthat means.cortex. The declaration is the allowlist: an unregistered or misspelled flag is refused with a message naming it, never reinterpreted as a path. Do not write a ninthparseArgs— there were seven, and each one was a different subset of the same bugs. - Whether a command refuses, degrades or builds when the index is unreadable is
spec.index(openTarget).readIndexalso checksINDEX_VERSION, which for one release was written into every index and read by no consumer at all — so an index in an older format was read confidently rather than refused. - Enrichment is additive. It attaches summaries to files and never edits
index.json, adds files, or removes them. enriched.jsonhas one reader —readEnrichmentinlib/enrich.mjs— and it returns a state, not a document.okis the only one a caller may trust; the states, their notes and why staleness never points atmergeare in its JSDoc. The viewer declines stale enrichment — the policy and its argument are incortex-view.mjs.findings.mjsandnext.mjsaskhas(ENRICHED_REL)and that is correct — "was this step ever run" is a question about a file existing, andnext.mjsmay only tick a step on the strength of one. Do not route them through the content reader to make the caller count come out at one.- Validate everything a model produced, but only drop what is actually wrong. Never let an
unreported drop happen — a silently incomplete enrichment looks exactly like a complete one. How
enrich.mjstells a hallucinated path from a renumbered batch is invalidateBatch.
Gotchas
- Vendored is declared in
.gitattributes, never guessed by Cortex. Same rule asgo.modandcomposer.json: declared beats guessed.briefCandidatesandisEnrichableskip it andstats.vendorednames what was skipped. A consumer that ranks or costs by size must use it and say which side it counted: silently dropping half a repo reads exactly like covering it. The one name Cortex adopts is Linguist's own default,vendor/: the walker leaves it out, counts it instats.skipped, and indexes it as source where the repo declares-linguist-vendoredthere (VENDOR_DIR,declaredOwn). Indexing every trackedvendor/as vendored was measured and rejected (#529). The rest islib/vendored.mjs's header. walk.mjsasks git, not.cortexignore. Those answer different questions:.cortexignoresays what is not knowledge in a vault, and honouring it here dropped this repo's owntools/andskills/from its index. Do not "fix" this by reading it again. ADR 0003 holds the argument and what it rules out — read it before proposing a second ignore source. Which directories are skipped by name, and which losses are counted, islib/walk.mjs's (AMBIGUOUS_SKIP_DIRS,listFiles).- "Stale" has exactly one definition, and it is
indexFreshnessinlib/open.mjs. It briefly meant two things, which is worth remembering because neither copy was wrong: preflight's was written when it was the only reachable definition, and the CLIs grew one because they could not reachtools/. Two right answers to one question still disagree the moment one of them changes. Do not add a second. - Import resolution is regex-based, so dynamic and computed imports are missed. That is a
documented limit, not a bug — it is why the orphan finding says "worth checking", never "safe to
delete". A code language
extractImportshas no case for belongs inUNRESOLVED_LANGUAGES(lib/imports.mjs). - One slot per language: a row in
ADAPTERS(lib/resolvers.mjs). Its header holds theprepare/resolvecontract. - Rust: a file no crate root contains is rooted at its own directory (
resolveRustImport). Known limit: a nested helper (tests/index/basic.rsin ripgrep) roots at its own directory rather than at the test crate's, so itscrate::utilfinds nothing. - "Unreferenced" means more than "unimported", and lives in
lib/orphans.mjs. The direction of error is chosen: it can only ever remove entries.findings.mjsandview.mjsboth call it — there is no second copy, for the reasoncoverage.mjssays. - A path alias is read from the repo, never guessed. Never widen this into inferring an alias
from directory names — the value of an edge is that it means something, and resolving
reactto a local file because abaseUrlsat above one is worse than missing the edge. - This gap was invisible to fixtures and obvious on one real repo. A Next.js app wrote 428
imports as
@/…against 104 relative ones: the index held a fifth of its edges and called 154 files orphans, and every consumer — orphans, impact, depth, the viewer — was confidently wrong. Nothing in the test suite could have found it. It happened a second time, the same way: theextendshalf was fixed andreferenceswas never considered, so a stock Vite React-TS app — the layoutnpm create vitegenerates — resolved 13 of its 109 imports and reported 30 unreferenced files. Validate resolver changes against cloned repos, and check that every resolved target actually exists on disk; more edges is not the same as correct edges. - The route map (
lib/routes.mjs; design and limits indocs/specs/2026-09-27-route-map-design.md) was validated on the Harbor workspace (7/7 calls, 3/3 gateway routes, each to one repo), the RealWorld React + Spring pair (22/22 calls, 19/19 handlers) and spring-petclinic; every citedfile:linewas opened and checked. - Coverage uses three signals — name, import, and a quoted string mention — and lives in
lib/coverage.mjs, shared byfindings.mjsandimpact.mjs. Each alone misreports: naming alone calledmcp/libuntested when its tests live inmcp/test; a CLI spawned as a subprocess is invisible to both name and import, which is what the mention signal is for. Do not copy this heuristic into a third caller — two copies would agree today and disagree in a month, with nothing to say which is right. - A skill Cortex wrote is checked against the repo it describes, by
lib/skill-drift.mjs. Validated on the first upgraded repo (#462): 12 findings, all real. cortex-impact.mjsreads the graph backwards — who imports me, not what do I import — and every count it returns is a floor, namedatLeastso a caller cannot print it as a total.--sizerecommends and never decides (lib/sizing.mjs). A finer sizing-local area key was tried and rejected: zustand'svanilla.ts,react.tsandtraditional.tsshare one directory, so no directory key sees that refactor as spread.- Every path two change sets compare goes through
normalizeChangedPath(lib/changed.mjs).--againstitself islib/overlap.mjs's header. - Where ADRs live is
lib/adr.mjs's one answer (isAdrPath,adrLocation); no reader keeps its owndocs/adr/regex. - The page carries nothing about the machine that built it — no absolute root, no home
directory (
scrubPathsinlib/view.mjs). The viewer's other rules — what draws on the Map, onestatsfield per count,safeJson— are in the comments oflib/view.mjsandlib/view-html.mjs. - A single file over the line budget is allowed through as its own batch; only accumulation is bounded.
The loop reader — lib/loop.mjs
Its rules are in its comments and loop.test.mjs; the second-round rows are SECOND_ROUND in
lib/next.mjs.
- Validated on
got(npm),fzf(Make, Go) andflask(Python, nested example manifests), and mutation-tested: nine guards broken one at a time, nine test failures. The watcher, lockfile and hooks rules were validated on bulletproof-react, vitest (root and examples), zustand, the Nest starter, a CRA app, ripgrep and fzf, with nineteen more guards mutated. Do both again when a row or a detector changes — fixtures here share the author's blind spots.
The Claude-setup checker — lib/claude-setup.mjs
Validated on superpowers, anthropics/skills and anthropics/claude-code; each false positive found
there (a negated "not read-only", [Title](URL), "explain the reasoning", unindented prose in a
description) has a test.
- A mod is judged by its files, never by its code. A plugin's
hooks/hooks.jsonwith amoduleskey is a mod. The checker reads the shape ofmodules, whether the path (relative tohooks.json) names a file, and its extension. Which events the module handles and which calls it makes is whatclaude plugin validateprints; a regex copy would disagree with it. Ahooks.jsonthat does not parse is alreadysettings-not-json, so mods have no finding of their own for it. Validated on the four mods in anthropics/claude-code and the three in anthropics/claude-code-playground (each reportsmod-presentand nothing else), with nine guards mutated and nine test failures.
How the scoped briefs load — lib/instructions.mjs
- A fact, not a finding. Under a root
CLAUDE.md, Claude Code does not read a subdirectory'sAGENTS.mdon its own. The setting that changes it is ignored in project settings, so no edit to the repo fixes it, andtools/test/cortex-follows-its-own-rules.test.shfails on anything a repo could fix. It is therefore one sentence in the findings report's glance and oncortex-next's brief step, both read fromleavesNote. Do not move it intoclaude-setup.mjs. - Validated on anthropics/claude-code and claude-code-playground (a
CLAUDE.mdand no scoped brief: silent), openai/codex (a scoped brief and noCLAUDE.md: silent) and this repo (four briefs under the shim: stated). Seven guards mutated, seven test failures.
The agents a repo already has — lib/agents.mjs
- Validated by hand on 83 agents in seven public repos (octez-manager, metaxy, spica, kapi-sprints,
a-safe-pulse, Heimdall, posthog). Two mappings are still wrong, and both are recoverable because
the developer confirms every mapping. octez-manager's
architectis a pre-merge architecture reviewer, and the name outranks a description with no job words. spica'spr-review-analystreviews other reviewers' comments. Mutation-checked: 32 guards, each breaking a test.
The team offer — lib/team.mjs
- Validated on kapi-sprints (offers the architect only; four roles covered), octez-manager (tester
and Project manager;
docs/plans/exists) and zustand (no agents: four roles, the Project manager waits). Mutation-checked withagents.mjs,loop.mjs,stamps.mjsand the CLI: 41 guards, each breaking a test.
Tests
node --test index/test/*.test.mjslib/ is well covered, and since lib/open.mjs exists that now includes argument handling:
open.test.mjs drives the unknown flag, the -v-shaped root, the corrupt index and the version
mismatch from literals, with a fake io so a refusal is an observation rather than a dead test
runner. It used to be reachable only by spawning a real process from a shell fragment, which is why
seven copies of it went unexercised.
Every CLI but cortex-memory.mjs earns a tools/test/cortex-*.test.sh against a real git
fixture, by the rule: does it print a sentence a user will act on, or write into their repo? A
CLI whose only failure mode is a crash does not need one — a stack trace is its own report. The
reason these must be git fixtures and not mkdtemp directories is that git is what decides the
answer: walk.mjs asks it (ADR 0003), churn drives severity, and a non-git fixture can only ever
execute one side of both. Each test's header says what it defends.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

