Provides strategies for working with large Claude context windows: checking model limits, counting tokens, structuring inputs for recall, caching stable content, and managing growing conversations via compaction or memory.
Ships in messages-api-features. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
A large context window lets you send a lot; it does not make sending a lot free or accurate. Count first, structure the input, cache what repeats, and actively manage context as it grows.
Context window size depends on the model. The docs list which current models have a 1M-token window and which have 200K, and state that for models with a 1M window, 1M is the default with no beta header. Older guidance that required a context-1m-... beta header applies only to the models it was written for.
Do not hard-code the number. Read it at runtime:
import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic();
const MODEL = process.env.ANTHROPIC_MODEL!; // a current model ID
const info = await client.models.retrieve(MODEL);
console.log(info.max_input_tokens, info.max_tokens); // context window, output cap
Pricing for very long prompts also varies by model; check the pricing page's long-context section rather than assuming a flat rate.
const { input_tokens } = await client.messages.countTokens({
model: MODEL,
system,
messages,
});
if (input_tokens > info.max_input_tokens! * 0.9) {
// trim, retrieve instead, or compact first
}
Everything counts: system prompt, every message (tool results, images, documents), tool definitions, and the output including thinking. If the input alone exceeds the window, the API returns 400 invalid_request_error ("prompt is too long"). On recent models, if input plus max_tokens would exceed the window, the request is accepted and generation can stop with stop_reason: "model_context_window_exceeded"; handle that stop reason.
The docs warn that accuracy and recall degrade as token count grows ("context rot"). Structure helps the model find things:
const prompt = `
<documents>
<document index="1" source="src/auth.ts">...</document>
<document index="2" source="docs/architecture.md">...</document>
</documents>
Using only the documents above, explain how a session token is validated.
Quote the relevant lines before answering.
`;
If several questions hit the same corpus, put the corpus before a cache breakpoint so later requests read it from cache (see the prompt-caching skill). Caching changes what you pay for those tokens, not whether they count toward the window.
For agents and long chats, choose a strategy before you hit the limit:
| Strategy | What it does | Where it runs |
|---|---|---|
| Compaction (beta) | Replaces older turns with a summary Claude writes | Server-side; on demand or at a token threshold |
| Context editing (beta) | Clears old tool results or thinking blocks by rule | Server-side, configured per request |
| Memory tool | Moves durable facts into files Claude reads on demand | Your storage (see memory-tool) |
| Retrieval | Fetches only relevant chunks per question | Your pipeline |
Compaction and context editing are beta features with their own beta headers and parameters, and both have changed over time. Follow the current compaction and context-editing pages for exact request shapes. Whichever you use, append the full response.content back to history, not just the text, so server-generated blocks are preserved.
| Long context fits better | Retrieval fits better |
|---|---|
| Corpus fits comfortably in the window | Corpus is unbounded or much larger than the window |
| Relevance is hard to predict in advance | Queries target known, narrow facts |
| Few questions per corpus load (or cached) | Many cheap lookups across many users |
| Synthesis across many sources | Data changes frequently or needs per-user isolation |
A hybrid is common: retrieve a generous candidate set, then let the model reason over it in one long prompt.
Large inputs take longer to process. Stream responses so users see progress, and cache stable prefixes so repeat requests skip most of the input processing.
model_context_window_exceeded and "prompt is too long" explicitlyWhat SKILL.md sets; muted values are Claude Code's defaults
/messages-api-features:long-contextfrom messages-api-features
npx claudepluginhub latestaiagents/agent-skills --plugin messages-api-features7 skills in this plugin
/code-executionUse the Claude API code execution tool so the model runs Bash and Python in an Anthropic-hosted sandbox during a response — for calculation, data analysis, file generation, and checking its own work. Covers tool versions, file upload, retrieving generated files, container reuse, limits, and data-retention constraints.
Use this skill when building features where Claude must actually run code (not just write it), when choosing a code execution tool version, or when debugging missing output files or expired containers.
Activate when: Claude code execution, code_execution tool, Python sandbox, run code tool, data analysis agent, code interpreter, container_upload, container reuse, OUTPUT_DIR.
/computer-useBuild desktop and browser automation agents with the Claude API computer use toolset — screenshots, clicks, typing, scrolling — run by your own harness inside an isolated VM or container. Covers choosing the toolset version, the agent loop, batch actions, sandboxing, prompt-injection risk, and when an API integration is the better choice.
Use this skill when building agents that operate GUIs (legacy apps, browsers without APIs), migrating from an older computer use tool version, or reviewing the safety of a computer use deployment.
Activate when: Claude computer use, computer_toolset, computer_20251124, computer_20250124, desktop agent, screen control, click and type agent, GUI automation.
Other plugins' skills for the same job
2 plugins in one repository ship this exact skill · first indexed Nov 5, 2026