Skill站外收录 @skilllib/skill-2117939930272410686
session-reflection-analysis
分析项目会话历史,识别重复操作、路径偏差与上下文浪费等低效模式,提炼为可落地的文档改进、自动化脚本及工作流优化方案,降低后续交互的 token 消耗并提升执行效率。
商业与营销 AI 技能
Skills.MD
# Session Reflection Analysis
Analyze recent chat history to identify improvement opportunities and reduce token waste in future sessions.
## Overview
This skill helps identify patterns of inefficiency in Claude Code sessions by analyzing session history. The analysis focuses on actionable improvements to documentation, automation, and workflows.
## Step 1: Locate Project Sessions
First, find the correct project folder. Claude Code stores sessions at `~/.claude/projects/` with folder names derived from the project path (slashes become dashes, colons become double-dashes).
```bash
# List available project folders
ls -la ~/.claude/projects/
# Find the current project's session folder by matching the working directory
# Example: /Users/harper/src/myproject -> -Users-harper-src-myproject
CURRENT_PATH=$(pwd | sed 's|^/||; s|/|-|g')
PROJECT_DIR="$HOME/.claude/projects/-${CURRENT_PATH}"
# Verify it exists
if [ -d "$PROJECT_DIR" ]; then
echo "Found project dir: $PROJECT_DIR"
ls -la "$PROJECT_DIR"/*.jsonl 2>/dev/null | head -5
else
echo "No session folder found for current project"
echo "Available projects:"
ls ~/.claude/projects/
fi
```
## Step 2: Generate Session Summary
**CRITICAL**: Do NOT read raw session files directly. They are massive and will consume your entire token budget.
First, verify `jq` is available:
```bash
if ! command -v jq &> /dev/null; then
echo "ERROR: jq is required but not installed"
echo "Install with: brew install jq (macOS) or apt install jq (Linux)"
exit 1
fi
```
Then use jq to generate a 98% token-reduced summary:
```bash
# Set project dir (adjust if auto-detection didn't work)
PROJECT_DIR="$HOME/.claude/projects/-Users-harper-Public-src-2389-matrix-productivity" # Update this path!
OUTPUT="/tmp/session-summary.jsonl"
# Optional: Only analyze sessions from last N days
DAYS_BACK=7
CUTOFF_DATE=$(date -v-${DAYS_BACK}d +%Y-%m-%d 2>/dev/null || date -d "${DAYS_BACK} days ago" +%Y-%m-%d)
# Summarize: extract user requests, tool names, assistant text (truncated)
cat "$PROJECT_DIR"/*.jsonl 2>/dev/null | jq -c '
select(.type == "user" or .type == "assistant") |
{
type,
ts: .timestamp,
content: (
if .message.content | type == "string" then
.message.content[0:300]
elif .message.content | type == "array" then
[.message.content[] |
if .type == "text" then {t: "text", v: .text[0:300]}
elif .type == "tool_use" then {t: "tool", v: .name}
elif .type == "tool_result" then {t: "result", len: (.content | length)}
elif .type == "thinking" then empty
else {t: .type}
end
]
else null
end
)
}' > "$OUTPUT" 2>/dev/null
echo "Summary: $(wc -l < "$OUTPUT") messages, $(wc -c < "$OUTPUT" | xargs) bytes"
```
This extracts:
- User message text (first 300 chars)
- Tool calls (name only, not full output)
- Tool result sizes (not content)
- Timestamps for sequence analysis
## Step 3: Launch Subagent for Analysis
Use the Task tool to spawn an analysis subagent:
```
Task tool parameters:
- subagent_type: "Explore"
- prompt: |
Analyze the session summary at /tmp/session-summary.jsonl for inefficiency patterns.
Read the file and look for these patterns:
| Pattern | Example | Impact |
|---------|---------|--------|
| **Wasted tokens** | Re-reading same file 5+ times | High |
| **Wrong paths taken** | Implemented feature, then discovered existing code | Medium-High |
| **Repeated mistakes** | Same error type in 3+ instances | Medium |
| **Missing automation** | Manual steps repeated across sessions | Medium |
| **Missing documentation** | Had to figure out what should be in CLAUDE.md | Medium |
| **Unnecessary tool calls** | Called multiple tools when one would work | Low-Medium |
| **Context loss after compaction** | Info that should survive in persistent docs | High |
| **Assumption without verification** | Decisions made without checking existing code | High |
For each pattern found, propose improvements as:
1. CLAUDE.md updates
2. New skills for .claude/skills/
3. New slash commands for .claude/commands/
4. Script automation
5. Git hooks
6. Workflow changes
Make all proposals copy-paste ready with complete text/code.
Quantify impact where possible (tokens saved, time saved).
Be specific with examples from the actual session data.
```
## Step 4: Create Reflection Document
The subagent should generate a document with this structure:
```markdown
# Session Reflection: YYYY-MM-DD
## Summary Statistics
- Session date range: [start] to [end]
- Messages analyzed: [count]
- Major inefficiencies found: [count]
## Proposed Improvements
### High Priority
#### 1. [Problem Title]
**Problem observed**: [What went wrong - be specific with examples]
**Proposed solution**:
```
[Complete text/code to add or change - copy-paste ready]
```
**File to modify**: `path/to/file.md`
**Cost**: [Effort to implement, any downsides]
**Benefit**: [Time/tokens saved - quantify if possible]
---
### Medium Priority
...
### Low Priority
...
## Implementation Notes
[Cross-cutting concerns, dependencies, warnings]
```
## Step 5: Present Findings
After analysis completes:
1. **Summarize key findings** - 3-5 bullet points of major inefficiencies
2. **Show the reflection document path** - Where to find full details
3. **Ask which changes to implement** - Don't auto-implement
## Critical Rules
1. **NEVER read raw session files directly** - Always use the jq summary
2. **NEVER implement changes automatically** - Only propose them
3. **Make proposals copy-paste ready** - Complete text, not descriptions
4. **Quantify impact when possible** - "Saved 10K tokens" not "saves tokens"
5. **Be specific with examples** - "Re-read config.py 7 times" not "read files multiple times"
## Example Analysis Output
```
High Priority Issues Found:
1. **Re-reading the same file repeatedly** (7 times in one session)
- Propose: Add key architecture summaries to CLAUDE.md
- Benefit: Save ~15K tokens per session
2. **Implemented feature without checking existing code first**
- Took 3 iterations to match actual behavior
- Propose: Add "Check existing code FIRST" rule to CLAUDE.md
- Benefit: Prevent wrong-path implementations
3. **Manual repetitive commands**
- Same shell commands typed each session
- Propose: Create slash commands for common operations
- Benefit: Save 2-3 minutes per session, prevent typos
```
## Troubleshooting
### Can't find project folder
```bash
# List all projects with recent activity
ls -lt ~/.claude/projects/ | head -10
# Search for a keyword in project names
ls ~/.claude/projects/ | grep -i "keyword"
```
### No jsonl files found
Sessions may not have been saved yet, or the project path detection failed. Check the folder manually.
### jq not installed
```bash
# macOS
brew install jq
# Ubuntu/Debian
sudo apt install jq
# Or use the standalone binary
curl -Lo /usr/local/bin/jq https://github.com/jqlang/jq/releases/download/jq-1.7.1/jq-macos-arm64
chmod +x /usr/local/bin/jq
```
评论 0
还没有评论,来抢沙发。
相关内容
同类或同场景的收录内容
building-with-kafka-strimzi
在 Kubernetes 上构建基于 Apache Kafka 的事件驱动系统,支持高可靠的消息传递、事务性处理与精确一次语义,结合 Strimzi 运营商实现集群自动化管理,利用 Schema Registry 保障事件模式演进,适用于微服务间解耦通信与实时数据流处理场景。
站外数据与分析
609 0.0
personal-tool-builder
专注于从个人真实痛点出发快速构建实用工具,涵盖命令行程序、本地优先应用和自动化脚本的开发与演进,强调先满足自身需求再逐步扩展,通过持续自用打磨功能,避免过度设计,确保工具简洁有效且长期可维护。
站外商业与营销
196 0.0
threejs-lighting
实现三维场景中的光照与阴影控制,支持多种光源类型及环境光照明,提供从基础布光到高级阴影优化的完整方案,适用于需要真实感渲染或性能平衡的可视化项目。
站外效率工具
442 0.0
aggregation-helper
提供数据聚合场景的自动化辅助能力,涵盖 SQL 查询编写、统计分析建模、可视化方案设计及商业智能配置,支持从需求理解到生产级代码生成的全流程指导。
站外效率工具数据与分析
217 0.0
举报「session-reflection-analysis」
举报信息仅审核团队可见,同一资产 24 小时内仅可举报一次