promote

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

/si:promote — Graduate Learnings to Rules

/si:promote — 将经验总结升级为规则

Moves a proven pattern from Claude's auto-memory into the project's rule system, where it becomes an enforced instruction rather than a background note.
将Claude自动记忆中经过验证的模式迁移到项目的规则系统中,使其成为强制执行的指令,而非仅作为背景备注。

Usage

使用方法

/si:promote <pattern description>                    # Auto-detect best target
/si:promote <pattern> --target claude.md             # Promote to CLAUDE.md
/si:promote <pattern> --target rules/testing.md      # Promote to scoped rule
/si:promote <pattern> --target rules/api.md --paths "src/api/**/*.ts"  # Scoped with paths
/si:promote <模式描述>                    # 自动检测最佳目标位置
/si:promote <模式> --target claude.md             # 升级到CLAUDE.md
/si:promote <模式> --target rules/testing.md      # 升级到特定领域规则文件
/si:promote <模式> --target rules/api.md --paths "src/api/**/*.ts"  # 带路径范围的领域规则

Workflow

工作流程

Step 1: Understand the pattern

步骤1:理解模式内容

Parse the user's description. If vague, ask one clarifying question:
  • "What specific behavior should Claude follow?"
  • "Does this apply to all files or specific paths?"
解析用户的描述。如果描述模糊,提出一个澄清问题:
  • “Claude需要遵循的具体行为是什么?”
  • “这适用于所有文件还是特定路径?”

Step 2: Find the pattern in auto-memory

步骤2:在自动记忆中查找模式

bash
undefined
bash
undefined

Search MEMORY.md for related entries

在MEMORY.md中搜索相关条目

MEMORY_DIR="$HOME/.claude/projects/$(pwd | sed 's|/|%2F|g; s|%2F|/|; s|^/||')/memory" grep -ni "<keywords>" "$MEMORY_DIR/MEMORY.md"

Show the matching entries and confirm they're what the user means.
MEMORY_DIR="$HOME/.claude/projects/$(pwd | sed 's|/|%2F|g; s|%2F|/|; s|^/||')/memory" grep -ni "<关键词>" "$MEMORY_DIR/MEMORY.md"

展示匹配的条目并确认是否符合用户需求。

Step 3: Determine the right target

步骤3:确定合适的目标位置

Pattern scopeTargetExample
Applies to entire project
./CLAUDE.md
"Use pnpm, not npm"
Applies to specific file types
.claude/rules/<topic>.md
"API handlers need validation"
Applies to all your projects
~/.claude/CLAUDE.md
"Prefer explicit error handling"
If the user didn't specify a target, recommend one based on scope.
模式适用范围目标位置示例
适用于整个项目
./CLAUDE.md
"使用pnpm,而非npm"
适用于特定文件类型
.claude/rules/<主题>.md
"API处理器需要验证"
适用于所有你的项目
~/.claude/CLAUDE.md
"优先使用显式错误处理"
如果用户未指定目标位置,根据适用范围推荐合适的选项。

Step 4: Distill into a concise rule

步骤4:提炼为简洁规则

Transform the learning from auto-memory's note format into CLAUDE.md's instruction format:
Before (MEMORY.md — descriptive):
The project uses pnpm workspaces. When I tried npm install it failed. The lock file is pnpm-lock.yaml. Must use pnpm install for dependencies.
After (CLAUDE.md — prescriptive):
markdown
undefined
将自动记忆中的笔记格式转换为CLAUDE.md的指令格式:
转换前(MEMORY.md — 描述性内容):
该项目使用pnpm工作区。我尝试用npm install时失败了。锁文件是pnpm-lock.yaml。必须使用pnpm install来安装依赖。
转换后(CLAUDE.md — 指令性内容):
markdown
undefined

Build & Dependencies

构建与依赖

  • Package manager: pnpm (not npm). Use
    pnpm install
    .

**Rules for distillation:**
- One line per rule when possible
- Imperative voice ("Use X", "Always Y", "Never Z")
- Include the command or example, not just the concept
- No backstory — just the instruction
  • 包管理器:pnpm(而非npm)。使用
    pnpm install
    命令。

**提炼规则:**
- 尽可能每条规则占一行
- 使用祈使语气(“使用X”、“始终Y”、“禁止Z”)
- 包含具体命令或示例,而非仅概念
- 无需背景说明 — 只保留指令内容

Step 5: Write to target

步骤5:写入目标文件

