Przejdź do treści
Biblioteka skilli
AI i agenci · Budowanie i kod

long-context

/long-context

Pracuje świadomie z dużymi oknami kontekstu Claude: liczy tokeny, porządkuje długie wejścia, buforuje stałą część i kompaktuje rozmowę.

Repozytorium
agent-skills ↗
Licencja
MIT
Ostatnia zmiana repozytorium
04.11.2026

Ocena i bezpieczeństwo

100/ 100Klasa: dobry
Format25 / 25
Frontmatter z nazwą i opisem, poprawna nazwa, opis do 1024 znaków, nazwa zgodna z folderem.
Odkrywalność25 / 25
Opis mówi, kiedy użyć skilla, ma sensowną długość i jest w 3. osobie.
Treść35 / 35
Co najmniej 150 słów i do 500 linii, nagłówki, listy kroków, przykłady albo kod.
Higiena15 / 15
Bez zaślepek typu TODO, bez ścieżek Windows, z licencją.
Ryzykobrak sygnałów w skanie
Pliki w paczce
1
Skrypty
0
Komentarze HTML
0
Adresy URL w SKILL.md
6
Przestarzałość

Brak sygnałów. Repozytorium zmienione 04.11.2026, bez odwołań do wycofanych modeli i API.

Licencja

MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.

Co robi i kiedy

Pracuje świadomie z dużymi oknami kontekstu Claude: liczy tokeny, porządkuje długie wejścia, buforuje stałą część i kompaktuje rozmowę.

Oryginalny opis (EN)

Work with large Claude context windows deliberately — check the window for your model, count tokens before sending, structure long inputs for recall, cache the stable part, and manage growing conversations with compaction, context editing, or memory instead of stuffing everything in. Use this skill when feeding large codebases, document sets, or long agent histories to Claude, when weighing long context against retrieval, or when a conversation is approaching the context limit. Activate when: long context, context window, 1M context, context limit, prompt is too long, context rot, compaction,

Jak działa

  1. When to Use
  2. Workflow
  3. Long Context vs Retrieval
  4. Latency
  5. Anti-Patterns
  6. Best Practices
  7. References
Sekcje z nagłówków SKILL.md, w oryginale · 126 linii, 896 słów
Podgląd SKILL.md
---
name: long-context
description: |
  Work with large Claude context windows deliberately — check the window for your model, count tokens before sending, structure long inputs for recall, cache the stable part, and manage growing conversations with compaction, context editing, or memory instead of stuffing everything in.
  Use this skill when feeding large codebases, document sets, or long agent histories to Claude, when weighing long context against retrieval, or when a conversation is approaching the context limit.
  Activate when: long context, context window, 1M context, context limit, prompt is too long, context rot, compaction, context editing, long context vs RAG, token counting.
---

# Long Context

**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.**

## When to Use

- Cross-document reasoning over a corpus that fits in the window
- Whole-repository review or refactoring where relevance is hard to predict
- Long-running agents whose history keeps growing
- Deciding between long context, retrieval (RAG), or both

## Workflow

### Step 1: Check the window for your model

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:

```ts
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.

### Step 2: Count tokens before you send

```ts
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.

### Step 3: Structure the input for recall

The docs warn that accuracy and recall degrade as token count grows ("context rot"). Structure helps the model find things:

```ts
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.
`;
```

- Put long material first and the question at the end
- Wrap each source in tags with an identifier the answer can cite
- Ask for supporting quotes before the answer on retrieval-style questions
- Remove what is clearly irrelevant: less noise beats more coverage

### Step 4: Cache the stable part

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.

### Step 5: Manage growing conversations

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 vs Retrieval

| 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.

## Latency

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.

## Anti-Patterns

1. Hard-coding a window size or beta header copied from an old example
2. Sending an entire repository when a directory would do
3. Undelimited blobs of text with the question at the top
4. Letting agent history grow until the API rejects the request
5. Appending only the text of responses when using compaction, which drops the compaction block

## Best Practices

1. Read the window from the Models API and count tokens before sending
2. Structure long inputs with tagged sources and put the question last
3. Cache the reusable prefix
4. Plan context management (compaction, editing, memory, retrieval) from the start for agents
5. Handle `model_context_window_exceeded` and "prompt is too long" explicitly
6. Measure answer quality at your real input sizes; do not assume recall is uniform

## References

- Context windows: https://platform.claude.com/docs/en/build-with-claude/context-windows
- Token counting: https://platform.claude.com/docs/en/build-with-claude/token-counting
- Compaction: https://platform.claude.com/docs/en/build-with-claude/compaction
- Context editing: https://platform.claude.com/docs/en/build-with-claude/context-editing
- Models overview: https://platform.claude.com/docs/en/about-claude/models/overview
- Effective context engineering: https://www.anthropic.com/engineering/effective-context-engineering-for-ai-agents

Wersje

RepozytoriumWynikLicencja
Ta strona · latestaiagents/agent-skills100MIT
davila7/claude-code-templates90MIT

Migawka bazy z 13.11.2026 · wersja paczki 7dc1c7f87894 (skrót SHA-256 całej paczki)

Pobrania w ostatnich 30 dniach: 0 · ranking

Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.

Podobne skille

  • 100context-window-compaction-kv-cache
    Prowadzi długie rozmowy z modelem dzięki streszczeniom kroczącym, przycinaniu tokenów i ponownemu użyciu pamięci KV.
  • 90context-window-management
    Rozdziela budżet tokenów między prompt systemowy, historię i retrieval oraz kompaktuje kontekst tak, by zachować to, co ważne, w długich aplikacjach LLM i przy przepełnieniu kontekstu.
  • 100short-context-agent
    Utrzymuje długie zadania agenta w krótkim kontekście: zwięzłe notatki przekazania, kompakcję rozmowy i czytanie dużych plików fragmentami.
  • 90context-window-management
    Opisuje strategie zarządzania oknem kontekstu LLM: streszczanie, przycinanie, routing i unikanie degradacji kontekstu.
  • 95context-engine
    Zarządza oknem kontekstu: automatycznie kompaktuje rozmowę, gdy się zapełnia, i zachowuje krytyczne informacje między granicami.
  • 90context-engineering
    Dobiera zawartość okna kontekstu modelu pod kątem niezawodności i kosztu: zapis, wybór, kompresja i izolacja.

Uwagi i zgłoszenia

Wiadomość trafi do Bartosza Sokolińskiego. Adres e-mail jest potrzebny tylko do odpowiedzi. Szczegóły w polityce prywatności.