Skip to content
Skillpedia
Agents48k · #2646

context-window-management

Lets your agent manage information space efficiently. It summarizes, trims, or organizes information so the agent doesn't get lost.

What it does

This tool helps the AI manage the amount of information it can 'remember' during a conversation. It uses techniques like summarizing, trimming, or prioritizing what's most important so the AI doesn't get lost in long conversations.

When to use it

  • ✓When you have a very long conversation with the AI and notice it starts forgetting what was said earlier.
  • ✓When building a system where the AI needs to maintain context from many past interactions.
  • ✓When you want to ensure the AI always considers the most important information, even if the conversation is extensive.

Example of what to ask your AI

“How can I make the AI remember important details from a conversation that has already lasted for hours?”

Want more? Open the sections below.

How to use

The easiest way: copy the message below and paste it into Claude, ChatGPT, Cursor or any AI. It reads the skill and follows the instructions.

Skill link

https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/context-window-management/SKILL.md

Ready-to-paste message

Use this skill to help me: https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/context-window-management/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
How it works

The AI analyzes the amount of text it can process at once (called the 'context window'). If the conversation gets too long, it uses strategies to summarize old parts or focus on the most relevant information to continue the conversation efficiently.

Installation

Easiest way: copy the skill link and paste it into Claude, ChatGPT or Cursor asking it to follow the instructions.

In the terminal (Claude Code, Codex, Cursor), in your project folder:

npx skills add sickn33/agentic-awesome-skills --skill context-window-management

Or download just the file:

curl -L https://raw.githubusercontent.com/sickn33/agentic-awesome-skills/main/plugins/agentic-awesome-skills-claude/skills/context-window-management/SKILL.md -o SKILL.md
Technical content (original SKILL.md)

Original text by the author, straight from GitHub.

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
  • Skills_recommended: prompt-engineering

Scope

  • Does_not_cover: RAG implementation details, Model fine-tuning, Embedding models
  • Boundaries: Focus is context optimization, Covers strategies not specific implementations

Ecosystem

Primary_tools

  • 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 Position Optimization

Place important content at start and end

When to use: Constructing prompts with significant context

// LLMs weight beginning and end more heavily
// Structure prompts to leverage this

function buildOptimalPrompt(components: {
    systemPrompt: string;
    criticalContext: string;
    conversationHistory: Message[];
    currentQuery: string;
}): string {
    // START: System instructions (always first)
    const parts = [components.systemPrompt];

    // CRITICAL CONTEXT: Right after system (high primacy)
    if (components.criticalContext) {
        parts.push(`## Key Context\n${components.criticalContext}`);
    }

    // MIDDLE: Conversation history (lower weight)
    // Summarize if long, keep recent messages full
    const history = components.conversationHistory;
    if (history.length > 10) {
        const oldSummary = summarize(history.slice(0, -5));
        const recent = history.slice(-5);
        parts.push(`## Earlier Conversation (Summary)\n${oldSummary}`);
        parts.push(`## Recent Messages\n${formatMessages(recent)}`);
    } else {
        parts.push(`## Conversation\n${formatMessages(history)}`);
    }

    // END: Current query (high recency)
    // Restate critical requirements here
    parts.push(`## Current Request\n${components.currentQuery}`);

    // FINAL: Reminder of key constraints
    parts.push(`Remember: ${extractKeyConstraints(components.systemPrompt)}`);

    return parts.join('\n\n');
}

Intelligent Summarization

Summarize by importance, not just recency

When to use: Context exceeds optimal size

interface MessageWithMetadata extends Message {
    importance: number;  // 0-1 score
    hasCriticalInfo: boolean;  // User preferences, decisions
    referenced: boolean;  // Was this referenced later?
}

async function smartSummarize(
    messages: MessageWithMetadata[],
    targetTokens: number
): Message[] {
    // Sort by importance, preserve order for tied scores
    const sorted = [...messages].sort((a, b) =>
        (b.importance + (b.hasCriticalInfo ? 0.5 : 0) + (b.referenced ? 0.3 : 0)) -
        (a.importance + (a.hasCriticalInfo ? 0.5 : 0) + (a.referenced ? 0.3 : 0))
    );


…
FAQ

What is a 'context window'?

It's the maximum amount of text the AI can process and 'remember' at a single time. Think of it like the AI's short-term memory.

Why is summarizing important?

Summarizing allows the AI to condense old information into a smaller text, freeing up space in its 'memory' for new important information without losing the overall meaning.

Will the AI forget everything if the conversation is too long?

Not necessarily. This tool helps the AI manage context by prioritizing what's most important so it can 'remember' the essentials, even in lengthy conversations.

Details

Original description by the author

Strategies for managing LLM context windows including summarization, trimming, routing, and avoiding context rot

repo: sickn33/agentic-awesome-skills

Popularity

GitHub stars
48k
Ranking position
#2646
License
MIT
Updated
10/15/2026

Is this skill useful?

0

Sign in to vote.

Comments

  • …

More skills from this repository

Similar skills