Agent skill

Context Management

by kangarooking in kangarooking/system-prompt-skills

当系统提示词需要设计 token 预算分配、上下文压缩策略、延迟加载机制、记忆持久化方案时调用此 Skill。适用于长对话 AI 助手、代码编辑器集成、研究型 Agent、多会话系统等需要精细管理上下文窗口的场景。不适用于:单轮交互系统(无上下文管理需求)、纯无状态 API(无对话历史)、简单的 prompt 模板设计。当需求聚焦于"如何搜索外部信息"而非"如何管理已有信息"时,应该用…

MITAuto-check passedAgent Workflows

Install Context Management

skills CLI
$ npx skills add kangarooking/system-prompt-skills --skill context-management -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install kangarooking/system-prompt-skills context-management --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/kangarooking/system-prompt-skills.git skills-src && mkdir -p .claude/skills && cp -r skills-src/context-management .claude/skills/context-management && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
context-management
GitHub stars
205
Token cost
~834 tokens
SKILL.md length
243 words
Files
1
Skills in repo
15
Repo updated
First seen
Licence
MIT

At a glance

当系统提示词需要设计 token 预算分配、上下文压缩策略、延迟加载机制、记忆持久化方案时调用此 Skill。适用于长对话 AI 助手、代码编辑器集成、研究型 Agent、多会话系统等需要精细管理上下文窗口的场景。不适用于:单轮交互系统(无上下文管理需求)、纯无状态 API(无对话历史)、简单的 prompt 模板设计。当需求聚焦于"如何搜索外部信息"而非"如何管理已有信息"时,应该用…

  • Works in 7 steps: Token 预算意识 —… → 分层压缩策略 — 原始对话 → 摘要压缩 → 关键点提取 →… → 延迟加载 (Lazy Loading) —… → …
  • Tasks that involve Context engineering
  • SKILL.md covers R — 原文 (Reading), I — 方法论骨架 (Interpretation), A1 — 案例分析 (Past Application) and A2 — 触发场景 (Future Trigger) ★, plus 2 more sections
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md

What it does

Context Management is an agent skill from kangarooking/system-prompt-skills. 当系统提示词需要设计 token 预算分配、上下文压缩策略、延迟加载机制、记忆持久化方案时调用此 Skill。适用于长对话 AI 助手、代码编辑器集成、研究型 Agent、多会话系统等需要精细管理上下文窗口的场景。不适用于:单轮交互系统(无上下文管理需求)、纯无状态 API(无对话历史)、简单的 prompt 模板设计。当需求聚焦于"如何搜索外部信息"而非"如何管理已有信息"时,应该用 search-integration 而非本 Skill。

Its SKILL.md is about 830 tokens, which your agent loads only when the skill is triggered. It is a single SKILL.md file with no bundled scripts.

It sits in Agent Workflows, covering Context engineering. The repository describes itself as: 从 165 个顶级 AI 产品系统提示词中蒸馏出的 15 个可执行 Agent skill. The licence is MIT.

When your agent uses it

  • Tasks that involve Context engineering

Example prompts

  • “如何搜索外部信息”
  • “如何管理已有信息”
  • “/context-management”

Workflow steps

7 steps, taken from the first numbered list in SKILL.md.

  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])

What it can do on your machine

Read from SKILL.md and the folder at commit 252cd52. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md.

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Context Management loads about 834 tokens when it runs. Until then it costs about 61 tokens; SKILL.md has 243 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~61
When it runs · the whole SKILL.md, loaded when a task matches
~834

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from kangarooking/system-prompt-skills at commit 252cd52, republished under its MIT licence (© kangarooking). 243 words, ~834 tokens.

