context-optimization
Skill27 starsChanged 3 months agoApache-2.0View on GitHub
Use when optimizing token usage, KV cache efficiency, or context window management for LLM agents. Keywords: context optimization, KV cache, prompt caching, token budget, semantic pruning, lost-in-the-middle.
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
- muratcankoylan/Agent-Skills-for-Context-Engineeringtheir own version, first seen Aug 10, 2026
- Fandry96/k3-agentic-skillstheir own version, first seen May 12, 2026
- JubaKitiashvili/context-memtheir own version, first seen Apr 17, 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
- 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
- VersoXBT/claude-initial-setup★ 4same 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 repository163 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- agent-memorySkill
- claukitSkill
- mcp-agent-patternsSkill
- multi-agent-orchestrationSkill
- workflow-state-machinesSkill
- ai-multimodalSkill
- geo-fundamentalsSkill
- media-processingSkill
- screenshotSkill
- seo-fundamentalsSkill
- soraSkill
- aestheticSkill
- figma-implement-designSkill
- figmaSkill
- frontend-designSkill
- mobile-designSkill
- tailwind-patternsSkill
- ui-stylingSkill
- agentic-ragSkill
- api-patternsSkill
- app-builderSkill
- architectureSkill
- ask-mattSkill
- aspnet-coreSkill
- backend-developmentSkill
- better-authSkill
- clean-codeSkill
- code-agent-patternsSkill
- codebase-designSkill
- code-review-checklistSkill
- code-reviewSkill
- context-engineeringSkill
- database-designSkill
- databasesSkill
- diagnoseSkill
- diagnosing-bugsSkill
- docs-seekerSkill
- domain-modelingSkill
- frontend-dev-guidelinesSkill
- graph-ragSkill
- i18n-localizationSkill
- implementSkill
- improve-codebase-architectureSkill
- lint-and-validateSkill
- llm-evalsSkill
- nextjs-best-practicesSkill
- nodejs-best-practicesSkill
- openai-docsSkill
- performance-profilingSkill
- playwright-interactiveSkill
- playwrightSkill
- prompt-engineeringSkill
- prototypeSkill
- python-patternsSkill
- react-patternsSkill
- render-deploySkill
- repomixSkill
- researchSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
7 rules. 0 are common, 7 are distinctive, and 0 are very specific to this project.
0
Common
Most of the 13 edited versions we read keep these.
7
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 26
Whitespace Stripping: Use minification for configuration files (JSON, YAML) and standard code.
- Distinctive: line 33
Boundary Priority: Place high-priority constraints, critical instructions, and schema definitions at the very beginning (Head) or the very …
- Distinctive: line 34
Sandwich Strategy: If critical information must be in the middle, sandwich it between two clear, high-level summary points that repeat its …
- Distinctive: line 40
Sliding Window: Keep only the N most recent turns for immediate interaction.
- Distinctive: line 59
Summarize: When history exceeds 50% of the token budget and requires long-term context.
- Distinctive: line 60
Truncate: When history is irrelevant to the current task or contains repetitive technical noise.
- Distinctive: line 61
Archive: When information must be preserved (e.g., decisions, ADRs) but is not needed for the immediate turn.
“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 Skill
This skill provides methodologies and best practices for maximizing context window efficiency, reducing token costs, and improving the performance of LLM-based agentic workflows.
1. Prompt Cache Alignment
To maximize Key-Value (KV) cache hits, prioritize stability in the early parts of the prompt.
- Static Prefixes: Design system prompts to remain identical across agent turns.
- Tool Order: Sort tool definitions alphabetically or by frequency of use. Keep this ordering constant.
- Prefix Consistency: Reserve the top 70% of the KV cache for global system instructions and tool definitions.
- Avoid Dynamic Data: Move dynamic session-specific data (dates, current file list) to the end of the context window.
2. Semantic Pruning & AST Compaction
Reduce unnecessary data before sending it to the model.
- Removal of Non-Essentials: Strip comments, debug logs, and unused boilerplate code.
- AST Compaction: Convert deep code structures into simplified, representative summaries or pseudocode.
- Whitespace Stripping: Use minification for configuration files (JSON, YAML) and standard code.
- Irrelevant Body Dropping: Replace large, irrelevant function bodies with docstrings or signatures if the model doesn't need to reason about the implementation details.
3. Lost-in-the-Middle Mitigation
LLMs often suffer from recall degradation for information in the center of the context window.
- Boundary Priority: Place high-priority constraints, critical instructions, and schema definitions at the very beginning (Head) or the very end (Tail) of the context.
- Sandwich Strategy: If critical information must be in the middle, sandwich it between two clear, high-level summary points that repeat its purpose.
4. Sliding Windows & Recursive Summarization
Manage long-running conversations without exceeding token thresholds.
- Sliding Window: Keep only the N most recent turns for immediate interaction.
- Recursive Summarization: Periodically collapse historical turns into a compressed "Session State Summary".
- State Archiving: Store older, less relevant interactions in a side-car file (e.g.,
archive.md) that the agent can read only when necessary.
5. Token Budget Allocation
Implement a disciplined token distribution:
| Category | Typical % | Goal |
| System Prompt | 10-15% | Definition of role & constraints |
| Tool Definitions | 15-20% | Capability exposure |
| Interaction History | 30-40% | Context for current turn |
| Reserved (Drafting) | 25-45% | Headroom for generation |
6. Context Freshness Decisions
Determine when to act on history:
- Summarize: When history exceeds 50% of the token budget and requires long-term context.
- Truncate: When history is irrelevant to the current task or contains repetitive technical noise.
- Archive: When information must be preserved (e.g., decisions, ADRs) but is not needed for the immediate turn.
7. Measuring Cache Hit Rate
Continuous improvement relies on telemetry.
- Monitoring: Track Cache Hit Rate (CHR) metrics provided by the API provider.
- Iteration: Analyze sessions with low CHR. Are the system prompts shifting? Is tool definition order inconsistent?
- Optimization Loop:
- Measure performance per turn.
- Identify volatility in the prefix.
- Refactor static content to improve cache stability.
- Re-measure.
Best Practices Checklist
- Does my system prompt remain stable across requests?
- Are tools sorted consistently?
- Is critical information pinned to the Head or Tail?
- Have I pruned unused code/data from the ingestion stream?
- Is there an automated summarization step for history?
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.

