Skip to content
Skills Library
AI & agents · Building & coding

context-window-management

/context-window-management

Budget tokens across system prompt, history, and retrieval, with compaction that keeps what matters. Use when building long-running LLM applications or debugging context overflow and mid-conversation amnesia.

Repository
AI-SKILLS ↗
Licence
MIT
Last repository change
05.09.2026

Assessment and security

90/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content25 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
1
Scripts
0
HTML comments
0
URLs in SKILL.md
0
Deprecation

No signals detected. Repository changed on 05.09.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What it does and when to use it

Budget tokens across system prompt, history, and retrieval, with compaction that keeps what matters. Use when building long-running LLM applications or debugging context overflow and mid-conversation amnesia.

Original author description

Budget tokens across system prompt, history, and retrieval, with compaction that keeps what matters. Use when building long-running LLM applications or debugging context overflow and mid-conversation amnesia.

How it works

  1. Method
  2. Boundaries
Original SKILL.md headings · 73 lines, 470 words
SKILL.md preview
---
name: context-window-management
description: Budget tokens across system prompt, history, and retrieval, with compaction that keeps what matters. Use when building long-running LLM applications or debugging context overflow and mid-conversation amnesia.
---

# Context window management

Context is a budget, and everything competes for it: instructions,
history, retrieved documents, tool results. Manage it like memory in
an embedded system: allocated by purpose, compacted under pressure,
with the invariant that the most decision-relevant tokens survive.

## Method

1. **Partition the budget explicitly.** Fixed allocation for
   the system prompt (keep it lean: every instruction competes
   with data for attention), a reserve for the response, and
   the remainder split between history and retrieval by the
   application's shape (chat leans history; Q&A leans
   retrieval: see rag-pipeline). Know your model's real
   window and your p95 usage against it: overflow failures
   are a capacity-planning problem (see capacity-planning).
2. **Compact history hierarchically, not by truncation.**
   Rolling summarization: old turns compress into a summary
   block (decisions made, facts established, current goal),
   recent turns stay verbatim: the summary is regenerated as
   turns age past a threshold. Naive head-truncation deletes
   the instructions and early decisions that the conversation
   still depends on (the mid-conversation amnesia bug).
3. **Preserve the load-bearing tokens.** Some content must
   never compact away: the task definition, hard constraints,
   user identity/preferences, schema definitions for
   structured output (see structured-output), and safety
   instructions. Pin them (re-inject after compaction) rather
   than trusting the summarizer to keep them (see
   agent-memory for durable cross-session state; this skill
   is within-session).
4. **Trim retrieval to relevance, not availability.** Rank
   retrieved chunks, take top-k under the retrieval budget,
   and prefer many small relevant chunks over few large
   loose ones (see embeddings-selection's chunking
   interplay); deduplicate near-identical chunks (retrieval
   loves returning five copies of the same paragraph);
   summarize tool results that are data dumps before they
   enter context (a 50KB JSON response is usually 500
   tokens of decision-relevant content wearing a payload).
5. **Watch position effects.** Models attend best to the
   start and end of context: instructions up front,
   the immediate question and freshest data near the end,
   the middle for reference material: and verify with
   needle tests on your actual layout when correctness
   depends on mid-context content (long-context claims
   degrade under load; measure, do not trust the
   spec sheet: see llm-eval-design).
6. **Instrument token flows in production.** Per-request
   token counts by section (system/history/retrieval/
   response), compaction frequency, and overflow events
   (see llm-observability): rising history share means the
   compaction threshold needs tuning; cost tracks tokens
   linearly, so this dashboard is also the bill (see
   llm-cost-latency).

## Boundaries

- Bigger windows are not a strategy: cost scales with
  tokens, latency grows, and attention quality drops
  before the hard limit; compaction discipline pays at
  every window size.
- Summaries are lossy by design; applications where exact
  history matters (legal, medical, audit) need verbatim
  logs outside the context (see audit-logging) with
  retrieval back in, not longer summaries.
- Prompt caching changes the economics of stable prefixes
  (see llm-cost-latency) and rewards a fixed
  system-prompt layout; design the partition with caching
  in mind from the start.

Versions

RepositoryScoreLicence
This page · Amey-Thakur/AI-SKILLS90MIT
seyhunak/skilldeck100MIT
fabiensalles/claude-marketplace100MIT
Wsh7Ash/skillmcp100MIT
charlieviettq/awesome-agent-skill100MIT
rootcastleco/rei-skills90MIT

Database snapshot: 13.11.2026 · package version fa969ba88314 (SHA-256 digest of the entire package)

Downloads in the last 30 days: 1 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 100context-budget
    Context window management for AI agents. Optimize context usage, prevent overflow, and ensure critical information is always available. Use when working with large codebases or long sessions.
  • 90context-optimization
    Use when optimizing token usage, KV cache efficiency, or context window management for LLM agents. Keywords: context optimization, KV cache, prompt caching, token budget, semantic pruning, lost-in-the-middle.
  • 100long-context
    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…
  • 100context-management
    Token budgeting, placement effects, RAG patterns, prompt caching, compression, and multi-turn context strategies for LLM applications. Use when dealing with context windows, token budgets, retrieval-augmented generation, long context, context overflow, caching costs, observation…
  • 100agent-context-budget-management-strategies
    Use this skill when monitoring, budgeting, and optimizing context window tokens during complex, multi-turn technical workflows.
  • 100context-ops
    Manage this session's own conversation context — compress the chat history to free up token budget, or clear it to start a fresh conversation. Use when the context window is filling up, the session has grown too long, token pressure is high, or the user wants to wipe the history…

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.