Download SKILL.mdSave it as .claude/skills/context-management/SKILL.md (or your agent's skills folder).
name
context-management
description
当系统提示词需要设计 token 预算分配、上下文压缩策略、延迟加载机制、记忆持久化方案时调用此 Skill。适用于长对话 AI 助手、代码编辑器集成、研究型 Agent、多会话系统等需要精细管理上下文窗口的场景。不适用于:单轮交互系统(无上下文管理需求)、纯无状态 API(无对话历史)、简单的 prompt 模板设计。当需求聚焦于"如何搜索外部信息"而非"如何管理已有信息"时,应该用 search-integration 而非本 Skill。
tags
上下文管理, token预算, 压缩策略, 记忆持久化, 延迟加载
related_skills
search-integration, agent-delegation, conversation-flow

上下文与窗口管理

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 控制输入侧的信息密度

E — 可执行步骤 (Execution)

  1. 定义 Token 预算分配方案 — 完成标准: 建立三级预算分配(系统提示词 / 对话历史 / 推理空间),定义每级的占比上限和压缩触发阈值(如对话历史超过 60% 时触发摘要压缩)

  2. 设计分层记忆架构 — 完成标准: 定义至少四层记忆(对话级临时记忆 / 会话级摘要 / 项目级文件记忆 / 用户级画像),每层有明确的存储格式、写入条件和读取优先级

  3. 建立结构化摘要模板 — 完成标准: 定义压缩后的标准输出格式(至少 5 个必填字段:用户目标、关键决策、未决事项、技术约束、偏好设定),确保压缩后不丢失可操作信息

  4. 实现延迟加载机制 — 完成标准: 定义按需加载的触发规则(如遇到未加载文件引用时才读取)、分块策略(固定大小 vs 语义分块)和预加载白名单(高频文件优先加载)

  5. 添加缓存感知优化 — 完成标准: 定义缓存友好的调度策略(短间隔保持缓存命中)、冷启动 vs 热续接的不同处理路径、以及缓存失效后的最小化重加载方案

B — 边界 (Boundary) ★

不要在以下情况使用
  • 单轮交互系统——没有上下文需要管理
  • 上下文窗口远大于实际使用量——预算管理没有实际意义
  • 对话记忆完全不重要的场景(如一次性代码生成工具)
  • 已有成熟的数据库/缓存基础设施处理状态管理——不需要在提示词层面重新设计
常见失败模式
  • 过度压缩:摘要过于简略导致关键决策信息丢失,后续对话需要反复追问已讨论过的问题
  • 延迟加载时机错误:按需加载过于激进,导致 AI 缺少必要上下文就做出判断
  • 记忆层级混乱:将临时对话信息写入持久记忆,导致记忆文件膨胀且包含过期信息
  • 忽视压缩成本:摘要操作本身消耗 token,在短对话中过度压缩反而增加总 token 消耗
  • 缓存假设失效:假设缓存一定命中而选择短延迟,实际缓存已失效导致上下文不完整

© kangarooking, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in context-management of kangarooking/system-prompt-skills.

Open the folder on GitHubat commit 252cd52

Compare with similar skills

Context Management next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Context Management compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Context Management this skillkangarooking/system-prompt-skills205—~834Automated safety check: PassMIT
Memori Long-Term MemoryMemoriLabs/Memori17k—~2kAutomated safety check: PassApache-2.0
Project Developmentguanyang/open-agent-hub9732 repos~4.7kAutomated safety check: PassMIT
Context DoctorjzOcb/context-doctor119—~642Automated safety check: PassMIT
Cognee Session Memory and Improvetopoteretes/cognee32k—~3kAutomated safety check: PassApache-2.0
Caveman Learn Token FixesJuliusBrussee/caveman110k—~2.8kAutomated safety check: PassApache-2.0

Similar skills

  • Memori Long-Term Memory

    MemoriLabs/Memori

    Adds structured long-term memory to OpenClaw agents, built automatically from sessions, with tools the agent calls to recall facts, summaries and decisions.

    17k GitHub stars~2k tokensUpdated 5 days ago
    Agent WorkflowsAuto-check passed
  • Project Development

    guanyang/open-agent-hub

    This skill should be used for project-level decisions about LLM-powered systems: whether an LLM is the right primitive for the task at hand, the shape of a multi-stage batch or agent pipeline, token…

    973 GitHub starsUsed in 2 repos~4.7k tokens
    Agent WorkflowsAuto-check passed
  • Context Doctor

    jzOcb/context-doctor

    Visualize and diagnose OpenClaw context window usage. An agent skill from jzOcb/context-doctor.

    119 GitHub stars~642 tokensUpdated 6 mo ago
    Agent WorkflowsAuto-check passed
  • Explains how cognee stores session memory by session_id and bridges it into the permanent graph with improve(), including the stages, results and settings.

    32k GitHub stars~3k tokensUpdated today
    Agent WorkflowsAuto-check passed
  • Caveman Learn Token Fixes

    JuliusBrussee/caveman

    Acts on a Caveman learn report: reviews ranked token sinks, applies cost-lowering edits one at a time with your consent, and reports what each fix returned.

    110k GitHub stars~2.8k tokensUpdated today
    Agent WorkflowsAuto-check passed
  • Claudish Usage

    MadAppGang/claudish

    CRITICAL - Guide for using Claudish CLI ONLY through sub-agents to run Claude Code with any AI model (OpenRouter, Gemini, OpenAI, local models).

    1k GitHub stars~9k tokensUpdated yesterday
    Agent WorkflowsAuto-check passed

More from kangarooking/system-prompt-skills

All 15 skills in this repo
  • Persona Design

    kangarooking/system-prompt-skills

    当需要为 AI 产品定义核心身份、角色声明和能力边界时调用此 skill。典型场景包括:设计新 AI 产品的 system prompt 首段、为不同场景创建差异化角色(如教学助手 vs 编程代理)、重新定义 AI 与用户的关系框架。

    205 GitHub starsUsed in 1 repo~956 tokens
    Auto-check passed
  • Tool Specification

    kangarooking/system-prompt-skills

    当需要为 AI 定义工具接口、设计调用规范、实现工具发现与编排机制时调用此 skill。典型场景包括:设计 AI agent 的工具集、定义 JSON Schema/XML/TypeScript 格式的工具描述、实现工具权限控制与并行调度、设计子代理委托架构。

    205 GitHub starsUsed in 1 repo~1.1k tokens
    Auto-check passed
  • Memory System

    kangarooking/system-prompt-skills

    当需要为 AI 设计记忆存储、检索、应用和更新机制时调用此 skill。典型场景包括:设计持久化记忆架构(用户偏好、历史上下文、项目知识)、定义记忆的创建/读取/更新/删除生命周期、实现静默记忆应用(不在回复中透露记忆内容)、管理敏感记忆边界。

    205 GitHub stars~1.2k tokensUpdated 5 mo ago
    Auto-check passed
  • Personality System

    kangarooking/system-prompt-skills

    当需要在基础身份之上叠加可切换的人格风格层时调用此 skill。典型场景包括:为同一产品提供多种人格选项(如 GPT-5.1 的 friendly/professional/quirky 模式)、设计人格切换机制、防止人格泄露到用户内容中。

    205 GitHub stars~1k tokensUpdated 5 mo ago
    Auto-check passed
  • Conversation Flow

    kangarooking/system-prompt-skills

    当系统提示词需要定义 AI 如何分类用户意图、路由到不同处理流程、决定澄清策略和自主度级别时调用此 Skill。适用于多任务型 AI 助手、客服机器人、编程工具、研究助手等需要结构化对话管理的场景。不适用于:纯问答型系统(无任务执行)、单轮交互(无对话状态)、简单的 prompt 模板(无路由逻辑)。当需求仅涉及"输出什么格式"而非"如何决定输出什么"时,应该用…

    205 GitHub starsUsed in 1 repo~788 tokens
    Auto-check passed
  • Safety Guardrails

    kangarooking/system-prompt-skills

    当需要为 AI 系统设计多层安全防线、内容过滤策略和伦理边界时调用此 skill。典型场景包括:设计拒绝策略与升级机制、防御 prompt 注入攻击、实现领域特定安全规则(教育、医疗、金融等)、定义 AI 的价值观锚点。

    205 GitHub stars~1.2k tokensUpdated 5 mo ago
    Auto-check passed

Questions about Context Management

What does Context Management do?

当系统提示词需要设计 token 预算分配、上下文压缩策略、延迟加载机制、记忆持久化方案时调用此 Skill。适用于长对话 AI 助手、代码编辑器集成、研究型 Agent、多会话系统等需要精细管理上下文窗口的场景。不适用于:单轮交互系统(无上下文管理需求)、纯无状态 API(无对话历史)、简单的 prompt 模板设计。当需求聚焦于"如何搜索外部信息"而非"如何管理已有信息"时,应该用…. Context Management is an agent skill from kangarooking/system-prompt-skills.

When should I use Context Management?

Context Management fits situations like: tasks that involve Context engineering.

How do I install Context Management in Claude Code?

Run `npx skills add kangarooking/system-prompt-skills --skill context-management -a claude-code`. Or copy the skill folder (context-management in kangarooking/system-prompt-skills) into .claude/skills/context-management in your project. Claude Code loads it when a task matches its description.

How do I install Context Management in Codex?

Run `npx skills add kangarooking/system-prompt-skills --skill context-management -a codex`. Or copy the skill folder (context-management in kangarooking/system-prompt-skills) into .agents/skills/context-management in your project. Codex loads it when a task matches its description.

Can I use Context Management in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add kangarooking/system-prompt-skills --skill context-management -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/context-management, .gemini/skills/context-management, .github/skills/context-management and .opencode/skills/context-management in your project.

What does Context Management need to run?

SKILL.md names no scripts, command-line tools or credentials: Context Management is instructions for the agent only.

Does Context Management access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is Context Management safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Context Management use?

Context Management is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Context Management use?

About 834 tokens (SKILL.md is roughly 3.3k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Context Management?

Skills that share tags, products or a category with Context Management: Memori Long-Term Memory (MemoriLabs/Memori, 17k stars), Project Development (guanyang/open-agent-hub, 973 stars), Context Doctor (jzOcb/context-doctor, 119 stars) and Cognee Session Memory and Improve (topoteretes/cognee, 32k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Context Management?

kangarooking (a GitHub user) maintains it in kangarooking/system-prompt-skills, which has 205 GitHub stars. The repository holds 15 skills in this directory. The repository was last updated on May 4, 2026.

Source: kangarooking/system-prompt-skills on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.