context-manager
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseContext Manager
上下文管理器
Manage the Claude Code memory hierarchy and audit the full markdown landscape of a project. Produces well-organised memory files, detects documentation overlap, and reports the total context footprint.
管理Claude Code记忆层级并审计项目的完整Markdown体系。生成组织有序的记忆文件,检测文档重叠情况,并报告总上下文占用量。
Four Context Layers
四个上下文层级
| Layer | Location | Purpose | What this skill does |
|---|---|---|---|
| Memory | | Project context, commands, architecture, rules | Audit, score, maintain |
| Project docs | | Technical documentation | Check existence per project type, flag staleness, detect CLAUDE.md overlap |
| Session | | Temporary progress tracking | Report presence + size (managed by dev-session) |
| Public | | Public-facing docs | Detect CLAUDE.md duplication |
Auto-memory () is also scanned for awareness but managed by Claude automatically.
~/.claude/projects/*/memory/MEMORY.md| 层级 | 位置 | 用途 | 该技能的作用 |
|---|---|---|---|
| 记忆层 | | 项目上下文、命令、架构、规则 | 审计、评分、维护 |
| 项目文档层 | | 技术文档 | 根据项目类型检查是否存在、标记过期、检测与CLAUDE.md的重叠 |
| 会话层 | | 临时进度跟踪 | 报告存在性及大小(由dev-session管理) |
| 公共层 | | 面向公众的文档 | 检测与CLAUDE.md的重复内容 |
自动记忆文件()也会被扫描以获取相关信息,但由Claude自动管理。
~/.claude/projects/*/memory/MEMORY.mdOperating Modes
操作模式
Mode 1: Session Capture
模式1:会话捕获
When: End of session, "capture learnings", "update CLAUDE.md with what we learned"
- Review the conversation for discoveries worth preserving:
- Commands that worked (or didn't)
- Gotchas and workarounds found
- Architecture decisions made
- Configuration quirks discovered
- Patterns that would help future sessions
- Categorise each discovery using the placement decision tree below
- Draft all changes as diffs in a single batch
- Present the batch — apply after a single yes/no confirmation
Keep it concise: one line per concept. No verbose explanations, no generic advice.
触发场景:会话结束时、输入"capture learnings"、"update CLAUDE.md with what we learned"
- 回顾对话内容,筛选值得保留的发现:
- 可行(或不可行)的命令
- 发现的陷阱与解决方法
- 做出的架构决策
- 发现的配置异常
- 对未来会话有帮助的模式
- 使用下方的放置决策树对每个发现进行分类
- 将所有更改以差异形式批量草拟
- 展示批量更改内容,在单次确认(是/否)后应用
注意简洁:每个概念仅用一行描述。无需冗长解释,无需通用建议。
Mode 2: Full Audit
模式2:全面审计
When: "audit context", "audit memory", "check project docs", periodic maintenance, working in a neglected project
- Run the audit script:
bash
python3 skills/context-manager/scripts/audit_memory.py [repo-path] - Review the output:
- Memory layer: CLAUDE.md sizes, quality scores, rules file sizes
- Project docs: existence, staleness, overlap with CLAUDE.md
- Session/public: presence and size
- Markdown footprint: total KB by layer
- Overlap warnings: sections duplicated between files
- Generate changes autonomously — create, update, or flag files as needed
- Present all changes as a single batch for approval
- Apply approved changes
For large repos, delegate to a sub-agent:
Task(subagent_type: "general-purpose",
prompt: "Run python3 skills/context-manager/scripts/audit_memory.py /path/to/repo
and summarise the findings.")触发场景:输入"audit context"、"audit memory"、"check project docs"、定期维护、处理被忽视的项目
- 运行审计脚本:
bash
python3 skills/context-manager/scripts/audit_memory.py [repo-path] - 查看输出内容:
- 记忆层:CLAUDE.md文件大小、质量评分、规则文件大小
- 项目文档层:存在性、过期情况、与CLAUDE.md的重叠情况
- 会话/公共层:存在性及大小
- Markdown占用量:各层级的总KB数
- 重叠警告:文件间重复的章节
- 自主生成更改内容——根据需要创建、更新或标记文件
- 将所有更改作为单个批次呈现以获取批准
- 应用已批准的更改
对于大型仓库,可委托给子代理:
Task(subagent_type: "general-purpose",
prompt: "Run python3 skills/context-manager/scripts/audit_memory.py /path/to/repo
and summarise the findings.")Mode 3: Restructure
模式3:重构
When: "restructure memory", root CLAUDE.md over 200 lines, first-time memory setup
- Run full audit (Mode 2) first
- Split oversized files:
- Extract topic sections from root CLAUDE.md into
.claude/rules/<topic>.md - Extract directory-specific content into sub-directory CLAUDE.md files
- Move detailed technical content from CLAUDE.md to or
docs/if it's reference material, not operational contextARCHITECTURE.md
- Extract topic sections from root CLAUDE.md into
- Resolve overlaps: if CLAUDE.md duplicates ARCHITECTURE.md or docs/, remove the duplication
- Create missing documentation files based on project type
- Present the restructure plan, apply after approval
触发场景:输入"restructure memory"、根目录CLAUDE.md超过200行、首次设置记忆文件
- 先运行全面审计(模式2)
- 拆分过大的文件:
- 从根目录CLAUDE.md中提取主题章节到
.claude/rules/<topic>.md - 将目录特定内容提取到子目录的CLAUDE.md文件中
- 如果是参考资料而非操作上下文,将CLAUDE.md中的详细技术内容移至或
docs/ARCHITECTURE.md
- 从根目录CLAUDE.md中提取主题章节到
- 解决重叠问题:如果CLAUDE.md与ARCHITECTURE.md或docs/内容重复,移除重复部分
- 根据项目类型创建缺失的文档文件
- 展示重构计划,在批准后应用
Placement Decision Tree
放置决策树
Would this still apply if I switched to a completely different project?
├── YES → ~/.claude/rules/<topic>.md
│ (correction rules, API patterns, coding standards)
└── NO → Is it specific to a subdirectory?
├── YES → <dir>/CLAUDE.md
│ (integrations, directory-specific gotchas)
└── NO → Is it reference documentation or operational context?
├── Reference → ARCHITECTURE.md or docs/
│ (system design, schemas, detailed flows)
└── Operational → ./CLAUDE.md (project root)
(identity, stack, commands, critical rules)如果切换到完全不同的项目,此内容是否仍然适用?
├── 是 → ~/.claude/rules/<topic>.md
│ (修正规则、API模式、编码标准)
└── 否 → 是否特定于某个子目录?
├── 是 → <dir>/CLAUDE.md
│ (集成、特定目录的陷阱)
└── 否 → 是参考文档还是操作上下文?
├── 参考文档 → ARCHITECTURE.md 或 docs/
│ (系统设计、架构、详细流程)
└── 操作上下文 → ./CLAUDE.md(项目根目录)
(项目标识、技术栈、命令、关键规则)Size Targets
大小目标
| File Type | Target | Maximum |
|---|---|---|
| Root CLAUDE.md | 50-150 lines | 200 |
| Sub-directory CLAUDE.md | 15-50 lines | 80 |
| Rules topic file | 20-80 lines | 120 |
| 文件类型 | 目标范围 | 最大值 |
|---|---|---|
| 根目录CLAUDE.md | 50-150行 | 200行 |
| 子目录CLAUDE.md | 15-50行 | 80行 |
| 规则主题文件 | 20-80行 | 120行 |
What Belongs Where
内容归属指南
Root CLAUDE.md
根目录CLAUDE.md
- Project name, purpose, owner
- Tech stack summary
- Build/deploy/test commands (copy-paste ready)
- Directory structure overview
- Critical "never do X" rules
- Key integrations and secrets locations
- 项目名称、用途、所有者
- 技术栈摘要
- 构建/部署/测试命令(可直接复制粘贴)
- 目录结构概述
- 关键的"禁止操作X"规则
- 核心集成及密钥位置
Sub-directory CLAUDE.md
子目录CLAUDE.md
- External service integrations for that component
- Non-obvious configuration specific to this area
- Directory-specific commands
- Gotchas when working in this directory
Don't create when: parent covers it, directory is self-explanatory, content would be under 10 lines.
- 该组件的外部服务集成
- 该区域特有的非显而易见配置
- 特定目录的命令
- 在该目录工作时的注意事项
无需创建的情况:父目录已涵盖相关内容、目录本身易于理解、内容不足10行。
.claude/rules/ topic files
.claude/rules/ 主题文件
- Correction rules bridging training cutoff (e.g. API changes, deprecated patterns)
- Coding patterns and standards
- Platform-specific formatting rules
- Error prevention patterns
- 弥补训练截止日期后的修正规则(如API变更、已弃用模式)
- 编码模式与标准
- 平台特定的格式规则
- 错误预防模式
docs/ and ARCHITECTURE.md
docs/ 和 ARCHITECTURE.md
- Detailed system architecture (component diagrams, data flows)
- Database schemas and migration guides
- API endpoint catalogues
- Content that Claude should read on demand, not every session
Rule of thumb: If it's needed every session, put it in CLAUDE.md. If it's reference material consulted occasionally, put it in docs/.
- 详细的系统架构(组件图、数据流)
- 数据库架构与迁移指南
- API端点目录
- Claude按需查阅而非每次会话都需要的内容
经验法则:如果每次会话都需要,放在CLAUDE.md中。如果是偶尔查阅的参考资料,放在docs/中。
What to delete
应删除的内容
- Content Claude already knows from training
- Verbose explanations of standard frameworks
- Changelogs or version history (use git)
- Duplicated content (between CLAUDE.md and docs/, ARCHITECTURE.md, or README.md)
- "TODO" items that were never completed
- Generic advice not specific to the project
- Claude从训练中已掌握的内容
- 对标准框架的冗长解释
- 变更日志或版本历史(使用git管理)
- 重复内容(CLAUDE.md与docs/、ARCHITECTURE.md或README.md之间)
- 从未完成的"TODO"项
- 非项目特定的通用建议
Project Type Detection
项目类型检测
The audit script detects project type from file presence and suggests appropriate documentation:
| Indicator | Type | Suggested Docs |
|---|---|---|
| Cloudflare Worker | ARCHITECTURE.md |
| Vite/React | ARCHITECTURE.md |
| Next.js | ARCHITECTURE.md |
MCP patterns in | MCP Server | ARCHITECTURE.md, API_ENDPOINTS.md |
| API Project | API_ENDPOINTS.md, DATABASE_SCHEMA.md |
| Drizzle/Prisma config | Database | DATABASE_SCHEMA.md |
All projects get CLAUDE.md. Additional docs only when the project type warrants them. See references/project-types.md for full detection heuristics and doc templates.
审计脚本通过文件存在情况检测项目类型,并建议相应的文档:
| 标识 | 类型 | 建议文档 |
|---|---|---|
| Cloudflare Worker | ARCHITECTURE.md |
| Vite/React | ARCHITECTURE.md |
| Next.js | ARCHITECTURE.md |
| MCP服务器 | ARCHITECTURE.md、API_ENDPOINTS.md |
| API项目 | API_ENDPOINTS.md、DATABASE_SCHEMA.md |
| Drizzle/Prisma配置 | 数据库项目 | DATABASE_SCHEMA.md |
所有项目都需要CLAUDE.md。仅当项目类型有需要时才添加额外文档。完整的检测规则和文档模板请参阅references/project-types.md。
Autonomy Rules
自主操作规则
- Just do it: Run audit, detect project type, identify gaps, draft changes
- Brief confirmation: Apply changes (single batch yes/no, not item-by-item)
- Ask first: Delete existing content, major restructures (moving 50+ lines), create new project docs from scratch where there's ambiguity about content
- 直接执行:运行审计、检测项目类型、识别缺口、草拟更改
- 简短确认:应用更改(单次批量确认是/否,而非逐项确认)
- 先询问:删除现有内容、重大重构(移动50行以上内容)、在内容存在歧义时从头创建新的项目文档
Quality Scoring
质量评分
The audit script scores each CLAUDE.md on 6 criteria (100 points):
| Criterion | Points | What it measures |
|---|---|---|
| Commands/Workflows | 20 | Build, test, deploy documented |
| Architecture Clarity | 20 | Structure, relationships, entry points |
| Non-Obvious Patterns | 15 | Gotchas, quirks, warnings |
| Conciseness | 15 | Dense content, no filler |
| Currency | 15 | References valid, commands work |
| Actionability | 15 | Copy-paste ready, real paths |
See references/quality-criteria.md for the full rubric.
审计脚本从6个维度对每个CLAUDE.md进行评分(满分100分):
| 维度 | 分值 | 衡量内容 |
|---|---|---|
| 命令/工作流 | 20 | 构建、测试、部署命令是否已记录 |
| 架构清晰度 | 20 | 结构、关系、入口点是否清晰 |
| 非显而易见模式 | 15 | 是否记录陷阱、异常、警告 |
| 简洁性 | 15 | 内容是否精炼、无冗余 |
| 时效性 | 15 | 参考内容是否有效、命令是否可行 |
| 可操作性 | 15 | 是否可直接复制粘贴、路径是否真实有效 |
完整评分标准请参阅references/quality-criteria.md。
Reference Files
参考文件
| When | Read |
|---|---|
| Scoring CLAUDE.md quality | references/quality-criteria.md |
| Detecting project type and expected docs | references/project-types.md |
| Creating new CLAUDE.md or rules files | references/templates.md |
| 场景 | 查阅文件 |
|---|---|
| 为CLAUDE.md质量评分 | references/quality-criteria.md |
| 检测项目类型及所需文档 | references/project-types.md |
| 创建新的CLAUDE.md或规则文件 | references/templates.md |
Scripts
脚本
- — Scan all four layers, score quality, detect project type, report footprint and overlap
scripts/audit_memory.py- — human-readable report
python3 audit_memory.py [repo-path] - — structured JSON output
python3 audit_memory.py [repo-path] --json
- — 扫描四个层级、为质量评分、检测项目类型、报告占用量与重叠情况
scripts/audit_memory.py- — 生成人类可读的报告
python3 audit_memory.py [repo-path] - — 生成结构化JSON输出
python3 audit_memory.py [repo-path] --json