lessons

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Lessons Learned

编码经验教训记录

Capture insights and learn from past experiences.
留存编码见解,从过往经验中学习提升。

Capture Patterns

经验记录模式

Quick Lesson Capture

快速记录经验

When you learn something valuable during a session:
bash
undefined
当你在编码过程中学到有价值的内容时:
bash
undefined

Write to lessons file

Write to lessons file

cat >> ~/.claude/lessons.md << 'EOF'
cat >> ~/.claude/lessons.md << 'EOF'

[Date] - [Topic]

[Date] - [Topic]

Context: What were you doing? Lesson: What did you learn? Application: When to apply this?
EOF
undefined
Context: What were you doing? Lesson: What did you learn? Application: When to apply this?
EOF
undefined

Structured Lesson

结构化经验记录

markdown
undefined
markdown
undefined

2024-01-15 - TypeScript Generic Constraints

2024-01-15 - TypeScript Generic Constraints

Context: Building a type-safe form library, struggled with generic types.
Problem: Generic function wasn't narrowing types correctly.
Solution: Use
extends
constraints to narrow:
typescript
function getValue<T extends { value: unknown }>(obj: T): T['value'] {
  return obj.value;
}
Lesson: TypeScript generics need explicit constraints for type narrowing.
Tags: #typescript #generics #types
undefined
场景: 构建类型安全的表单库时,在泛型类型使用上遇到困难。
问题: 泛型函数无法正确地缩小类型范围。
解决方案: 使用
extends
约束来缩小类型范围:
typescript
function getValue<T extends { value: unknown }>(obj: T): T['value'] {
  return obj.value;
}
经验总结: TypeScript 泛型需要显式约束才能实现类型缩小。
标签: #typescript #generics #types
undefined

Lesson Categories

经验分类记录

Bug Lessons

Bug经验记录

markdown
undefined
markdown
undefined

Bug: [Brief description]

Bug: [简要描述]

Symptom: What happened Root Cause: Why it happened Fix: How to fix Prevention: How to avoid in future Time Cost: How long to debug (motivation to remember!)
undefined
症状: 发生了什么问题 根本原因: 问题产生的原因 修复方案: 如何修复 预防措施: 未来如何避免 时间成本: 调试耗时(提醒自己牢记的动力!)
undefined

Pattern Lessons

模式经验记录

markdown
undefined
markdown
undefined

Pattern: [Name]

模式:[名称]

When to use: Situations where this applies How to implement: Basic structure Gotchas: Common mistakes Example: Working code
undefined
适用场景: 该模式的适用情况 实现方式: 基础结构 注意事项: 常见误区 示例: 可运行代码
undefined

Tool Lessons

工具经验记录

markdown
undefined
markdown
undefined

Tool: [Name]

工具:[名称]

What it does: Brief description Key commands: Most useful commands Gotchas: Things that trip people up Alternatives: Other options
undefined
功能介绍: 简要描述 核心命令: 最实用的命令 注意事项: 容易踩坑的点 替代方案: 其他可选工具
undefined

Review Practices

回顾实践

Daily Review

每日回顾

bash
undefined
bash
undefined

Review recent lessons

Review recent lessons

tail -100 ~/.claude/lessons.md
tail -100 ~/.claude/lessons.md

Search for topic

Search for topic

grep -A 10 "typescript" ~/.claude/lessons.md
undefined
grep -A 10 "typescript" ~/.claude/lessons.md
undefined

Weekly Audit

每周审计

bash
gemini -m pro -o text -e "" "Review these lessons from the past week:

$(tail -500 ~/.claude/lessons.md)

1. What patterns emerge?
2. What mistakes keep recurring?
3. What should be turned into automation?
4. What needs deeper study?"
bash
gemini -m pro -o text -e "" "Review these lessons from the past week:

$(tail -500 ~/.claude/lessons.md)

1. What patterns emerge?
2. What mistakes keep recurring?
3. What should be turned into automation?
4. What needs deeper study?"

Before Starting Work

工作前置回顾

bash
undefined
bash
undefined

Get relevant lessons

Get relevant lessons

TOPIC="authentication" grep -B 2 -A 10 -i "$TOPIC" ~/.claude/lessons.md
undefined
TOPIC="authentication" grep -B 2 -A 10 -i "$TOPIC" ~/.claude/lessons.md
undefined

Automation from Lessons

经验转化为自动化

When a lesson appears multiple times, automate it:
当某条经验多次出现时,将其转化为自动化工具:

Create Git Hook

创建Git钩子

bash
undefined
bash
undefined

Lesson: Always run tests before commit

Lesson: Always run tests before commit

→ Create pre-commit hook

→ Create pre-commit hook

