Context Mode 上下文清理工具
Model: qwen-max | ¥0.15/call
工程方法论GPT-4.1工程实践上下文清理工具
上下文清理工具:mksglu/context-mode: ctx-purge,适用于工程实践、代码质量与开发流程优化。
Calls: 1
Skill Documentation
Context Mode 上下文清理工具
摘要
上下文清理工具:mksglu/context-mode: ctx-purge,适用于工程实践、代码质量与开发流程优化。
> 来源: mksglu/context-mode (19.7k stars) — Claude Code 上下文窗口优化
> 原文件: skills/ctx-purge/SKILL.md
> 模型推荐: gpt-4.1 (工具/查询类)
这个 skill 是干嘛的
mksglu 在 19.7k stars 的 context-mode 仓库里整理的"上下文窗口优化"工具集 — 通过 sandbox 输出压缩(98% reduction)、会话记忆持久化、17 平台路由,让 Claude 在长对话中保持高效。
michael 强调"skill 要有相应的指导功能,指导用户使用",所以加了下面两节让 Agent 和用户对接。
---
🤖 Agent 使用说明
1. 用户提到"上下文 / context / 长会话 / 记忆"时触发
2. skill 会按"压缩 → 持久化 → 检索"流程跑
3. 涉及外部存储前 ask user 确认
4. 完工后让 Agent 跑自检
👤 用户需要做什么?
1. 告诉 Agent 你要管理什么对话(长会话 / 项目 / 知识库)
2. 如果需要外部存储 / API key,按提示提供
3. 全程 Agent 自动化,你只需回答授权类问题
---
原 skill 内容(mksglu/context-mode/skills/ctx-purge/SKILL.md,截断到 12k chars)
---
name: ctx-purge
description: |
Purge the context-mode knowledge base. Permanently deletes all indexed content
and resets session stats. This is destructive and cannot be undone.
Trigger: /context-mode:ctx-purge
user-invocable: true
---
Context Mode Purge
Permanently deletes session data for this project. Two scopes are supported (issue #520):
- **Project scope** (`scope: "project"`): wipes EVERYTHING — knowledge base, all session DB rows for every session, events markdown, and stats.
- **Session scope** (`sessionId: "<id>"` or `scope: "session"`): wipes ONLY the matching session's rows + FTS5 chunks. Sibling sessions, project stats, and the FTS5 store file are preserved.
Instructions
1. **Decide the scope first** with the user:
- "Wipe just one session?" → ask for the `sessionId`.
- "Wipe the whole project?" → confirm scope:'project' (this is the destructive, irreversible default).
2. **Warn the user about scope:'project'**. Everything will be deleted:
- FTS5 knowledge base (all indexed content from `ctx_index`, `ctx_fetch_and_index`, `ctx_batch_execute`)
- Session events DB (analytics, metadata, resume snapshots) for ALL sessions in the project
- Session events markdown file
- In-memory session stats + persisted stats file
3. Call the `mcp__context-mode__ctx_purge` MCP tool with the chosen parameters:
- Scoped: `{ confirm: true, sessionId: "<id>" }` — implies scope:'session'.
- Project: `{ confirm: true, scope: "project" }` — explicit destructive form.
- Bare `{ confirm: true }` still works but emits a deprecation warning. Prefer the explicit forms.
4. Report the result to the user — the response lists exactly what was deleted and (for scoped purges) confirms that other sessions and project stats were preserved.
Schema rules
- `confirm: true` is always required.
- `sessionId` and `scope: "project"` together is REJECTED as ambiguous (the sessionId implies session scope; combining with project scope contradicts intent).
- `scope: "session"` without `sessionId` throws — sessionId is required.
When to Use
- **Scoped (per-session)**: scratch acceptance scenarios, drill replays, isolating a polluted session without losing the main working session's stats.
- **Project**: KB contains stale or incorrect content polluting search results, switching between unrelated projects in the same session, completely fresh start.
Important
- `ctx_purge` is the **only** way to delete session data. No other mechanism exists.
- `ctx_stats` is read-only — shows statistics only.
- `/clear` and `/compact` do NOT affect any context-mode data.
- There is no undo. Re-index content if you need it again.
常见问题(FAQ)
使用「上下文清理工具」这个 skill 能解决什么问题?
本 skill 专注于上下文清理工具,mksglu/context-mode: ctx-purge。它将相关流程标准化,帮助用户更快拿到可靠结果,减少重复手工操作。
什么情况下适合使用「上下文清理工具」?
当你需要在上下文清理工具相关工作中获得稳定、可复用的产出时最适合——无论是单次任务还是纳入日常工作流,都能直接调用。
使用「上下文清理工具」前需要准备什么?
需要一个具体的项目或任务上下文,最好带有代码仓库或需求文档。
FAQ
👤 用户需要做什么?
1. 告诉 Agent 你要管理什么对话(长会话 / 项目 / 知识库)
2. 如果需要外部存储 / API key,按提示提供
3. 全程 Agent 自动化,你只需回答授权类问题
---
使用「上下文清理工具」这个 skill 能解决什么问题?
本 skill 专注于上下文清理工具,mksglu/context-mode: ctx-purge。它将相关流程标准化,帮助用户更快拿到可靠结果,减少重复手工操作。
什么情况下适合使用「上下文清理工具」?
当你需要在上下文清理工具相关工作中获得稳定、可复用的产出时最适合——无论是单次任务还是纳入日常工作流,都能直接调用。
使用「上下文清理工具」前需要准备什么?
需要一个具体的项目或任务上下文,最好带有代码仓库或需求文档。