For CLAUDE.md:
  1. Read existing CLAUDE.md
  2. Find the appropriate section (or create one)
  3. Append the new rule under the right heading
  4. If file would exceed 200 lines, suggest using
    .claude/rules/
    instead
For
.claude/rules/
:
  1. Create the file if it doesn't exist
  2. Add YAML frontmatter with
    paths
    if scoped
  3. Write the rule content
markdown
---
paths:
  - "src/api/**/*.ts"
  - "tests/api/**/*"
---
对于CLAUDE.md:
  1. 读取现有CLAUDE.md内容
  2. 找到合适的章节(或新建章节)
  3. 在对应标题下添加新规则
  4. 如果文件行数将超过200行,建议改用
    .claude/rules/
    目录
对于
.claude/rules/
  1. 如果文件不存在则创建
  2. 如果有范围限制,添加带
    paths
    的YAML前置内容
  3. 写入规则内容
markdown
---
paths:
  - "src/api/**/*.ts"
  - "tests/api/**/*"
---

API Development Rules

API开发规则

  • All endpoints must validate input with Zod schemas
  • Use
    ApiError
    class for error responses (not raw Error)
  • Include OpenAPI JSDoc comments on handler functions
undefined
  • 所有端点必须使用Zod schema验证输入
  • 错误响应使用
    ApiError
    类(而非原生Error)
  • 处理器函数需包含OpenAPI JSDoc注释
undefined

Step 6: Clean up auto-memory

步骤6:清理自动记忆

After promoting, remove or mark the original entry in MEMORY.md:
bash
undefined
完成升级后,移除或标记MEMORY.md中的原始条目:
bash
undefined

Show what will be removed

展示即将移除的内容

grep -n "<pattern>" "$MEMORY_DIR/MEMORY.md"

Ask the user to confirm removal. Then edit MEMORY.md to remove the promoted entry. This frees space for new learnings.
grep -n "<模式内容>" "$MEMORY_DIR/MEMORY.md"

请求用户确认移除操作。然后编辑MEMORY.md删除已升级的条目,为新的经验总结腾出空间。

Step 7: Confirm

步骤7:确认完成

✅ Promoted to {{target}}

Rule: "{{distilled rule}}"
Source: MEMORY.md line {{n}} (removed)
MEMORY.md: {{lines}}/200 lines remaining

The pattern is now an enforced instruction. Claude will follow it in all future sessions.
✅ 已升级至 {{目标位置}}

规则:"{{提炼后的规则}}"
来源:MEMORY.md第{{n}}行(已移除)
MEMORY.md:剩余{{lines}}/200行

该模式现已成为强制执行的指令。Claude在未来所有会话中都会遵循此规则。

Promotion Decision Guide

升级决策指南

Promote when:

建议升级的情况:

  • Pattern appeared 3+ times in auto-memory
  • You corrected Claude about it more than once
  • It's a project convention that any contributor should know
  • It prevents a recurring mistake
  • 模式在自动记忆中出现3次以上
  • 你已经纠正Claude相关问题超过一次
  • 这是所有贡献者都应了解的项目约定
  • 它可以防止重复出现的错误

Don't promote when:

不建议升级的情况:

  • It's a one-time debugging note (leave in auto-memory)
  • It's session-specific context (session memory handles this)
  • It might change soon (e.g., during a migration)
  • It's already covered by existing rules
  • 这是一次性调试笔记(保留在自动记忆中即可)
  • 这是会话特定的上下文(会话记忆会处理此类内容)
  • 它可能很快发生变化(例如在迁移期间)
  • 现有规则已涵盖相关内容

CLAUDE.md vs .claude/rules/

CLAUDE.md 对比 .claude/rules/

Use CLAUDE.md forUse .claude/rules/ for
Global project rulesFile-type-specific patterns
Build commandsTesting conventions
Architecture decisionsAPI design rules
Team conventionsFramework-specific gotchas
适合CLAUDE.md的场景适合.claude/rules/的场景
全局项目规则特定文件类型的模式
构建命令测试约定
架构决策API设计规则
团队约定框架特定注意事项

Tips

提示

  • Keep CLAUDE.md under 200 lines — use rules/ for overflow
  • One rule per line is easier to maintain than paragraphs
  • Include the concrete command, not just the concept
  • Review promoted rules quarterly — remove what's no longer relevant
  • 保持CLAUDE.md在200行以内 — 超出部分使用rules/目录
  • 每条规则占一行比段落更易于维护
  • 包含具体命令,而非仅概念
  • 每季度回顾已升级的规则 — 移除不再相关的内容