context-optimization
Skill4 starsChanged 9 months agoMITView on GitHub
Strategies for managing Claude Code's context window efficiently: token budgeting, progressive disclosure, reference files, and using subagents to protect context. Use when conversations are getting long, the user mentions context limits, or tasks involve reading many files.
14 other projects use a version of this.
Adopted by
Most recently taken up by
- AbdullahMalik17/Digital-FTEtheir own version, first seen Sep 26, 2026
- SkotAlexsander/skillstheir own version, first seen Sep 16, 2026
- docxology/templatetheir own version, first seen Aug 29, 2026
- VoDaiLocz/kilo-kit-mcptheir own version, first seen Aug 21, 2026
- muratcankoylan/Agent-Skills-for-Context-Engineeringtheir own version, first seen Aug 10, 2026
- Fandry96/k3-agentic-skillstheir own version, first seen May 12, 2026
Used with
Projects with it also use bdi-mental-states, filesystem-context 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.
Downey6689Skillbdi-mental-states
Transforms external RDF context into BDI mental states. Invoke when modeling beliefs, desires, and intentions.
Also in 4 projects that use this
Downey6689Skillfilesystem-context
Uses filesystem for dynamic context discovery. Invoke when organizing docs or loading information just-in-time.
Also in 4 projects that use this
AbdullahMalik17Skillconfiguring-dapr-pubsub
Configures Dapr pub/sub components for event-driven microservices with Kafka or Redis. Use when wiring agent-to-agent communication, setting up event subscriptions, or integrating Dapr sidecars. Covers component configuration, subscription patterns, publishing events, and Kubernetes deployment. NOT when using direct Kafka clients or non-Dapr messaging patterns.
Also in 3 projects that use this
AbdullahMalik17Skillcontainerizing-applications
Containerizes applications with Docker, docker-compose, and Helm charts. Use when creating Dockerfiles, docker-compose configurations, or Helm charts for Kubernetes. Includes Docker Hardened Images (95% fewer CVEs), multi-stage builds, and 15+ battle-tested gotchas.
Also in 3 projects that use this
xfstudioSkillconversation-memory
Persistent memory systems for LLM conversations including short-term, long-term, and entity-based memory Use when: conversation memory, remember, memory persistence, long-term memory, chat history.
Also in 3 projects that use this
muratcankoylanSkilllong-horizon-prompting
This skill should be used when writing, enhancing, or evaluating the launch prompt for a long-running autonomous agent or a parallel multi-agent orchestration attacking a hard problem: pseudo-formal task briefs that define terms and an exact success predicate linguistically, enumerate non-counting outcomes, set persistence rules with explicit stop and return conditions and effort floors, manage a diverse portfolio of parallel approaches with an approach registry and blocked-route bookkeeping, and gate the return on adversarial audit. Route agent topology and coordination protocols to multi-agent-patterns, runtime control surfaces and loop governance to harness-engineering, evaluator and quality-gate construction to evaluation, judge design to advanced-evaluation, and compaction or memory mechanics to context-compression and memory-systems.
Also in 3 projects that use this
- +6 more from AbdullahMalik17
Other versions14 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 14
- muratcankoylan/Agent-Skills-for-Context-Engineering★ 18ksame name
- Fandry96/k3-agentic-skills★ 27same name
- VoDaiLocz/kilo-kit-mcp★ 27same name
- docxology/template★ 20same name
- JubaKitiashvili/context-mem★ 19same name
- AbdullahMalik17/Digital-FTE★ 12same name
- AbdullahMalik17/Hacathan_5★ 9same name
- AbdullahMalik17/My_skills★ 9same name
- xfstudio/skills★ 9same name
- rohunvora/my-claude-skills★ 6same name
4 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.
In this repository78 other files it gives its agents.
- AGENTS.mdAGENTS.md
- rules/agents.mdAGENTS.md
- .github/copilot-instructions.mdCopilot instructions
- .cursor/rules/claude-initial-setup.mdcCursor rule
- parallel-task-executionSkill
- subagent-patternsSkill
- task-coordinationSkill
- agent-communicationSkill
- context-managementSkill
- multi-agent-orchestrationSkill
- deploy-strategiesSkill
- github-actions-guideSkill
- pipeline-patternsSkill
- anthropic-sdk-guideSkill
- prompt-engineeringSkill
- tool-use-patternsSkill
- automated-review-setupSkill
- pr-standardsSkill
- review-checklistSkill
- file-organizationSkill
- immutability-patternsSkill
- naming-conventionsSkill
- branching-strategySkill
- commit-conventionsSkill
- pr-workflowSkill
- migration-patternsSkill
- query-optimizationSkill
- schema-design-guideSkill
- error-tracingSkill
- log-analysisSkill
- systematic-debuggingSkill
- django-admin-customizationSkill
- django-orm-masterySkill
- drf-api-patternsSkill
- docker-compose-guideSkill
- dockerfile-best-practicesSkill
- multi-stage-buildsSkill
- express-error-handlingSkill
- middleware-patternsSkill
- rest-api-nodeSkill
- async-fastapiSkill
- dependency-injection-fastapiSkill
- pydantic-validationSkill
- concurrency-patterns-goSkill
- error-handling-goSkill
- idiomatic-goSkill
- automation-triggersSkill
- hook-recipesSkill
- pre-post-hooksSkill
- junit-testingSkill
- maven-gradle-guideSkill
- spring-boot-patternsSkill
- mcp-resource-patternsSkill
- mcp-server-creationSkill
- mcp-tool-designSkill
- knowledge-persistenceSkill
- memory-patternsSkill
- caching-strategiesSkill
- lazy-loading-patternsSkill
- profiling-guideSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
8 rules. 0 are common, 8 are distinctive, and 0 are very specific to this project.
0
Common
Most of the 13 edited versions we read keep these.
8
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 44
Start with structure, then drill into details:
- Distinctive: line 60
Do not read all source files upfront.
- Distinctive: line 64
When a file's contents have been read and discussed, refer to it by path and line number instead of quoting large blocks:
- Distinctive: line 77
Use subagents when exploration would consume too much main context:
- Distinctive: line 99
Use Grep to locate exactly what you need before reading entire files:
- Distinctive: line 153
Reading everything upfront: Do not read all project files at the start of a session.
- Distinctive: line 156
Repeating tool calls: If you already read a file earlier in the session, do not read it again.
- Distinctive: line 170
Rule: Read only what you need, when you need it.
“Common” is measured: kept by at least 6 in 10 of the 13 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 Optimization
Claude Code's context window is finite. Efficient use of context enables longer sessions, larger refactors, and deeper analysis without hitting limits or losing important earlier information.
When to Use
- Conversation is approaching context limits (system may compress earlier messages)
- Task requires reading many large files
- User mentions running out of context or losing earlier information
- Planning a large refactoring or multi-file implementation
- Deciding whether to use subagents vs direct tool calls
Core Patterns
Token Budgeting
Estimate context costs before reading files:
Small file (< 100 lines): ~500-1000 tokens -- Read freely
Medium file (100-500 lines): ~1000-5000 tokens -- Read if needed
Large file (500+ lines): ~5000+ tokens -- Use offset/limit or subagentFor large files, read only the relevant section:
Read:
file_path: "src/services/auth.ts"
offset: 150 # Start at line 150
limit: 50 # Read only 50 linesProgressive Disclosure
Start with structure, then drill into details:
# Step 1: Understand the project structure (cheap)
Glob: "src/**/*.ts"
# Step 2: Find the relevant area (cheap)
Grep: pattern "export function authenticate"
# Step 3: Read only the relevant file (targeted)
Read: "src/middleware/auth.ts"
# Step 4: Read related files only if needed
Read: "src/types/auth.ts"Do not read all source files upfront. Discover what you need, then read it.
Reference Files Instead of Inline Content
When a file's contents have been read and discussed, refer to it by path and line number instead of quoting large blocks:
# EXPENSIVE: Quoting 30 lines of code in your response
"The function at lines 45-75 does X, here is the full code: ..."
# EFFICIENT: Reference by path and line
"The authenticate function at src/middleware/auth.ts:45 handles
token validation. The error branch at line 62 needs updating."Subagents as Context Firewalls
Use subagents when exploration would consume too much main context:
# BAD: Reading 15 files directly into main context
Read: "src/db/users.ts"
Read: "src/db/posts.ts"
Read: "src/db/comments.ts"
... (12 more files)
# GOOD: Delegate to subagent, receive summary only
Agent (Explore):
prompt: "Read all files in src/db/. For each file, report:
1. Table/model name
2. Key query functions
3. Whether it uses parameterized queries
Return a concise table with these columns."The subagent reads all 15 files in its own context. The main context receives only the summary table.
Targeted Grep Before Read
Use Grep to locate exactly what you need before reading entire files:
# Step 1: Find where the function is defined
Grep:
pattern: "export function processPayment"
output_mode: "content"
-C: 3
# Step 2: Read only if you need more context around it
Read:
file_path: "src/services/billing.ts"
offset: 120
limit: 40Context-Sensitive Task Sizing
Match task complexity to remaining context:
High context remaining (early in session):
- Large refactors across multiple files
- Feature implementation spanning many components
- Deep codebase exploration
Low context remaining (late in session):
- Single-file edits
- Independent utility creation
- Simple bug fixes with known location
- Documentation updates
Avoiding Context Waste
Common context wasters to avoid:
# WASTE: Reading a file you will not modify
Read: "package.json" # Just to "check" — only read if you need specific info
# WASTE: Reading the same file twice
Read: "src/app.ts" # Read earlier in session
Read: "src/app.ts" # Reading again because you forgot — check conversation first
# WASTE: Large verbose tool output
Bash: "npm list --all" # Produces hundreds of lines
# Better: "npm list --depth=0" # Top-level only
# WASTE: Reading generated files
Read: "dist/bundle.js" # Generated, not useful
Read: "node_modules/..." # Never read node_modulesAnti-Patterns
- Reading everything upfront: Do not read all project files at the start of a session. Use progressive disclosure — start with structure, drill into specifics.
- Ignoring offset/limit: For large files, always use offset and limit to read only the relevant section. Reading a 2000-line file when you need lines 500-520 wastes context.
- Quoting code back to the user: The user can see the file. Reference by path:line instead of copying 30 lines into your response.
- Repeating tool calls: If you already read a file earlier in the session, do not read it again. Use your conversation history.
- Using verbose bash output: Commands like
npm list --all,find / -name "*.ts", orgit logwithout limits dump large amounts of text. Always constrain output with flags or pipes.
Quick Reference
| Strategy | When | How |
| Progressive disclosure | Starting exploration | Glob -> Grep -> Read (targeted) |
| Offset/limit | Large files | offset: N, limit: M on Read |
| Subagent firewall | Many files to analyze | Agent (Explore) with summary prompt |
| Reference by path | Discussing code | file.ts:line instead of quoting |
| Targeted grep | Finding specific code | Grep with context before Read |
| Output constraints | Bash commands | Use --depth, head, tail, flags |
Rule: Read only what you need, when you need it. Summarize, do not quote.
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.

