字节笔记本
2026年2月21日
Prompt Coach - Claude Code 使用分析与提示词优化 Skill
本文介绍 Prompt Coach - 一个用于 Claude Code 的使用分析 Skill,它可以分析你的会话日志,提供关于编码模式、Token 使用、生产力和提示词质量的深度洞察。
项目简介
Prompt Coach 是由 hancengiz 开发的开源 Claude Code Skill,目前在 GitHub 上已获得 133 stars。该 Skill 通过读取 ~/.claude/projects/*.jsonl 会话日志文件,帮助开发者:
- ✍️ 提升提示词质量 - 了解你的提示词是否清晰有效
- 🎯 查看真实案例 - 分析日志中实际的模糊提示词,提供改进前后对比
- 💰 计算时间节省 - 了解不清晰提示词的成本(时间 + 迭代次数)
- 📋 获取可操作的模板 - 接收针对常见任务的特定提示词模板
- 🛠️ 优化工具使用 - 发现未充分利用的强大工具
- ⚡ 提升效率 - 了解每个任务需要多少次迭代
- 🕐 找到高效时段 - 了解你最高效的工作时间
- 🔥 识别代码热点 - 查看你最常编辑的文件
- 🔄 减少上下文切换 - 衡量项目切换的开销
- 🐛 从错误中学习 - 了解常见问题和恢复模式
核心特性
1. Token 使用与成本追踪
详细分解 Token 使用情况,包含当前定价计算:
- 输入/输出 Token 统计
- 缓存写入/读取分析
- 成本计算与节省建议
2. 增强的提示词质量分析 ⭐
高级分析功能,能够:
- 检测模糊提示词模式(缺少文件路径、错误详情、成功标准)
- 从你的日志中展示真实案例,显示 Claude 需要询问什么
- 为你实际编写的提示词提供改进前后对比
- 计算不清晰提示词的时间/迭代成本
- 提供按影响排序的可操作模板
- 识别提示词中最常缺少的元素
3. 工具使用模式分析
- 统计你最常/最少使用的工具
- 发现工具使用优化机会
4. 会话效率分析
- 平均每任务迭代次数
- 会话时长与效率评估
5. 生产力时间模式
- 最佳编码时段分析
- 工作日效率对比
6. 文件修改热力图
- 最常编辑的文件统计
- 代码变更模式识别
7. 错误与恢复分析
- 常见错误类型统计
- 错误修复时间分析
8. 项目切换分析
- 上下文切换成本评估
- 多项目工作效率分析
安装指南
快速安装(推荐)
cd ~/code/claude-code-prompt-coach-skill
./install.sh安装脚本会自动:
- ✅ 创建
~/.claude/skills/目录(如需要) - ✅ 检查现有安装
- ✅ 将 Skill 复制到正确位置
- ✅ 验证安装完整性
- ✅ 显示后续步骤
安装完成后,重启 Claude Code 即可使用。
手动安装
cp -r ~/code/claude-code-prompt-coach-skill ~/.claude/skills/prompt-coach开发模式(符号链接)
ln -s ~/code/claude-code-prompt-coach-skill ~/.claude/skills/prompt-coach使用符号链接可以在编辑 Skill.md 后立即生效(下次重启 Claude Code 时)。
使用方法
重要提示:此 Skill 仅分析当前机器的日志,只能访问本地存储在 ~/.claude/projects/ 的 Claude Code 会话日志。
选项 1:分析所有项目
直接向 Claude 询问关于你的使用情况的自然语言问题:
"How much have I spent on tokens this month?"
"Analyze my prompt quality from last week"
"Which tools do I use most?"
"Show me my productivity patterns"
"What files do I edit most often?"
"When am I most efficient?"Claude 将自动读取所有会话日志并提供详细分析。
选项 2:先列出项目,然后选择
如果你想查看有哪些项目日志并选择分析:
"List all projects with Claude Code logs"
"Show me which projects I've worked on"
"What projects do I have session logs for?"Claude 会显示所有可用项目及其详情(会话数、日期范围、大小),你可以选择要分析的项目。
选项 3:分析特定项目
如果你知道项目路径,可以仅分析该项目:
"Analyze my prompt quality for the project under ~/code/youtube/transcript/mcp"
"Analyze my prompt quality for /Users/username/code/my-app and save it as report.md"
"Show me token usage for the project in ~/code/experiments"
"What tools do I use most in the ~/code/my-app project?"这将仅分析该特定项目的日志,提供更有针对性的洞察。
示例输出
Token 使用分析
📊 Token Usage Analysis (Last 30 Days)
Input tokens: 450,000 ($1.35)
Output tokens: 125,000 ($1.88)
Cache writes: 200,000 ($0.75)
Cache reads: 1,500,000 ($0.45)
─────────────────
Total cost: $4.43
Cache savings: $4.05
Cache efficiency: 75% hit rate
💡 Tip: Your cache hit rate is excellent! You're saving ~$4/month by keeping focused sessions.提示词质量分析
📝 Prompt Quality Analysis (Last 14 Days)
Total prompts: 145
Needed clarification: 51 (35%)
Average prompt score: 5.2/10 (Good, room for improvement)
🚩 Most Common Missing Elements:
1. File paths: Missing in 61 prompts (42%)
2. Error details: Missing in 34 prompts (23%)
3. Success criteria: Missing in 43 prompts (30%)
4. Specific approach: Missing in 28 prompts (19%)
🔴 Real Examples from Your Logs:
**Example 1: Missing File Context**
❌ Your prompt: "fix the bug"
🤔 Claude asked: "Which file has the bug? What's the error message or symptom?"
✅ Better prompt: "fix the authentication bug in src/auth/login.ts where JWT validation fails with 401 error"
📉 Cost: +2 minutes, +1 iteration
📉 Impact Analysis:
- 51 prompts needed clarification
- Average time lost per clarification: 2.8 minutes
- Total time lost to vague prompts: ~2.4 hours
- **Potential time savings: ~1.2 hours by improving top 25 vague prompts**
🎯 Your Top 3 Improvements (Maximum Impact):
**1. Always Include File Paths (42% of clarifications)**
Template: "[action] in [file path] [details]"
💰 Impact: Would eliminate ~21 clarifications (~1 hour saved)
**2. Provide Error Details When Debugging (23% of clarifications)**
Template: "fix [error message] in [file] - expected [X], getting [Y]"
💰 Impact: Would eliminate ~12 clarifications (~25 min saved)
**3. Define Success Criteria for Vague Actions (30% of clarifications)**
Instead of: "optimize", "improve", "make better"
Use: "[action] to achieve [specific measurable outcome]"
💰 Impact: Would eliminate ~15 clarifications (~40 min saved)工具使用模式
🛠️ Tool Usage Patterns (Last 30 Days)
Most used tools:
1. Read ████████████████████ 450 uses
2. Edit ████████████ 220 uses
3. Bash ███████ 150 uses
4. Grep ██ 34 uses
💡 Insights:
✅ Good: You use Read heavily - shows careful code review
⚠️ Opportunity: Low Grep usage (34 uses vs 450 Reads)
→ Try Grep for searching across multiple files
→ It's much faster than reading each file工作原理
该 Skill 为 Claude 提供:
- 官方 Claude 提示词工程最佳实践 - 来自 Anthropic 文档
- 日志存储位置知识 -
~/.claude/projects/ - JSONL 日志格式理解
- 提示词质量评分系统 - 清晰度、具体性、可操作性、范围(各 0-10 分)
- 查找模式 - 工具使用、Token、时间戳等
- 指标计算方法
- 洞察展示模板
然后 Claude 使用其内置工具(Read、Bash、Grep)来:
- 查找并读取日志文件
- 解析 JSON 数据
- 根据官方最佳实践评分提示词
- 计算指标
- 生成个性化、可操作的洞察
无需外部依赖,无需安装,数据不会离开你的机器。
提示词工程知识
该 Skill 基于官方 Claude 提示词工程指南训练,包括:
黄金法则
"将你的提示词展示给了解最少背景的同事。如果他们感到困惑,Claude 很可能也会。"
提示词工程层次结构(最有效的方法)
| 优先级 | 技巧 | 说明 |
|---|---|---|
| ⭐ | 清晰直接 | 最有效 |
| 使用示例(多轮) | 展示期望输出 | |
| 让 Claude 思考 | 思维链推理 | |
| 使用 XML 标签 | 结构化清晰 | |
| 给 Claude 设定角色 | 设置上下文 | |
| 预填充回复 | 引导输出格式 | |
| 链式复杂提示词 | 分解为步骤 |
隐私保护
- ✅ 所有数据保留在本地机器
- ✅ 不调用外部服务
- ✅ 无跟踪或分析
- ✅ 你控制 Skill 文件
自定义扩展
想要添加自己的分析类型?只需编辑 Skill.md 并添加:
### 9. Your Custom Analysis
**When asked about [your topic]:**
**Steps:**
1. Read session files
2. Look for [pattern]
3. Calculate [metric]
4. Present [insights]项目链接
- GitHub 仓库: https://github.com/hancengiz/claude-code-prompt-coach-skill
- 作者博客: https://www.cengizhan.com/p/claude-code-prompt-coach-skill-to
总结
Prompt Coach 是一个强大的 Claude Code Skill,它不仅能帮你分析和优化使用习惯,还能教你写出更好的提示词。通过分析真实的会话数据,它提供了具体的、可操作的改进建议,帮助你提升效率、节省时间。对于经常使用 Claude Code 的开发者来说,这是一个不可或缺的工具。