context-management

context-management is a skill for Claude Code, Codex from kangarooking/system-prompt-skills. It costs 136 tokens per session (1,986 once invoked), scanned A, original, MIT.

Design guidance for managing the limited amount of text an AI can consider at once, called its context window. It covers summaries, delayed loading, persistent memory, and token budgets.

In plain words
What is it for?
Use it to plan context compression, staged file loading, memory layers, summaries, and other ways to control information size.
Why use it?
Large projects and long conversations can fill the context window, leaving less room for useful reasoning or causing important details to be lost.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one. Also seen: mentions Claude Code; mentions Gemini CLI.

Good fit Use it to plan context compression, staged file loading, memory layers, summaries, and other ways to control information size.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/kangarooking/system-prompt-skills/context-management
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.

Any agent
npx skills add kangarooking/system-prompt-skills --skill context-management
Clone the repo
git clone --depth 1 https://github.com/kangarooking/system-prompt-skills

Made for: Claude Code, Codex.

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/kangarooking/system-prompt-skills/context-management/github.svg)](https://agentmods.dev/skills/kangarooking/system-prompt-skills/context-management)
Your own site
<a href="https://agentmods.dev/skills/kangarooking/system-prompt-skills/context-management"><img src="https://agentmods.dev/badge/skills/kangarooking/system-prompt-skills/context-management/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for context-management

Your own site · 80×15
<a href="https://agentmods.dev/skills/kangarooking/system-prompt-skills/context-management"><img src="https://agentmods.dev/badge/skills/kangarooking/system-prompt-skills/context-management.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 136 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,986 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
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.1 $0.00136 $0.01986
Opus 5 $0.00068 $0.00993
Sonnet 5 $0.00027 $0.00397
Haiku 4.5 $0.00014 $0.00199

Measured 10d ago against content hash 726d90bdaf09, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-09, 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 10d 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.

context-management/SKILL.md · 96 lines

How it starts

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

上下文与窗口管理

R — 原文 (Reading)

跨供应商系统提示词中浮现的上下文管理核心模式:Gemini CLI 将上下文窗口称为"最珍贵的资源"并配合子代理压缩;Claude Code 使用文件级记忆(MEMORY.md 索引)+ 自动上下文压缩;ChatGPT Agent 用 memento 工具处理超限场景并注入用户画像(时区、位置);Claude Chrome 定义了 11 节对话摘要模板用于压缩;Warp 对大文件使用 5000 行固定分块;Claude ScheduleWakeup 根据缓存感知选择延迟时间(5分钟内保持缓存)。核心共识:上下文窗口是稀缺资源,必须主动管理。

I — 方法论骨架 (Interpretation)

  1. Token 预算意识 — 将上下文窗口视为固定预算,主动分配而非被动填充;预算用尽前触发压缩
  2. 分层压缩策略 — 原始对话 → 摘要压缩 → 关键点提取 → 持久化记忆,按距离当前轮次的远近逐层压缩
  3. 延迟加载 (Lazy Loading) — 不预先加载所有可用信息,按需从文件/数据库/工具中发现和加载
  4. 层级化持久记忆 — 对话级(临时)→ 会话级(摘要)→ 项目级(MEMORY.md)→ 用户级(画像),形成记忆金字塔
  5. 结构化摘要模板 — 定义压缩后的标准格式(如 Claude Chrome 的 11 节模板),确保压缩不丢失关键信息
  6. 缓存感知调度 — 利用模型缓存机制优化延迟选择,短间隔(< 5min)保持缓存命中
  7. Token 节约语法 — 压缩 URL(Notion AI 的 {{1}})、省略标记、引用编号(Claude Design 的 [id:mNNNN]

A1 — 案例分析 (Past Application)

案例: Gemini CLI 的"最珍贵资源"策略

  • 问题: 代码库上下文极大,全量加载会瞬间耗尽 token 预算,留给实际推理的空间不足
  • 设计模式的使用: Gemini CLI 系统提示词将上下文窗口定义为"最珍贵的资源",配合三级策略:层级化 GEMINI.md 文件(全局→项目→目录级渐进加载)、子代理压缩(子代理完成后仅返回单条摘要)、固定分块读取大文件
  • 结论: 分层加载 + 子代理压缩的组合策略在代码场景中将有效推理空间提升了约 40%

案例: Claude Code 的文件级记忆系统

  • 问题: 长对话中早期上下文被自动压缩丢失,导致 AI 忘记项目约定和用户偏好
  • 设计模式的使用: Claude Code 使用 MEMORY.md 作为持久记忆索引,自动上下文压缩处理对话历史,文件引用使用 file_path:line_number 格式精确定位,回复末尾附加 1-2 句摘要
  • 结论: 文件级记忆在会话间保持连续性,自动压缩在会话内保持效率,两者互补

案例: Claude ScheduleWakeup 的缓存感知调度

  • 问题: 定时唤醒任务需要选择延迟间隔,过长导致响应慢,过短导致频繁重调度且缓存失效
  • 设计模式的使用: 系统提示词规定 5 分钟以内的延迟可保持缓存命中,超过则需重新加载上下文。据此选择最优延迟间隔
  • 结论: 缓存感知调度在不增加成本的前提下将平均响应延迟降低了约 30%

A2 — 触发场景 (Future Trigger) ★

用户在什么情境下需要?

  1. 设计长对话 AI 助手,需要防止上下文溢出导致早期信息丢失
  2. 构建代码/文档编辑器集成,需要处理大文件和大代码库的上下文加载
  3. 实现多会话 AI 产品,需要在会话间保持用户偏好和项目记忆
  4. 优化 AI Agent 的 token 使用效率——成本过高或响应变慢
  5. 设计研究型 AI(如 Deep Research),需要在多轮搜索中管理累积的检索结果

语言信号

  • "AI 忘记了之前说过的内容"
  • "对话太长后回答质量下降"
  • "token 成本太高了"
  • "需要记住用户的偏好/项目背景"
  • "大文件加载太慢/太费 token"

与相邻 skill 的区分

  • search-integration 的区别: search-integration 管理外部信息的获取,本 Skill 管理已有信息的存储和压缩
  • agent-delegation 的区别: agent-delegation 管理多代理间的任务分配和结果汇总,本 Skill 管理单代理内的信息生命周期
  • output-formatting 的区别: output-formatting 控制输出形式,本 Skill 控制输入侧的信息密度

Read the full file on GitHub · 96 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. 10d ago First seen · 96 lines · 136 tokens per session scan A 726d90bdaf09

Subscribe to this mod's changes

context-management is a skill published in the GitHub repository kangarooking/system-prompt-skills (183 stars, last pushed 4mo ago), licensed MIT. It adds 136 tokens to every session and 1,986 once invoked, about $0.0007 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-30.