context-engineering
Skill33 starsChanged 22 days agoMITView on GitHub
Use when managing what an LLM sees. Covers context-window budgeting, retrieval and compaction, memory across turns, tool-result pruning, and the failure modes that come from too much context rather than too little. Trigger on "model gets worse as the conversation gets longer", "context window keeps filling up". Do not use for state that persists across sessions — see the agent-memory skill; for retrieval over a document corpus, see the rag skill.
We split this skill into the rules it gives an agent
1 rule. 0 are common, 1 is distinctive, and 0 are very specific to this project.
0
Common
Most of the 113 edited versions we read keep these.
1
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 59
Write important state to a file.
“Common” is measured: kept by at least 6 in 10 of the 113 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
Purpose
Decide what an LLM sees, and what it does not. Context is a finite budget with a nonlinear cost curve: more context is not more capability, and past a point it is actively less.
When to Use
- Building an agent or assistant that runs over many turns.
- A model that performs worse as the conversation gets longer.
- Managing tool results, retrieved documents, or long files.
- Reducing token cost in a long-running system.
Capabilities
- Context budgeting and allocation.
- Retrieval: putting the right thing in, not everything.
- Compaction and summarization of history.
- Memory: what persists across sessions, and in what form.
- Tool-result pruning and progressive disclosure.
Inputs
- The task, and what information it genuinely requires.
- The context window and its cost.
- The failure symptom, if the system is degrading over long runs.
Outputs
- A context budget with an allocation per component.
- A compaction strategy that preserves what matters.
- Measurably better performance on long tasks.
Workflow
- Budget the window explicitly — System prompt, tools, retrieved context, history, and the response all compete for the same space. Decide the allocation rather than letting history consume everything.
- Retrieve narrowly — Ten highly relevant chunks outperform a hundred marginally relevant ones. Irrelevant context does not sit inertly; it distracts.
- Compact, do not truncate — Dropping the oldest turns loses the decisions that explain the current state. Summarize the history into the facts and decisions that are still live.
- Prune tool results — A tool returning 50 KB of JSON when the agent needs three fields is spending the budget on noise. Filter at the tool boundary.
- Disclose progressively — Provide a file listing, not the files. Let the model request what it actually needs. This is how a large codebase fits in a small window.
- Externalize memory — Long-lived state belongs in a file or a store the model can read and write, not in a conversation history that grows without bound.
Best Practices
- Long context degrades attention. A model given 200,000 tokens of context often performs worse than the same model given the 5,000 tokens that mattered. Adding context is not free.
- Information in the middle of a long context is attended to least. Put the critical instruction at the start or the end, not buried in the middle.
- Compaction is lossy by design. Preserve the decisions, the constraints, and the unresolved questions; discard the exploration that led to them.
- A tool that returns raw API output is a context leak. Wrap it, select the fields, and return a summary with a way to fetch the detail.
- Cache the stable prefix. A system prompt and tool definitions that do not change should be cached rather than re-sent and re-processed each turn.
- Write important state to a file. A note the model writes and re-reads survives compaction; a fact buried in turn 12 does not.
Examples
Explicit context budget:
Window: 200,000 tokens. Allocation:
System prompt + skill 4,000 stable, cached
Tool definitions 3,000 stable, cached
Working memory file 2,000 the agent's own notes, re-read each turn
Retrieved context 20,000 top-k, re-retrieved per turn, not accumulated
Conversation history 40,000 compacted when it exceeds this
Tool results 30,000 pruned; only the most recent kept in full
Reserve for response 16,000
--------
115,000 leaving deliberate headroom
Rules:
- History exceeding 40k triggers compaction, not truncation.
- Retrieved context is replaced each turn, never appended — otherwise it
grows monotonically and crowds out everything else.
- Tool results older than 3 turns are replaced by a one-line summary.Compaction that preserves what matters:
COMPACTION_PROMPT = """\
Summarize the conversation so far into a working state document. This summary
replaces the full history, so anything you omit is lost permanently.
Preserve:
- The user's goal and any constraints they stated.
- Decisions made, and the reason for each.
- Facts discovered (file paths, API shapes, error messages, values).
- What has been tried and failed, so it is not retried.
- Open questions and the current next step.
Discard:
- Exploration that led nowhere.
- Full file contents (keep the path and what was learned from it).
- Tool call mechanics and intermediate output.
Write it as a factual state document, not a narrative."""Progressive disclosure instead of loading everything:
# Wrong: 400 files, 2M tokens, does not fit and would not help if it did.
context = "\n".join(read(f) for f in repo.all_files())
# Right: give the model a map, and a tool to fetch what it decides it needs.
context = repo.tree(max_depth=3) # ~2,000 tokens
tools = [read_file, grep, list_directory] # the model pulls what it needsNotes
- The "lost in the middle" effect is well-documented: retrieval accuracy for a fact placed in the middle of a long context is substantially lower than for the same fact at either end. Placement is not neutral.
- Prompt caching makes a large stable prefix cheap after the first call. It changes the economics of a long system prompt entirely — but only if the prefix is genuinely stable, byte for byte.
- The instinct to give the model more context is usually wrong. The instinct to give it better context is usually right.
Other versions126 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 126
- 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
- liza-mas/liza★ 414same name
- typv/nest-turbo-starter★ 224same name
- VAMFI/claude-user-memory★ 206same name
- shashankswe2020-ux/whoop-mcp★ 174same name
116 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 repository137 other files it gives its agents.
- agent-instructionsSkill
- agent-memorySkill
- hooksSkill
- plugin-developmentSkill
- skill-authoringSkill
- skill-reviewSkill
- slash-commandsSkill
- subagentsSkill
- agent-designSkill
- fine-tuningSkill
- llm-cost-optimizationSkill
- llm-evaluationSkill
- llm-integrationSkill
- mcp-serverSkill
- ml-pipelineSkill
- model-selectionSkill
- prompt-engineeringSkill
- ragSkill
- structured-outputSkill
- api-designSkill
- background-jobsSkill
- cachingSkill
- djangoSkill
- event-driven-architectureSkill
- fastapiSkill
- graphqlSkill
- microservicesSkill
- nestjsSkill
- realtime-websocketsSkill
- spring-bootSkill
- competitive-analysisSkill
- lead-researchSkill
- product-analysisSkill
- resumeSkill
- user-researchSkill
- database-performanceSkill
- data-modelingSkill
- data-qualitySkill
- pandasSkill
- postgresSkill
- sparkSkill
- brand-guidelinesSkill
- generative-artSkill
- themingSkill
- ui-reviewSkill
- visual-designSkill
- architecture-decisionsSkill
- bug-fix-protocolSkill
- cli-developmentSkill
- code-reviewSkill
- debuggingSkill
- design-patternsSkill
- domain-modelingSkill
- git-workflowSkill
- legacy-modernizationSkill
- refactoringSkill
- repository-explorationSkill
- simple-designSkill
- system-designSkill
- aws-cdkSkill
- The first 60 shown.
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.

