context-engineering
Skill36 starsChanged 6 days agoMITView on GitHub
How to budget and structure what a coding agent sees. Use when asked to trim, split or write AGENTS.md, CLAUDE.md, rules files or skill descriptions (for example 'CLAUDE.md is too long'), when an agent ignores instructions, forgets rules or drifts in long sessions, and when planning compaction or progress notes.
We split this skill into the rules it gives an agent
6 rules. 0 are common, 6 are distinctive, and 0 are very specific to this project.
0
Common
Most of the 112 edited versions we read keep these.
6
Distinctive
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 25
Use the cheapest layer that still loads when the agent needs the content.
- Distinctive: line 107
Put the most important instructions at the top of any file that gets re-injected.
- Distinctive: line 110
Keep rules that must survive in always-on files.
- Distinctive: line 112
Do not rely on chat history for decisions.
- Distinctive: line 120
Ask for a condensed answer with file paths and line numbers, so the main agent can verify.
- Distinctive: line 122
Do not use one for work that needs the main conversation's context or for a three-file lookup you can do directly.
“Common” is measured: kept by at least 6 in 10 of the 112 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Context engineering
An agent's context window is a budget, not storage: reliability falls as the window fills (context rot). Give the agent the smallest set of high-signal tokens for the step it is on, and load everything else only when needed. Each line in an always-loaded file must change behavior, and a rule that must always hold belongs in a hook, linter or test, not text. Add a context file only for a failure you have seen.
Evidence that more context can hurt
| Source | Finding |
| ETH Zurich and LogicStar, arXiv 2602.11988 (2026) | Repository context files did not generally improve task success and raised inference cost by more than 20% on average, for both generated and developer-written files. Agents followed specific instructions, but repository overviews did not help. Useful for non-standard practices. |
| Vercel, AGENTS.md outperforms skills (2026-01-27) | On framework-API tasks, a passive 8 KB docs index in AGENTS.md passed 100%. Skills left on default behavior passed 53% (same as no docs) because the agent never invoked them in 56% of cases. |
| Chroma, context rot | Model reliability drops as input length grows, even on simple tasks. |
| Thoughtworks Radar vol. 34 (2026-04) | Adopt context engineering and curated shared instructions. Caution on agent instruction bloat. |
Read these together. Vercel's result is not "skills are bad". It says knowledge the agent needs on nearly every task belongs in always-on context as a compact index, and skills fit explicit, user-triggered workflows. ETH's result says the always-on file must stay short and specific. The two agree: put little in always-on context, and make all of it count.
What goes where
Use the cheapest layer that still loads when the agent needs the content. Full decision table and examples are in placement-guide.
| Layer | Loads | Put here |
| Always-on file (AGENTS.md, CLAUDE.md, GEMINI.md, copilot-instructions.md) | Every session | Build, test and lint commands. Non-obvious conventions. Hard prohibitions. Pointers to deeper docs. |
Path-scoped rules (.claude/rules/ with paths:, .cursor/rules, Copilot .github/instructions/) | When matching files are touched | Rules for one language, directory or file type. |
| Nested instruction files in subdirectories | When the agent works there | Rules for one package or service in a monorepo. |
| Skills | Description always, body when invoked | Repeatable workflows and reference material the agent should pull in on a trigger. |
On-demand docs (docs/, ADRs, runbooks) | When the agent reads them | Architecture, history, long procedures, API detail. |
| Hooks, linters, CI, tests | Every time the event fires | Rules that must never be skipped. |
| Tool output | When a command runs | Facts the agent can discover itself. Do not copy these into instruction files. |
Size budgets
| Item | Budget | Notes |
| CLAUDE.md | Under about 200 lines per file | Anthropic guidance. Longer files reduce adherence. Imports with @path organize a file but do not reduce cost, because imported files also load at launch (memory docs). |
| Codex AGENTS.md chain | 32 KiB combined (project_doc_max_bytes) | Codex stops adding files once the limit is reached, so deep files can be silently left out. Raise the setting or split into nested directories (Codex docs). |
| Claude Code skill listing | 1% of the context window, scaled with the model | Overflow drops descriptions of the least-used skills first. Raise with skillListingBudgetFraction (for example 0.02) or a fixed character count via SLASH_COMMAND_TOOL_CHAR_BUDGET. Set rarely used personal or project skills to "name-only" in skillOverrides (plugin skills are managed through /plugin instead). |
| One skill entry | 1,536 characters for description plus when_to_use | Configurable with skillListingMaxDescChars. Put the key use case first. Aim for 200 to 400 characters (skills docs). |
| Skill body | Under 500 lines, key rules at the top | After compaction only the first 5,000 tokens of each invoked skill return, with 25,000 tokens shared across skills (context window docs). |
Other tools have their own caps and defaults. Check the vendor docs for the tool in use before assuming these numbers carry over. Use /context in Claude Code for a live breakdown, and /doctor prompt-audit to find outdated or conflicting instruction files.
Signs of instruction bloat
- The agent ignores a rule that is clearly written. Often a longer file buried it.
- The same rule appears in two files, or in the file and in a linter config.
- Rules that explain things the agent can see: directory trees, tech stack lists, a README summary.
- Rules written for an older model ("think step by step", "be careful") or for a tool the team dropped.
- Two files that disagree (one says tabs, the other spaces).
- Style rules a formatter already enforces.
- Rules for one package that load for the whole repository.
- Emphasis inflation: many lines marked IMPORTANT, NEVER or CRITICAL. When everything shouts, nothing stands out.
- A rule that exists because of an old incident nobody remembers.
- A skill routing table ("When X, use /skill") or an agent roster copied into the instruction file. Every skill and agent description already carries its trigger and reaches the model on its own, so the copy only adds size and goes stale. Entries for skills that are not installed point nowhere. Replace the table with one generic line ("Before acting, check the available skills and invoke any whose description matches the task") plus rules for the few skills that need a custom trigger, each checked against the installed set.
- The same project rules in both
AGENTS.mdandCLAUDE.md, or in a tool file and a global file. Keep one copy and import or point to it.
Fix by deleting first, then moving, then rewriting. For each line ask: what mistake would the agent make without this? If the answer is "none", delete it. For wording of the lines that stay (one word per concept, positive phrasing, a project glossary), see writing-levers.
Skill listing overflow
Agents load every skill name and description into context each turn, within a fixed budget. With many installed skills the budget runs out.
| Symptoms | Skills appear as bare names with no description. Skills that should match a request are never picked. The agent does the work itself instead of invoking the skill. |
| Why | In Claude Code the listing is capped at 1% of the context window and 1,536 characters per skill. Past the cap, descriptions of the least-used skills are dropped first. The name stays, but the trigger text the agent matches against is gone. |
| Diagnose | /context shows the Skills row, sized after the budget is applied. /doctor estimates the listing's cost and biggest contributors. /skill-doctor (Claude Code 2.1.252 or later) shows each skill's cost and how often it is invoked. Count installed skills: user, project, and plugin caches. A warning also goes to the debug log (--debug). |
| Fix | Disable unused plugins and skills (/plugin for plugin skills). Set low-value personal or project skills to "name-only" or "off" in skillOverrides, or mark them disable-model-invocation: true and invoke them by name. Trim descriptions and put the key use case first. As a last step, raise the budget with skillListingBudgetFraction (for example 0.02) or SLASH_COMMAND_TOOL_CHAR_BUDGET, which spends more context on every turn. |
Sources: skills docs, descriptions are cut short, override skill visibility, settings reference. Other tools cap their listings differently, so check their docs.
Instruction drift
Always-on instruction files load once at session start. As the conversation grows with file reads and tool output, they make up a smaller share of what the agent sees, and rules from early in the session are followed less (see context rot above). Symptoms: the agent follows the file for the first prompts, then stops using a convention, a persona, or a prohibition.
| Fix | How |
| Keep the file short and rules-only | A short file holds a larger share of attention. No overviews, no skill tables, no copies. Target under about 200 lines for CLAUDE.md. |
| Remind on every prompt | A UserPromptSubmit hook runs before each prompt, and its plain-text output is added as context the model can see (hooks reference). Have it print two or three rules that keep failing. Keep it to a few lines, since it costs tokens each turn. Setup is in the hooks-and-guardrails skill. |
| Enforce what must hold | Move must-never-fail rules to hooks, linters, or tests. |
| One session per task | Start a clean session (/clear) between unrelated tasks. |
| Compact with a focus | /compact focus on ... between phases. Project-root CLAUDE.md is re-read from disk after compaction (what survives compaction), but conversation-only instructions and not-yet-reloaded scoped rules are lost. |
One source of truth for instructions
Several tools means several files, and copies drift apart. Write project rules once in AGENTS.md. Claude Code reads AGENTS.md by itself only when no CLAUDE.md exists (v2.1.277 or later). If a CLAUDE.md is needed, make its first line @AGENTS.md and add only Claude-specific lines below. Never paste the same rules into both. The import avoids a second copy, but the imported text still loads at launch, so it does not lower cost (memory docs). For user-level files there is no shared standard: Codex reads ~/.codex/AGENTS.md, and Claude Code documents ~/.claude/CLAUDE.md. Keep each short. See placement-guide.
Signs of context rot in a session
- The agent repeats a question you already answered or redoes finished work.
- It forgets a constraint stated early in the session.
- Quality drops after many large file reads or long tool outputs.
- It cites files or functions that do not exist.
Respond by compacting with a focus, writing state to a file, or starting a clean session, in that order of effort. Do not keep pushing in a degraded window.
Compaction hygiene
Compaction replaces history with a summary. Plan for what it keeps and drops. Details and a notes template are in long-task-notes.
- Put the most important instructions at the top of any file that gets re-injected. Truncation keeps the start.
- Compact on your own schedule, between phases, with a focus:
/compact focus on the auth bug and the failing test list. The automatic pass guesses what matters. - Clear between unrelated tasks (
/clear). Old conversation crowds out the files you need next and costs tokens on every message. - Keep rules that must survive in always-on files. Path-scoped rules and nested files load into message history, so a compaction summary can drop them until the agent touches a matching file again.
- Re-invoke a skill after compaction if the task depends on its full text.
- Do not rely on chat history for decisions. Write them to a file.
Other agents compact differently. Check the tool's docs for what survives.
Offload big reads to subagents
A subagent works in its own window. It may read tens of thousands of tokens and return a summary of about 1,000 to 2,000 tokens. Use one when the answer is small but the search is large: tracing a code path, auditing a directory, reading a long log, comparing many files.
- Ask for a condensed answer with file paths and line numbers, so the main agent can verify.
- Give the subagent a narrow question and the files to start from.
- Do not use one for work that needs the main conversation's context or for a three-file lookup you can do directly.
Long tasks
For work that spans many sessions or compactions, keep a progress file and a task list in the repository, update them at each step, and begin every session by reading them. See long-task-notes for the file layouts, the one-feature-per-session pattern, and handoff notes.
Reference Files
| Reference | Contents |
| placement-guide | Decision flow for where each kind of instruction goes, per-tool file names and scoping, before and after examples, migration steps |
| long-task-notes | Progress file and task list layouts, one-feature-per-session pattern, handoff notes, compaction checklist |
| writing-levers | Leading words, positive phrasing instead of prohibitions, the no-op test, project glossary with Avoid lists |
Other versions123 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 123
- addyosmani/agent-skills★ 112ksame name
- bojieli/ai-agent-book-projects★ 53ksame name
- bojieli/ai-agent-book★ 53ksame name
- rohitg00/pro-workflow★ 2.9ksame name
- mrgoonie/claudekit-skills★ 2.2ksame name
- kdlbs/kandev★ 1ksame name
- rizqinrr/viserys-agent★ 556same name
- liza-mas/liza★ 409same name
- typv/nest-turbo-starter★ 224same name
- VAMFI/claude-user-memory★ 206same name
113 more not listed
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
Used alongsideProjects with it also use using-agent-skills, constraint-driven-development and 10 more.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
LLl0k0laDSkillusing-agent-skills
Use when starting a session or when you need to discover which skill applies to the current task. This is the meta-skill that governs how all other skills are discovered and invoked.
Also in 35 projects that use this
MrCipherSmithSkillconstraint-driven-development
Use when a project needs a persistent, measurable quality bar — starting a project without documented standards, 'set up constraints', or when coverage/perf/a11y thresholds get re-debated per-PR. Produces CONSTRAINTS.md with enforceable numbers, ratchets, and a guard against silent weakening. NOT for throwaway prototypes or a one-off CI setup.
Also in 12 projects that use this
HK-hubSkilldeprecation-and-migration
Manages deprecation and migration. Use when removing old systems, APIs, or features. Use when migrating users from one implementation to another. Use when deciding whether to maintain or sunset existing code.
Also in 38 projects that use this
LLl0k0laDSkillgit-workflow-and-versioning
Use when making any code change. Use when committing, branching, resolving conflicts, or when you need to organize work across multiple parallel streams.
Also in 40 projects that use this
HK-hubSkillsource-driven-development
Grounds every implementation decision in official documentation. Use when you want authoritative, source-cited code free from outdated patterns. Use when building with any framework or library where correctness matters.
Also in 41 projects that use this
- +6 more from LLl0k0laD
- +1 more from HK-hub
In this repository38 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- llm-evalsSkill
- llm-observabilitySkill
- accessibilitySkill
- debuggingSkill
- docs-lookupSkill
- performanceSkill
- securitySkill
- verification-before-completionSkill
- finishing-branchSkill
- game-feature-loopSkill
- handoffSkill
- hooks-and-guardrailsSkill
- pr-feedbackSkill
- security-researchSkill
- spec-driven-developmentSkill
- tddSkill
- agent-creatorSkill
- agentic-rules-writerSkill
- audit-dependenciesSkill
- brainstormingSkill
- communication-styleSkill
- find-test-gapsSkill
- plan-migrationSkill
- plugin-creatorSkill
- pr-message-writerSkill
- report-writerSkill
- researchSkill
- review-pr-coldSkill
- review-prSkill
- scan-refactorsSkill
- skill-creatorSkill
- skill-measureSkill
- stakeholder-update-writerSkill
- ticket-writerSkill
- ui-reviewSkill
- verify-acceptanceSkill
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
Reviews can't be read right now.
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.

