context-management

context-management is a skill for Claude Code, Codex from VersoXBT/claude-initial-setup. It costs 66 tokens per session (2,009 once invoked), scanned A, original, MIT.

A set of methods for controlling the information an AI agent keeps in its working context over long tasks. It covers techniques such as summaries, retrieval of relevant material, staged detail, and removing low-value history.

In plain words
What is it for?
Use it when building long-running agents, designing retrieval systems, managing conversation history, or reducing context-related cost and loss of detail.
Why use it?
It helps agents stay within context limits while retaining the information needed to make good decisions and reducing unnecessary token use.

Skill for Claude CodeCodex

Part of the claude-initial-setup plugin — 75 skills, 15 commands, 14 agents, 2 hooks shipped together

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/versoxbt/claude-initial-setup/context-management
Any agent
npx skills add VersoXBT/claude-initial-setup --skill context-management
Clone the repo
git clone --depth 1 https://github.com/VersoXBT/claude-initial-setup

Made for: Claude Code, Codex.

Or install claude-initial-setup, the plugin that ships this one along with the rest of its 75 skills, 15 commands, 14 agents, 2 hooks.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for context-management

README.md
[![agentmods](https://agentmods.dev/badge/skills/versoxbt/claude-initial-setup/context-management.svg)](https://agentmods.dev/skills/versoxbt/claude-initial-setup/context-management)
Your own site
<a href="https://agentmods.dev/skills/versoxbt/claude-initial-setup/context-management"><img src="https://agentmods.dev/badge/skills/versoxbt/claude-initial-setup/context-management.svg" alt="Measured on agentmods" height="20"></a>
Per session 66 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,009 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00066 $0.02009
Opus 5 $0.00033 $0.01005
Sonnet 5 $0.00013 $0.00402
Haiku 4.5 $0.00007 $0.00201

Measured 4d ago against content hash 727ac6bd397b, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

context-management scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 4d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills/agent-patterns/context-management/SKILL.md · 246 lines

How it starts

The opening of the file, as written. The whole thing — 246 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Context Management

Strategies for optimizing AI agent context windows. Covers summarization, RAG, progressive disclosure, pruning, and token budgeting for long-running agents.

When to Use

  • User is hitting context window limits in agent workflows
  • User is building long-running agents that accumulate context
  • User needs retrieval-augmented generation (RAG) patterns
  • User wants to optimize token usage and reduce costs
  • User is designing memory systems for agents

Core Patterns

Sliding Window with Summarization

Keep recent messages in full while summarizing older ones.

def manage_context(messages: list[dict], max_tokens: int = 50000) -> list[dict]:
    token_count = count_tokens(messages)

    if token_count <= max_tokens:
        return messages

    # Keep system message, summarize old messages, keep recent ones
    system_msg = messages[0] if messages[0]["role"] == "system" else None
    conversation = messages[1:] if system_msg else messages

    # Split: older half gets summarized, recent half stays intact
    midpoint = len(conversation) // 2
    older = conversation[:midpoint]
    recent = conversation[midpoint:]

    # Summarize older messages
    summary = client.messages.create(
        model="claude-haiku-4-5-20251001",
        max_tokens=1024,
        system="Summarize this conversation, preserving key decisions, facts, and action items.",
        messages=[{"role": "user", "content": json.dumps(older)}]
    )

    summary_msg = {
        "role": "user",
        "content": f"[Summary of earlier conversation]\n{summary.content[0].text}"
    }

    result = []
    if system_msg:
        result.append(system_msg)
    result.append(summary_msg)
    result.extend(recent)
    return result

Retrieval-Augmented Generation (RAG)

Fetch relevant context on demand instead of loading everything upfront.

from anthropic import Anthropic

client = Anthropic()

def rag_agent(question: str, knowledge_base) -> str:
    # Step 1: Generate search queries from the question
    query_response = client.messages.create(
        model="claude-haiku-4-5-20251001",
        max_tokens=512,
        system="Generate 3 search queries to find relevant information. Return a JSON array of strings.",
        messages=[{"role": "user", "content": question}]
    )
    queries = json.loads(query_response.content[0].text)

    # Step 2: Retrieve relevant chunks
    chunks = []
    for query in queries:
        results = knowledge_base.search(query, top_k=3)
        chunks.extend(results)

    # Deduplicate and rank by relevance
    unique_chunks = deduplicate(chunks)
    top_chunks = sorted(unique_chunks, key=lambda c: c.score, reverse=True)[:5]

    # Step 3: Answer with retrieved context
    context = "\n\n---\n\n".join(
        f"Source: {c.metadata['source']}\n{c.text}" for c in top_chunks
    )

    response = client.messages.create(
        model="claude-sonnet-4-6-20250514",
        max_tokens=4096,
        system="""Answer based on the provided context. If the context does not contain
enough information, say so. Cite sources using [Source: filename] format.""",
        messages=[{
            "role": "user",
            "content": f"Context:\n{context}\n\nQuestion: {question}"
        }]
    )
    return response.content[0].text

Read the full file on GitHub · 246 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 4d ago First seen · 246 lines · 66 tokens per session scan A 727ac6bd397b

Subscribe to this mod's changes

context-management is a skill published in the GitHub repository VersoXBT/claude-initial-setup (4 stars, last pushed 3mo ago), licensed MIT. It adds 66 tokens to every session and 2,009 once invoked, about $0.0003 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.