process: Lean agent context with progressive disclosure (short core, path-scoped rules, skills on demand)
Back to our planType
process
Summary
Agents read a set of instruction files every time they start working on this site. Today that set is about 1,650 lines, most of it unrelated to any given task. That costs tokens in every session and every subagent, and long instruction files are followed less reliably. This change keeps a short core always loaded (at most 300 lines) and makes everything else load only when the work calls for it. It is step 1 of the knowledge layer (see the epic linked in the comments).
Regroomed on 2026-11-06: the earlier version of this issue measured a .claude/rules/ folder that no longer exists. The first comment dated 2026-11-06 says what changed.
Problem
Measured on main at d268658 (2026-11-06):
CLAUDE.mdis 87 lines and imports ten files. Together the ten are 1,564 lines, about 17,500 words:File Lines AGENTS.md221 docs/project.md207 docs/process/project-management.md213 docs/guidelines/guard-rails.md61 docs/guidelines/development.md149 docs/guidelines/security.md120 docs/guidelines/payload-cms.md110 docs/guidelines/nextjs-tailwind.md139 docs/guidelines/components-and-content.md94 docs/guidelines/ui-ux-design.md250 All of it loads into every session, and into every subagent, whatever the task: a wording fix in a post loads the security and Payload guidelines too.
What the vendor says (Claude Code: memory, opens in a new tab): target under 200 lines per instruction file, because longer files use more context and reduce adherence; imports help organize a file but don't reduce its cost; rules scoped to paths load only when matching files are opened; instruction files in subfolders load when a file there is read.
What studies found: context files raised cost by over 20% without improving success on average (ETH Zurich, opens in a new tab). A compact always-loaded index did better than instructions the agent had to choose to open, which were skipped in 56% of runs (Vercel, opens in a new tab). So the answer is a small core plus loading triggered by the files being touched, not by the agent's choice.
Proposed fix
Always loaded (at most 300 lines in total):
AGENTS.mdtrimmed to at most 200 lines,docs/guidelines/guard-rails.md, and the Claude Code notes that apply to every session. The knowledge index joins this set when the knowledge-layer design creates it.Everything else loads on a trigger. The text stays where it is, in
docs/, as the one source for Claude Code and Codex; an adapter file holds only the trigger. Proposed triggers:File Loads when the work touches payload-cms.mdsrc/**/cms/**,src/payload.config.ts,src/platform/payload/**,src/migrations/**nextjs-tailwind.md,ui-ux-design.md,components-and-content.mdsrc/**/*.tsx,src/app/**,src/themes/**,src/platform/ui/**,src/platform/theme/**security.mdsrc/modules/accounts/**,src/modules/verification/**,src/modules/agents/**,src/platform/payload/**, route handlers,src/proxy.ts,ops/**,.github/workflows/**development.mdany file under src/project.mdsplit: the stack summary stays short; hosting, environment variables and gotchas load with the code or server files they describe project-management.mdfiling, grooming or picking up work (the project-trackingskill already points to it)Choose the mechanism by test, and record the result here. Candidates: (a) a
.claude/rules/<name>.mdwithpaths:whose body brings in the guideline; (b) instruction files in subfolders, which Claude Code and Codex both read when working there; (c) a skill withpaths:. For each, in a fresh session: does the guideline's text enter the context when a matching file is opened, and stay out when it isn't? Note how Codex reaches the same text.Keep must-hold rules enforced. A rule that is loaded less often is followed less often. The guard rails already list what lint and CI enforce. Any rule that is prose only and needed on every change stays in the always-loaded set.
Guard the budget. A small script counts the lines loaded at session start (
CLAUDE.mdand everything it imports), and CI fails when the count goes over the budget.Nothing is lost. The PR has a table: each file, how it is reached now, and the test that showed it.
Acceptance criteria
- Not done: A session start loads at most 300 lines (
CLAUDE.mdplus its imports), down from 1,651, measured by the script, with the output in the PR. - Not done:
AGENTS.mdis at most 200 lines and still holds the workflow, the Never list and the map of where things are. - Not done: Each of the ten files is reached by a documented trigger, and the PR's table shows the test result for each.
- Not done: The test results for Claude Code are recorded on this issue (a session that opens a
cms/file has the Payload guideline in context; a docs-only session doesn't), with a note on Codex. - Not done: CI fails when the always-loaded set grows past the budget.
- Not done: No rule, procedure or fact lives only in
.claude/(tool adapters, opens in a new tab). - Not done: No instruction file is over 250 lines.
- Not done: The review lists this as a policy change the owner asked for (summary of his direction, 2026-11-06, Claude session, text: reduce what is sent on every prompt and optimize the skills and rules).
Files likely touched
CLAUDE.md, AGENTS.md, .claude/rules/ (new, if the test picks it), .claude/settings.json, docs/project.md, docs/guidelines/README.md, .agents/skills/*/SKILL.md (pointers only), scripts/ (the budget check), .github/workflows/lint.yml or ci.yml.
Must not touch
src/. What the guidelines say (this changes how they load, not their rules). docs/process/agent-operating-model.md.
Open questions
None for the owner.
Depends on
Nothing open. #142 (architecture docs), which the earlier version waited for, is done.
Area
tooling
Priority
high
Generated by Claude Code, opens in a new tab