write-context-docs
Skill1 starsChanged 18 days agoMITView on GitHub
Write the context layer into a repo — root AGENTS.md, shims, CONTEXT.md, docs/adr/ and .cortex/. The apply step after a findings report. Triggers — "add the context layer", "scaffold cortex here", "write the AGENTS.md".
- Reads credentials
In this repository43 other files it gives its agents.
- AGENTS.mdAGENTS.md
- core/AGENTS.mdAGENTS.md
- evals/AGENTS.mdAGENTS.md
- index/AGENTS.mdAGENTS.md
- mcp/AGENTS.mdAGENTS.md
- tools/AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- architecture-reviewSkill
- audit-notesSkill
- challenge-planSkill
- change-impactSkill
- clarify-requestSkill
- connect-mcpSkill
- create-teamSkill
- daily-planSkill
- debug-issueSkill
- define-termsSkill
- design-specSkill
- end-of-day-summarySkill
- handover-notesSkill
- join-teamSkill
- merge-workSkill
- migrate-legacy-engineSkill
- personal-setupSkill
- quick-noteSkill
- register-projectsSkill
- repo-mapSkill
- resolve-conflictsSkill
- resume-workSkill
- retrospectiveSkill
- review-changeSkill
- set-profileSkill
- setup-repoSkill
- story-mapSkill
- suggest-skillsSkill
- summarize-filesSkill
- sync-websiteSkill
- trim-agent-docsSkill
- update-pluginSkill
- weekly-reviewSkill
- whats-changedSkill
- write-agent-docsSkill
- write-area-briefSkill
The file
We split this skill into the rules it gives an agent
11 rules. About 0 are common, 6 are distinctive, and 5 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈6
Distinctive · estimate
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 14
Run this only when the user has asked for it by name, or picked it from a findings report.
- Distinctive: line 37
If the index reports zero files, the rule above has no source to satisfy — and inventing a stack is exactly the failure it warns about.
- Very specific: line 41
Use /challenge-plan: ask the settled frontier in one round, each question with your recommended answer, rather than one at a time.
- Distinctive: line 122
Do not report success without checking:
- Distinctive: line 124
Every file step 3 lists exists: Run the check, do not recall it:
- Very specific: line 138
Every placeholder is filled: Do not grep for {{. That grep has three false hits by design: TEMPLATE.md keeps its placeholders on purpose, …
- Very specific: line 147
The files pass the repo's own formatter and its check: Write LF line endings. Then run the formatter this repo declares (state.formatters …
- Very specific: line 153
Every command in the *Running it* section actually exists — check package.json scripts, the Makefile, or whatever this repo uses.
- Distinctive: line 156
Every path in the routing table and the layout table exists on disk.
- Very specific: line 165
If reading the repo turned up setup a person has to do by hand — .env.example keys with no values, a secrets.* reference in a workflow, a …
- Distinctive: line 173
Do not restate the language's own conventions.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill 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
/write-context-docs — write the context layer
The apply half of Cortex. /setup-repo finds and reports; this writes. They are separate
skills on purpose: the one that analyses has no authority to change a repository, so "the user
decides" holds structurally rather than by good intentions.
Run this only when the user has asked for it by name, or picked it from a findings report.
1. Read before writing
node "${CLAUDE_PLUGIN_ROOT}/index/cortex-index.mjs" .Refresh the index if it is missing or stale — everything below is filled in from what is actually in the repo. A scaffold written from assumption is worse than none: it reads as authoritative and is wrong.
If .cortex/ does not exist, ask before that run. Being invoked by name covers the scaffold;
it does not cover creating a generated directory the user has never seen. That is the write
ADR 0005 gates, and generated and
gitignored is not the same as invisible. The .gitignore entry is written at creation time by the
indexer itself, so step 3 no longer has to remember it — the asking is what remains yours.
Then read enough source to answer honestly: what does this project do, how is it run, how are its tests invoked, and what would a competent newcomer get wrong on day one.
Greenfield: ask, because there is nothing to read
If the index reports zero files, the rule above has no source to satisfy — and inventing a stack is exactly the failure it warns about. The only honest source is the user, so interview them instead of the code.
Use /challenge-plan: ask the settled frontier in one round, each question with your recommended answer,
rather than one at a time. Four questions cover the template:
- What is this project, in one sentence — the purpose, not the stack?
- What is the stack — language, framework, package manager, runtime version?
- What are the commands: install, dev, test, lint? (Say if they do not exist yet.)
- What must stay true that a newcomer could break without noticing?
Then write only what they answered. A greenfield brief is short and that is correct — delete
the sections nothing filled rather than leaving {{placeholders}}, which read as instructions to
the next agent and never get cleaned up.
Two sections behave differently here:
- Layout — write the directories that exist and are intended, not aspirational ones. An empty
repo often has none; delete the table and let
/write-area-briefadd rows when structure appears. CONTEXT.md— seed it from the domain words the user used answering question 1, and say the glossary will sharpen through/define-termsas the code arrives. Do not invent terms the project has not used yet.
Say plainly what you did: the brief was written from what they told you, not from analysis, so it
should be re-checked once there is code. A greenfield brief is a hypothesis, and the first
/setup-repo run over real code is what tests it.
2. Never clobber
For each target, check first:
| Exists and has real content | Do |
AGENTS.md | write AGENTS.generated.md beside it and tell the user to diff |
CONTEXT.md | leave it; offer to add missing terms instead |
docs/adr/ or adr/ | leave it where it is; only add the template if the directory is empty |
CLAUDE.md / GEMINI.md | if they hold more than the shim line (and, for CLAUDE.md, the ## Verifying your work block /setup-repo appends), leave them |
A curated file is someone's work. Overwriting it is the fastest way to make a team distrust the tool.
3. Write
From ${CLAUDE_PLUGIN_ROOT}/templates/:
target-AGENTS.md→AGENTS.md. Fill every{{placeholder}}from the index and the code. The opening HTML comment of this template and ofCONTEXT.mdis addressed to you, so leave it out. Keep it under ~120 lines — it loads on every turn. Include the routing table heading even if it has no rows yet, so/write-area-briefhas somewhere to add them.CLAUDE.mdandGEMINI.md: each is written as one line,@AGENTS.md. Never restate the brief in them, because a copy drifts./setup-repolater appends one thing toCLAUDE.md: the## Verifying your workblock. It is the one Claude-specific section, and it belongs there.GEMINI.mdstays one line. Claude Code v2.1.277 and later can readAGENTS.mdwith noCLAUDE.mdat all, and the shim is still written: older versions and some sessions cannot, and the import is never read twice (memory).CONTEXT.md— seed from terms that genuinely appear in the code and are ambiguous. Three sharp entries beat twenty obvious ones. Delete the worked example.The ADR directory: copy
adr.mdas<dir>/TEMPLATE.md. Do not invent records; ADRs are written when a decision happens. Ask for<dir>rather than assumingdocs/adr/:node "${CLAUDE_PLUGIN_ROOT}/index/cortex-next.mjs" . --json # state.adrDir, state.adrWhyIn most repos
adrDirisdocs/adr. It isadrwhendocs/is the source of a published site, such as a Docusaurus, VitePress, MkDocs, Sphinx or Jekyll config, or a workflow that deploys Pages fromdocs. A record under that site's source would be published with the user guide. Proposeadr/and quoteadrWhyas the reason. The user may still choosedocs/adr/; those two are the locations every Cortex reader accepts. ADRs already on disk stay where they are..cortex/— creatememory/. The generated dirs are already ignored: whichever CLI first created.cortex/wrote them, because attaching that to this skill meant every other entry point left a directory of artifacts untracked in someone's repo. Verify rather than repeat it:
grep -c '^\.cortex/' .gitignore # expect 3: index/, findings/, view/.cortex/memory/ is deliberately not ignored. Say this out loud to the user: memory is
committed so the team and their agents share one context, and that is exactly why Cortex refuses
to write anything carrying a credential into it.
4. Verify what you wrote
Do not report success without checking:
Every file step 3 lists exists. Run the check, do not recall it:
ADR=docs/adr # or adr — whichever step 3 chose for f in AGENTS.md CLAUDE.md GEMINI.md CONTEXT.md "$ADR/TEMPLATE.md" .cortex/memory; do [ -e "$f" ] && echo " ok $f" || echo " MISSING $f" doneStep 3 is a bulleted list, and a bulleted list is easy to half-complete — the second shim is the one that goes missing, because the first one satisfies the feeling of having written the shims. A missing
GEMINI.mdfails silently and forever: Gemini reads no context, nothing errors, and the gap only surfaces as that agent being inexplicably worse in this repo. Anything reported MISSING gets written now, or named to the user in step 5 as deliberately skipped.Every placeholder is filled. Do not grep for
{{. That grep has three false hits by design:TEMPLATE.mdkeeps its placeholders on purpose, and a workflow's${{ … }}is GitHub Actions syntax. Run the check that knows which template each file came from:node "${CLAUDE_PLUGIN_ROOT}/tools/cortex-placeholders.mjs" AGENTS.md CLAUDE.md CONTEXT.md "$ADR"Exit 1 names each leftover as
path:line. Fill it from the index or the user, or delete the line.- The files pass the repo's own formatter and its check. Write LF line endings. Then run the
formatter this repo declares (
state.formattersincortex-loop.mjs . --json) on exactly the files you wrote, never on.. Then run the repo's lint/format check. On the first real install, the repo's test script ranprettier --list-different, and it failed on ten files Cortex had just written. If the check still fails on a file you wrote and you cannot fix it, say so in step 5 with the output. Never edit the repo's formatter config to make it pass. - Every command in the Running it section actually exists — check
package.jsonscripts, the Makefile, or whatever this repo uses. A wrong test command is the single most costly error here, because every future agent trusts it. - Every path in the routing table and the layout table exists on disk.
5. Report
List the files written, as paths. Suggest committing them so the whole team gets the context.
Then offer the two natural next steps: /write-area-brief for the areas the findings report proposed,
and /suggest-skills for skills that fit this stack. Say what the second one is for — the context
layer you just wrote is tailored to this repo, and its skills are not yet.
If reading the repo turned up setup a person has to do by hand — .env.example keys with no
values, a secrets.* reference in a workflow, a dashboard the README sends you to — list each item
and where its value comes from. That setup is the user's to do; never fill in a value yourself.
Gotchas
- The root brief gets shorter over time, not longer. As leaves appear, area-specific detail moves out of the root into them. If the root is growing, something is being duplicated.
- Do not restate the language's own conventions. Only record where this repo differs from what a competent developer would assume.
- On a monorepo, scaffold per package rather than one root brief for everything — the routing
table then points at each package's own
AGENTS.md.
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.

