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.
npx agentmods add skills/versoxbt/claude-initial-setup/context-managementnpx skills add VersoXBT/claude-initial-setup --skill context-managementgit clone --depth 1 https://github.com/VersoXBT/claude-initial-setupWrote 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.
[](https://agentmods.dev/skills/versoxbt/claude-initial-setup/context-management)<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>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.
| Model | Per session | Once 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 |
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.
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
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.
- 4d ago First seen · 246 lines · 66 tokens per session scan A 727ac6bd397b
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.
Other skills, from other repositories
agent-v3-memory-specialist
Agent skill for v3-memory-specialist - invoke with $agent-v3-memory-specialist.
vector-memory
HNSW vector search for pattern similarity retrieval and knowledge graph maintenance with PageRank scoring, community detection, and 3-tier memory management.
memory-lancedb
LanceDB-backed vector memory for high-volume embedding and retrieval workloads.
graphiti-temporal
Temporal context graph for agent memory — track entity relationships and state changes over time.
agentic-retrieval
Agentic 检索思维 — 蒙多的记忆不只是搜索,是主动推理.
library
Sync agent memory files to a Cortex knowledge graph for enhanced retrieval, hybrid search (vector + keyword + graph), AI-powered Q&A with agentic deep research, and knowledge graph exploration.