cat > .git/hooks/pre-commit << 'EOF' #!/bin/bash npm test || exit 1 EOF chmod +x .git/hooks/pre-commit
undefined
cat > .git/hooks/pre-commit << 'EOF' #!/bin/bash npm test || exit 1 EOF chmod +x .git/hooks/pre-commit
undefined

Create Snippet

创建代码片段

bash
undefined
bash
undefined

Lesson: This pattern is useful

Lesson: This pattern is useful

→ Save as snippet

→ Save as snippet

cat > ~/.claude/snippets/async-error-handling.ts << 'EOF' async function safeAsync<T>(promise: Promise<T>): Promise<[T, null] | [null, Error]> { try { const result = await promise; return [result, null]; } catch (error) { return [null, error as Error]; } } EOF
undefined
cat > ~/.claude/snippets/async-error-handling.ts << 'EOF' async function safeAsync<T>(promise: Promise<T>): Promise<[T, null] | [null, Error]> { try { const result = await promise; return [result, null]; } catch (error) { return [null, error as Error]; } } EOF
undefined

Create Checklist

创建检查清单

bash
undefined
bash
undefined

Lesson: Keep forgetting these steps

Lesson: Keep forgetting these steps

→ Create checklist

→ Create checklist

cat > ~/.claude/checklists/pr-review.md << 'EOF'
cat > ~/.claude/checklists/pr-review.md << 'EOF'

PR Review Checklist

PR Review Checklist

  • Tests pass
  • No console.logs
  • Types are explicit
  • Error handling present
  • Documentation updated EOF
undefined
  • Tests pass
  • No console.logs
  • Types are explicit
  • Error handling present
  • Documentation updated EOF
undefined

AI-Assisted Learning

AI辅助学习

Extract Lessons from Session

从会话中提取经验

bash
gemini -m pro -o text -e "" "Extract lessons learned from this coding session:

[Paste conversation or summary]

For each lesson:
1. What was learned
2. When it applies
3. How to remember it"
bash
gemini -m pro -o text -e "" "Extract lessons learned from this coding session:

[Paste conversation or summary]

For each lesson:
1. What was learned
2. When it applies
3. How to remember it"

Connect Lessons

关联经验

bash
gemini -m pro -o text -e "" "Find connections between these lessons:

$(cat ~/.claude/lessons.md)

1. What themes emerge?
2. What knowledge gaps exist?
3. What should be studied next?"
bash
gemini -m pro -o text -e "" "Find connections between these lessons:

$(cat ~/.claude/lessons.md)

1. What themes emerge?
2. What knowledge gaps exist?
3. What should be studied next?"

Generate Quiz

生成测试题

bash
gemini -m pro -o text -e "" "Create a quiz from these lessons:

$(tail -1000 ~/.claude/lessons.md)

Generate 5 questions that test understanding of key concepts."
bash
gemini -m pro -o text -e "" "Create a quiz from these lessons:

$(tail -1000 ~/.claude/lessons.md)

Generate 5 questions that test understanding of key concepts."

Storage Options

存储方案

File-based

文件存储

bash
undefined
bash
undefined

Single file

Single file

~/.claude/lessons.md
~/.claude/lessons.md

By date

By date

~/.claude/lessons/2024-01.md
~/.claude/lessons/2024-01.md

By topic

By topic

~/.claude/lessons/typescript.md ~/.claude/lessons/git.md
undefined
~/.claude/lessons/typescript.md ~/.claude/lessons/git.md
undefined

Memory Integration

记忆库集成

bash
undefined
bash
undefined

Save to basic-memory

Save to basic-memory

basic-memory tool write-note
--title "Lesson: TypeScript Generics"
--folder "lessons"
--content "$(cat lesson.md)"
--tags "lesson,typescript"
undefined
basic-memory tool write-note
--title "Lesson: TypeScript Generics"
--folder "lessons"
--content "$(cat lesson.md)"
--tags "lesson,typescript"
undefined

Best Practices

最佳实践

  1. Capture immediately - Don't wait, you'll forget
  2. Be specific - Include code examples
  3. Note the cost - Time spent motivates remembering
  4. Review regularly - Lessons fade without review
  5. Automate repeated - Turn lessons into tools
  6. Tag consistently - Makes searching easier
  7. Connect to context - When does this apply?
  1. 即时记录 - 不要拖延,否则会遗忘
  2. 内容具体 - 附上代码示例
  3. 记录成本 - 耗时记录能提醒自己牢记
  4. 定期回顾 - 不回顾的经验会被遗忘
  5. 自动化重复经验 - 将经验转化为工具
  6. 统一标签 - 便于搜索
  7. 关联场景 - 明确适用时机