Optimizes the context provided to an AI model by deduplicating, filtering, reordering, and scoring information to maximize relevance and token efficiency.
npx skills add https://github.com/seb1n/awesome-ai-agent-skills --skill context-optimization
Context optimization is the process of refining the raw context assembled for an AI model so that every token contributes meaningfully to the task. In a typical RAG or agent pipeline, the retrieved context often contains redundant passages, marginally relevant chunks, and poorly ordered information. Optimization transforms this raw material into a lean, high-signal context block that improves answer quality, reduces inference cost, and makes the most of the model's attention budget.
Provide the raw context (a list of text chunks with optional metadata and scores), the user query, and the target token budget. The skill returns an optimized context block -- deduplicated, filtered, scored, and reordered -- ready for prompt assembly. Optionally provide a coverage checklist (key topics the context must address) to prevent important information from being filtered out.
Task: "Refactor the authentication module to use async/await instead of callbacks."
Raw Context (7 chunks, ~4,200 tokens):
| # | Source | Relevance | Density | Content Summary |
|---|--------|-----------|---------|-----------------|
| 1 | src/auth/login.js:1-45 | 0.93 | High | Login function using callback-based db.findUser() |
| 2 | src/auth/login.js:20-55 | 0.90 | High | Overlapping chunk -- duplicates lines 20-45 of chunk 1, adds token refresh logic |
| 3 | src/auth/middleware.js:1-30 | 0.88 | High | Auth middleware with callback-based token verification |
| 4 | README.md:100-130 | 0.45 | Low | Project setup instructions -- no code, no auth details |
| 5 | src/auth/register.js:1-40 | 0.82 | High | Registration function using callbacks |
| 6 | package.json:1-25 | 0.35 | Low | Dependency list -- no auth-related logic |
| 7 | src/auth/login.js:40-70 | 0.91 | High | Token generation and session creation with callbacks |
Optimization Steps:
login.js.package.json, relevance 0.35) -- below the 0.50 threshold.Optimized Context (~2,800 tokens, 33% reduction):
src/auth/login.js:1-55 (merged) -- Login function with callback-based DB lookup and token refreshsrc/auth/login.js:40-70 -- Token generation and session creationsrc/auth/middleware.js:1-30 -- Auth middleware with callback token verificationsrc/auth/register.js:1-40 -- Registration function using callbacksQuery: "What is the company's return policy for electronics?"
Raw Retrieved Chunks (6 chunks, ~3,000 tokens):
returns-policy.md (score 0.95) -- "Electronics purchased from our store may be returned within 30 days of purchase. Items must be in original packaging with all accessories. A 15% restocking fee applies to opened items."faq.md (score 0.88) -- "Q: Can I return electronics? A: Yes, within 30 days. Items must be in original packaging. A 15% restocking fee applies to opened items. See our returns policy for full details."holiday-policy.md (score 0.72) -- "During the holiday season (Nov 15 - Jan 15), the return window for all products, including electronics, is extended to 60 days. All other conditions apply."shipping-info.md (score 0.40) -- "We ship electronics via insured ground shipping. Delivery takes 3-7 business days."returns-policy.md (score 0.85) -- "Refunds are processed to the original payment method within 5-10 business days. Defective items are exempt from the restocking fee and may be returned within 90 days."store-locator.md (score 0.30) -- "Visit any of our 200 retail locations nationwide."Optimization Steps:
Optimized Context (~900 tokens, 70% reduction):
Integration with protocols.io API for managing scientific protocols. This skill should be used when working with protocols.io to search, create, update, or publish protocols; manage protocol steps and materials; handle discussions and comments; organize workspaces; upload and manage files; or integrate protocols.io functionality into workflows. Applicable for protocol discovery, collaborative protocol development, experiment tracking, lab protocol management, and scientific documentation.
Analyzes job descriptions and generates tailored resumes that highlight relevant experience, skills, and achievements to maximize interview chances
Generate Excalidraw diagrams from natural language descriptions. Use when asked to "create a diagram", "make a flowchart", "visualize a process", "draw a system architecture", "create a mind map", or "generate an Excalidraw file". Supports flowcharts, relationship diagrams, mind maps, and system architecture diagrams. Outputs .excalidraw JSON files that can be opened directly in Excalidraw.
Build and distribute Expo development clients locally or via TestFlight
Use when you have a written implementation plan to execute in a separate session with review checkpoints
Data structure for annotated matrices in single-cell analysis. Use when working with .h5ad files or integrating with the scverse ecosystem. This is the data format skill—for analysis workflows use scanpy; for probabilistic models use scvi-tools; for population-scale queries use cellxgene-census.
Benchling R&D platform integration. Access registry (DNA, proteins), inventory, ELN entries, workflows via API, build Benchling Apps, query Data Warehouse, for lab data management automation.
Comprehensive molecular biology toolkit. Use for sequence manipulation, file parsing (FASTA/GenBank/PDB), phylogenetics, and programmatic NCBI/PubMed access (Bio.Entrez). Best for batch processing, custom bioinformatics pipelines, BLAST automation. For quick lookups use gget; for multi-service integration use bioservices.
Take seb1n/context-optimization from the repository into ~/.claude/skills for personal
use, or into .claude/skills inside a project.
The agent identifies a skill by the name field in its header. Two skills with the
same name cannot sit side by side — one of them will be ignored.