claude-md-progressive-disclosurer
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCLAUDE.md Progressive Disclosure Optimizer
CLAUDE.md 渐进式披露优化工具
Analyze and optimize user CLAUDE.md files to reduce context overhead while preserving functionality.
分析并优化用户的CLAUDE.md文件,在保留功能的同时减少上下文开销。
Quick Start
快速开始
- Backup the original file first
- Audit the current state (list all sections with line counts)
- Classify each section using the criteria below
- Propose optimizations with before/after comparison table
- Verify information completeness checklist before executing
- Execute approved changes
- Test that moved content remains discoverable
- 备份原始文件
- 审计当前状态(列出所有章节及行数)
- 分类每个章节(遵循以下标准)
- 提出优化方案,包含前后对比表
- 验证信息完整性清单后再执行更改
- 执行已批准的修改
- 测试已迁移内容的可发现性
Section Classification
章节分类
Analyze each section and classify:
| Category | Criteria | Action |
|---|---|---|
| Keep in CLAUDE.md | Core principles, short rules (<10 lines), frequently needed | Keep as-is |
| Move to references/ | Detailed procedures, code examples, troubleshooting guides | Create |
| Extract to skill | Reusable workflows, scripts, domain-specific knowledge | Create skill in skills repository |
| Remove | Duplicates existing skills, outdated, or unnecessary | Delete after confirmation |
分析每个章节并进行分类:
| 类别 | 判断标准 | 操作 |
|---|---|---|
| 保留在CLAUDE.md中 | 核心原则、简短规则(少于10行)、高频需求内容 | 保持原样 |
| 移至references/ | 详细流程、代码示例、故障排查指南 | 创建 |
| 提取为Skill | 可复用工作流、脚本、领域特定知识 | 在技能仓库中创建Skill |
| 移除 | 与现有Skill重复、过时或非必要内容 | 确认后删除 |
Exceptions to Size Guidelines
篇幅规则的例外情况
Even if a section is >50 lines, KEEP in CLAUDE.md if any of these apply:
| Exception | Reason | Example |
|---|---|---|
| Safety-critical | Consequences of forgetting are severe | Deployment protocols, "never force push to main" |
| High-frequency | Referenced in most conversations | Core development patterns, common commands |
| Easy to violate | Claude tends to ignore when not visible | Code style rules, permission requirements |
| Security-sensitive | Must be always enforced | Production access restrictions, data handling rules |
Rule of thumb: If forgetting the rule could cause production incidents, data loss, or security breaches, keep it visible regardless of length.
即使章节超过50行,若符合以下任一条件,仍需保留在CLAUDE.md中:
| 例外类型 | 原因 | 示例 |
|---|---|---|
| 安全关键型 | 遗忘会导致严重后果 | 部署协议、「禁止强制推送到main分支」 |
| 高频使用型 | 大多数对话中都会引用 | 核心开发模式、常用命令 |
| 易违反型 | Claude未直接可见时容易忽略 | 代码风格规则、权限要求 |
| 安全敏感型 | 必须始终强制执行 | 生产环境访问限制、数据处理规则 |
经验法则:若遗忘规则可能导致生产事故、数据丢失或安全漏洞,无论篇幅长短都需保持可见。
Optimization Workflow
优化工作流
Step 0: Backup Original File
步骤0:备份原始文件
CRITICAL: Always create a backup before any changes.
bash
undefined重要提示:进行任何更改前务必创建备份。
bash
undefinedCreate timestamped backup
创建带时间戳的备份
cp ~/.claude/CLAUDE.md ~/.claude/CLAUDE.md.bak.$(date +%Y%m%d_%H%M%S)
cp ~/.claude/CLAUDE.md ~/.claude/CLAUDE.md.bak.$(date +%Y%m%d_%H%M%S)
For project-level CLAUDE.md
针对项目级CLAUDE.md
cp CLAUDE.md CLAUDE.md.bak.$(date +%Y%m%d_%H%M%S)
If issues found after optimization:
```bashcp CLAUDE.md CLAUDE.md.bak.$(date +%Y%m%d_%H%M%S)
若优化后出现问题:
```bashRestore from backup
从备份恢复
cp ~/.claude/CLAUDE.md.bak.YYYYMMDD_HHMMSS ~/.claude/CLAUDE.md
undefinedcp ~/.claude/CLAUDE.md.bak.YYYYMMDD_HHMMSS ~/.claude/CLAUDE.md
undefinedStep 1: Audit Current State
步骤1:审计当前状态
Task Progress:
- [ ] Create backup (Step 0)
- [ ] Read ~/.claude/CLAUDE.md
- [ ] Count total lines
- [ ] List all ## sections with line counts
- [ ] Identify sections >20 lines任务进度:
- [ ] 创建备份(步骤0)
- [ ] 读取~/.claude/CLAUDE.md
- [ ] 统计总行数
- [ ] 列出所有##章节及行数
- [ ] 识别超过20行的章节Step 2: Classify Each Section
步骤2:分类每个章节
For each section >20 lines, determine:
- Frequency: How often is this information needed?
- Complexity: Does it contain code blocks, tables, or detailed steps?
- Reusability: Could other users benefit from this as a skill?
针对每个超过20行的章节,判断:
- 使用频率:该信息需要多久引用一次?
- 复杂度:是否包含代码块、表格或详细步骤?
- 可复用性:其他用户是否能从该内容中受益并将其作为Skill?
Step 3: Propose Changes
步骤3:提出修改方案
Present optimization plan in this format:
markdown
undefined按以下格式呈现优化计划:
markdown
undefinedOptimization Proposal
优化提案
Current: X lines
After: Y lines (Z% reduction)
| Section | Lines | Action | Destination |
|---|---|---|---|
| Section A | 50 | Move to references | ~/.claude/references/section_a.md |
| Section B | 80 | Extract to skill | skill-name/ |
| Section C | 5 | Keep | - |
undefined当前状态:X行
优化后:Y行(减少Z%)
| 章节 | 行数 | 操作 | 目标位置 |
|---|---|---|---|
| 章节A | 50 | 移至参考文件 | ~/.claude/references/section_a.md |
| 章节B | 80 | 提取为Skill | skill-name/ |
| 章节C | 5 | 保留 | - |
undefinedStep 3.5: Pre-execution Verification Checklist
步骤3.5:执行前验证清单
CRITICAL: Before executing any changes, verify information completeness.
For each section being moved or modified:
-
Extract key items to verify:
- Credentials/passwords/API keys
- Critical rules ("never do X", "always do Y")
- Specific values (ports, IPs, URLs, paths)
- Code snippets that are frequently referenced
- Cross-references to other sections
-
Create verification checklist:markdown
## Verification Checklist for [Section Name] | Key Item | Original Location | New Location | Verified | |----------|-------------------|--------------|----------| | Server IP 47.96.x.x | Line 123 | infrastructure.md:15 | [ ] | | "Never push to main" rule | Line 45 | Kept in CLAUDE.md | [ ] | | Login credentials | Line 200 | api-login.md:30 | [ ] | -
Check cross-references:
- If Section A references Section B, ensure links work after moving
- Update any relative paths to absolute paths if needed
重要提示:执行任何更改前,务必验证信息完整性。
针对每个要迁移或修改的章节:
-
提取关键内容进行验证:
- 凭证/密码/API密钥
- 关键规则(「切勿执行X」、「必须执行Y」)
- 特定值(端口、IP、URL、路径)
- 高频引用的代码片段
- 指向其他章节的交叉引用
-
创建验证清单:markdown
## [章节名称]验证清单 | 关键内容 | 原始位置 | 新位置 | 是否已验证 | |----------|-------------------|--------------|----------| | 服务器IP 47.96.x.x | 第123行 | infrastructure.md:15 | [ ] | | 「禁止推送到main分支」规则 | 第45行 | 保留在CLAUDE.md中 | [ ] | | 登录凭证 | 第200行 | api-login.md:30 | [ ] | -
检查交叉引用:
- 若章节A引用章节B,确保迁移后链接仍可用
- 必要时将相对路径更新为绝对路径
Step 4: Execute Changes
步骤4:执行更改
After user approval AND verification checklist complete:
- Create reference files in
~/.claude/references/ - Update CLAUDE.md with pointers to moved content
- Create skills if applicable
- Verify each checklist item exists in new location
- Report final line count
获得用户批准并完成验证清单后:
- 在中创建参考文件
~/.claude/references/ - 更新CLAUDE.md,添加指向已迁移内容的指针
- 按需创建Skill
- 验证清单中的每个内容项都存在于新位置
- 报告最终行数
Step 5: Post-optimization Testing
步骤5:优化后测试
Verify that Claude can still discover moved content:
-
Test discoverability - Ask questions that require moved content:
Test queries to run: - "How do I connect to the production database?" - "What are the deployment steps for [service]?" - "Show me the credentials for [system]" -
Verify pointer functionality - Each "See" link should work:
reference.mdbash# Check all referenced files exist grep -oh '`~/.claude/references/[^`]*`' ~/.claude/CLAUDE.md | \ sed 's/`//g' | while read f; do eval test -f "$f" && echo "✓ $f" || echo "✗ MISSING: $f" done -
Compare with backup - Ensure no unintended deletions:bash
diff ~/.claude/CLAUDE.md.bak.* ~/.claude/CLAUDE.md | grep "^<" | head -20 -
Document results:markdown
## Optimization Results | Metric | Before | After | |--------|--------|-------| | Total lines | X | Y | | Reduction | - | Z% | | References created | - | N files | | Skills extracted | - | M skills | **Verification**: All N checklist items verified ✓ **Testing**: All K test queries returned correct information ✓
验证Claude仍能发现已迁移的内容:
-
测试可发现性 - 提出需要使用已迁移内容的问题:
建议执行的测试查询: - "我如何连接到生产数据库?" - "[服务]的部署步骤是什么?" - "显示[系统]的凭证" -
验证指针功能 - 每个「查看」链接都应可用:
reference.mdbash# 检查所有引用文件是否存在 grep -oh '`~/.claude/references/[^`]*`' ~/.claude/CLAUDE.md | \ sed 's/`//g' | while read f; do eval test -f "$f" && echo "✓ $f" || echo "✗ 缺失:$f" done -
与备份对比 - 确保没有意外删除内容:bash
diff ~/.claude/CLAUDE.md.bak.* ~/.claude/CLAUDE.md | grep "^<" | head -20 -
记录结果:markdown
## 优化结果 | 指标 | 优化前 | 优化后 | |--------|--------|-------| | 总行数 | X | Y | | 减少比例 | - | Z% | | 创建的参考文件数 | - | N个 | | 提取的Skill数 | - | M个 | **验证**:所有N项清单内容已验证 ✓ **测试**:所有K项测试查询返回正确信息 ✓
Reference File Format
参考文件格式
When moving content to :
~/.claude/references/markdown
undefined将内容移至时遵循以下格式:
~/.claude/references/markdown
undefined[Section Title]
[章节标题]
[Full original content, possibly enhanced with additional examples]
undefined[完整原始内容,可酌情添加更多示例]
undefinedCLAUDE.md Pointer Format
CLAUDE.md指针格式
Replace moved sections with:
markdown
undefined用以下内容替换已迁移的章节:
markdown
undefined[Section Title]
[章节标题]
[One-line summary]. See
~/.claude/references/[filename].mdundefined[一行摘要]。查看
~/.claude/references/[filename].mdundefinedBest Practices
最佳实践
- Keep core principles visible: Rules like "never do X" should stay in CLAUDE.md
- Group related references: Combine small related sections into one reference file
- Preserve quick commands: Keep frequently-used command snippets in CLAUDE.md
- Test after optimization: Ensure Claude can still find moved information
- 核心原则保持可见:类似「切勿执行X」的规则应保留在CLAUDE.md中
- 相关参考内容分组:将小型相关章节合并到一个参考文件中
- 保留快速命令:将高频使用的命令片段保留在CLAUDE.md中
- 优化后测试:确保Claude仍能找到已迁移的信息
Common Patterns
常见模式
Pattern: Infrastructure/Credentials
模式:基础设施/凭证
Before: Full API examples, deployment scripts, server lists
After: One-line pointer to
~/.claude/references/infrastructure.md优化前:完整API示例、部署脚本、服务器列表
优化后:一行指针指向
~/.claude/references/infrastructure.mdPattern: Code Generation Rules
模式:代码生成规则
Before: 50+ lines of coding standards with examples
After: Keep bullet-point rules, move examples to references
优化前:50+行带示例的编码标准
优化后:保留要点规则,将示例移至参考文件
Pattern: Reusable Workflows
模式:可复用工作流
Before: Complete scripts embedded in CLAUDE.md
After: Extract to skill with scripts/ directory
优化前:完整脚本嵌入在CLAUDE.md中
优化后:提取为带scripts/目录的Skill
Project-Level vs User-Level CLAUDE.md
项目级与用户级CLAUDE.md的区别
This skill handles both types, but strategies differ:
本Skill支持两种类型的文件,但策略有所不同:
User-Level (~/.claude/CLAUDE.md
)
~/.claude/CLAUDE.md用户级(~/.claude/CLAUDE.md
)
~/.claude/CLAUDE.md| Aspect | Approach |
|---|---|
| Reference location | |
| Scope | Personal preferences, global rules |
| Sharing | Not shared, personal only |
| Size target | 100-200 lines ideal |
| 维度 | 处理方式 |
|---|---|
| 参考文件位置 | |
| 适用范围 | 个人偏好、全局规则 |
| 共享方式 | 不共享,仅个人使用 |
| 理想篇幅 | 100-200行 |
Project-Level (/path/to/project/CLAUDE.md
)
/path/to/project/CLAUDE.md项目级(/path/to/project/CLAUDE.md
)
/path/to/project/CLAUDE.md| Aspect | Approach |
|---|---|
| Reference location | |
| Scope | Project-specific patterns, architecture |
| Sharing | Committed to git, shared with team |
| Size target | 300-600 lines acceptable (more project context needed) |
| 维度 | 处理方式 |
|---|---|
| 参考文件位置 | 项目根目录下的 |
| 适用范围 | 项目特定模式、架构 |
| 共享方式 | 提交至git,与团队共享 |
| 可接受篇幅 | 300-600行(需更多项目上下文) |
Key Differences
核心差异
- Reference paths: Use relative paths for project-level ()
docs/best-practices/ - Git considerations: Project references are versioned with code
- Team alignment: Project CLAUDE.md should reflect team consensus
- Update frequency: Project-level changes more often as code evolves
- 参考路径:项目级使用相对路径()
docs/best-practices/ - Git考量:项目参考文件随代码版本化
- 团队对齐:项目CLAUDE.md应反映团队共识
- 更新频率:项目级文件随代码演进更频繁更新
Project-Level Pointer Format
项目级指针格式
markdown
undefinedmarkdown
undefined[Section Title]
[章节标题]
[Summary]. See
docs/06-best-practices/[topic].md
**Note**: For project CLAUDE.md, prefer `docs/` over hidden directories for discoverability by human team members.[摘要]。查看
docs/06-best-practices/[topic].md
**注意**:对于项目级CLAUDE.md,优先使用`docs/`而非隐藏目录,以便团队成员更容易发现。Bundled Reference
内置参考文件
- — progressive disclosure の設計原則の詳細
references/progressive_disclosure_principles.md
- — 渐进式披露设计原则的详细内容
references/progressive_disclosure_principles.md