Agent skill · research science · aiskillstore

context-window-management

Strategies for managing LLM context windows including

Why this skill is useful

Provides specific strategies and code snippets for optimizing LLM context management that are not commonly known.

What it needs

Requires langchain, tiktoken installed locally. About 4k tokens when loaded. Last updated 2026-08-07. 405 stars on the source repository.

What this skill does

Context Window Management Strategies for managing LLM context windows including summarization, trimming, routing, and avoiding context rot Capabilities context-engineering context-summarization context-trimming context-routing token-counting context-prioritization Prerequisites Knowledge: LLM fundamentals, Tokenization basics, Prompt engineering Skillsrecommended: prompt-engineering Scope Doesnotcover: RAG implementation details, Model fine-tuning, Embedding models Boundaries: Focus is context optimization, Covers strategies not specific implementations Ecosystem Primarytools tiktoken - OpenAI's tokenizer for counting tokens LangChain - Framework with context management utilities Claude API - 200K+ context with caching support Patterns Tiered Context Strategy Different strategies based on context size When to use: Building any multi-turn conversation system interface ContextTier { maxTokens: number; strategy: 'full' 'summarize' 'rag'; model: string; } const TIERS: ContextTier[] = [ { maxTokens: 8000, strategy: 'full', model: 'claude-3-haiku' }, { maxTokens: 32000, strategy: 'full', model: 'claude-3-5-sonnet' }, { maxTokens: 100000, strategy: 'summarize', model: 'claude-3-5-sonnet' }, { maxTokens: Infinity, strategy: 'rag', model: 'claude-3-5-sonnet' } ]; async function selectStrategy(messages: Message[]): ContextTier { const tokens = await countTokens(messages); for (const tier of TIERS) { if (tokens <= tier.maxTokens) { return tier; } } return TIERS[TIERS.length - 1]; } async function prepareContext(messages: Message[]): PreparedContext { const tier = await selectStrategy(messages); switch (tier.strategy) { case 'full': return { messages, model: tier.model }; case 'summarize': const summary = await summarizeOldMessages(messages); return { messages: [summary, ...recentMessages(messages)], model: tier.model }; case 'rag': const relevant = await retrieveRelevant(messages); return { messages: [...relevant, ...recentMessages(messages)], model: tier.model }; } } Serial P …

How to use it

Reference it in AdaL, Claude Code, Cursor or any coding agent — nothing to install:

@skills aiskillstore/context-window-management

View the source on GitHub

Browse the @skills marketplace