File contents Context efficiency report
Analyze the Claude Code JSONL session data for the current project to generate a context efficiency report.
When to invoke
When reviewing Claude Code session efficiency
To understand model usage patterns
When optimizing for cost reduction
After completing a project to review usage
Instructions
Project path detection
The current working directory is: $ARGUMENTS (if provided) or $CWD
Convert the path to the Claude projects folder format:
Replace / with -
The projects folder is at: ~/.dotfiles/claude.symlink/projects/
Analysis script
Run this analysis for the current project:
#!/bin/bash
CWD="${ARGUMENTS:-$(pwd)}"
PROJECT_KEY=$(echo "$CWD" | sed 's|/|-|g; s|\.|-|g')
PROJECTS_BASE="$HOME/.dotfiles/claude.symlink/projects"
PROJECT_DIR="$PROJECTS_BASE/$PROJECT_KEY"
if [ ! -d "$PROJECT_DIR" ]; then
echo "No session data found for: $CWD"
echo "Looking in: $PROJECT_DIR"
exit 1
fi
echo "╔══════════════════════════════════════════════════════════════════╗"
echo "║ Context Efficiency Report: $(basename "$CWD" | head -c 20)"
echo "╚══════════════════════════════════════════════════════════════════╝"
echo "Project: $CWD"
echo ""
# Session counts
session_count=$(find "$PROJECT_DIR" -maxdepth 1 -name "*.jsonl" ! -name "agent-*.jsonl" 2>/dev/null | wc -l | tr -d ' ')
agent_count=$(find "$PROJECT_DIR" -maxdepth 1 -name "agent-*.jsonl" 2>/dev/null | wc -l | tr -d ' ')
echo "📁 SESSIONS"
echo "────────────────────────────────────────────────────────────────────"
echo "Main Sessions: $session_count"
echo "Agent Sessions: $agent_count"
if [ "$session_count" -gt 0 ]; then
ratio=$(echo "scale=2; $agent_count / $session_count" | bc)
echo "Delegation Ratio: ${ratio}:1"
fi
echo ""
# Model usage
echo "🤖 MODEL USAGE"
echo "────────────────────────────────────────────────────────────────────"
find "$PROJECT_DIR" -maxdepth 1 -name "*.jsonl" -size +1k -exec cat {} + 2>/dev/null | \
jq -r 'select(.message.model != null) | .message.model' 2>/dev/null | \
sort | uniq -c | sort -rn
echo ""
# Tool usage
echo "🔧 TOOL USAGE"
echo "────────────────────────────────────────────────────────────────────"
find "$PROJECT_DIR" -maxdepth 1 -name "*.jsonl" -size +1k -exec cat {} + 2>/dev/null | \
jq -r '.message.content[]? | select(.type == "tool_use") | .name' 2>/dev/null | \
sort | uniq -c | sort -rn | head -15
echo ""
# Size
echo "📊 DATA SIZE"
echo "────────────────────────────────────────────────────────────────────"
total_size=$(du -sh "$PROJECT_DIR" 2>/dev/null | cut -f1)
msg_count=$(find "$PROJECT_DIR" -maxdepth 1 -name "*.jsonl" -exec cat {} + 2>/dev/null | wc -l | tr -d ' ')
echo "Total Size: $total_size"
echo "Message Records: $msg_count"
echo ""
# Collect tool data once
all_tools=$(find "$PROJECT_DIR" -maxdepth 1 -name "*.jsonl" -size +1k -exec cat {} + 2>/dev/null | jq -r '.message.content[]? | select(.type == "tool_use") | .name' 2>/dev/null)
all_models=$(find "$PROJECT_DIR" -maxdepth 1 -name "*.jsonl" -size +1k -exec cat {} + 2>/dev/null | jq -r '.message.model // empty' 2>/dev/null)
# Model counts
opus=$(echo "$all_models" | grep -c "opus" || echo 0)
sonnet=$(echo "$all_models" | grep -c "sonnet" || echo 0)
haiku=$(echo "$all_models" | grep -c "haiku" || echo 0)
model_total=$((opus + sonnet + haiku))
# Tool counts
bash_count=$(echo "$all_tools" | grep -c "^Bash$" || echo 0)
grep_count=$(echo "$all_tools" | grep -c "^Grep$" || echo 0)
glob_count=$(echo "$all_tools" | grep -c "^Glob$" || echo 0)
todo_count=$(echo "$all_tools" | grep -c "^TodoWrite$" || echo 0)
task_count=$(echo "$all_tools" | grep -c "^Task$" || echo 0)
# Calculate scores
score=0
warnings=""
# 1. Model score (30 pts): 50% opus = 30pts, 100% opus = 0pts
if [ "$model_total" -gt 0 ]; then
opus_pct=$((opus * 100 / model_total))
model_score=$((30 - (opus_pct - 50) * 30 / 50))
[ "$model_score" -lt 0 ] && model_score=0
[ "$model_score" -gt 30 ] && model_score=30
score=$((score + model_score))
[ "$opus_pct" -gt 80 ] && warnings="${warnings}⚠️ Opus ${opus_pct}% - apply --model haiku for exploration\n"
else
opus_pct=0
model_score=15
score=$((score + model_score))
fi
# 2. Delegation score (25 pts): 3:1 = 25pts, 0:1 = 0pts
if [ "$session_count" -gt 0 ]; then
delegation_ratio_x100=$((agent_count * 100 / session_count))
delegation_score=$((delegation_ratio_x100 * 25 / 300))
[ "$delegation_score" -gt 25 ] && delegation_score=25
score=$((score + delegation_score))
[ "$delegation_ratio_x100" -lt 100 ] && warnings="${warnings}⚠️ Low delegation - apply Task agents more\n"
else
delegation_score=0
fi
# 3. Tool efficiency score (25 pts): native tools vs bash
native_search=$((grep_count + glob_count))
if [ "$bash_count" -gt 0 ]; then
tool_ratio_x100=$((native_search * 100 / bash_count))
tool_score=$((tool_ratio_x100 * 25 / 50))
[ "$tool_score" -gt 25 ] && tool_score=25
score=$((score + tool_score))
[ "$tool_ratio_x100" -lt 10 ] && warnings="${warnings}⚠️ Bash/Native ratio - prefer Grep/Glob tools\n"
else
tool_score=25
score=$((score + tool_score))
fi
# 4. TodoWrite score (20 pts): task tracking
if [ "$msg_count" -gt 0 ]; then
todo_ratio_x1000=$((todo_count * 1000 / msg_count))
todo_score=$((todo_ratio_x1000 * 20 / 50))
[ "$todo_score" -gt 20 ] && todo_score=20
score=$((score + todo_score))
[ "$todo_count" -eq 0 ] && warnings="${warnings}⚠️ No TodoWrite - apply for task tracking\n"
else
todo_score=0
fi
# Output
echo "📈 EFFICIENCY SCORE"
echo "────────────────────────────────────────────────────────────────────"
echo ""
echo " ┌─────────────────────────────────────┐"
printf " │ SCORE: %3d / 100 │\n" "$score"
echo " └─────────────────────────────────────┘"
echo ""
echo " Breakdown:"
printf " Model efficiency: %2d/30 (Opus %d%%)\n" "$model_score" "$opus_pct"
del_ratio=$(echo "scale=1; $agent_count / ($session_count + 0.001)" | bc)
printf " Task delegation: %2d/25 (ratio %s:1)\n" "$delegation_score" "$del_ratio"
printf " Tool efficiency: %2d/25 (Grep+Glob: %d, Bash: %d)\n" "$tool_score" "$native_search" "$bash_count"
printf " Task tracking: %2d/20 (TodoWrite: %d)\n" "$todo_score" "$todo_count"
echo ""
if [ -n "$warnings" ]; then
echo " Warnings:"
printf " $warnings"
fi
echo ""
echo "═══════════════════════════════════════════════════════════════════"
echo "Generated: $(date '+%Y-%m-%d %H:%M')"
Output
Present the results and provide recommendations based on:
Model usage distribution (aim for <50% Opus)
Tool efficiency (Grep > bash grep, Glob > bash find)
Task delegation ratio (aim for >2:1)
TodoWrite usage for task tracking
1 --- 2 name: context-report 3 description: Analyze Claude Code context efficiency. Use when evaluating session token usage. 4 --- 5 6 # Context efficiency report 7 8 Analyze the Claude Code JSONL session data for the current project to generate a context efficiency report. 9 10 ## When to invoke 11 12 - When reviewing Claude Code session efficiency 13 - To understand model usage patterns 14 - When optimizing for cost reduction 15 - After completing a project to review usage 16 17 ## Instructions 18 19 ### Project path detection 20 21 The current working directory is: `$ARGUMENTS` (if provided) or `$CWD` 22 23 Convert the path to the Claude projects folder format: 24 25 - Replace `/` with `-` 26 - The projects folder is at: `~/.dotfiles/claude.symlink/projects/` 27 28 ### Analysis script 29 30 Run this analysis for the current project: 31 32 ```bash 33 #!/bin/bash 34 CWD="${ARGUMENTS:-$(pwd)}" 35 PROJECT_KEY=$(echo "$CWD" | sed 's|/|-|g; s|\.|-|g') 36 PROJECTS_BASE="$HOME/.dotfiles/claude.symlink/projects" 37 PROJECT_DIR="$PROJECTS_BASE/$PROJECT_KEY" 38 39 if [ ! -d "$PROJECT_DIR" ]; then 40 echo "No session data found for: $CWD" 41 echo "Looking in: $PROJECT_DIR" 42 exit 1 43 fi 44 45 echo "╔══════════════════════════════════════════════════════════════════╗" 46 echo "║ Context Efficiency Report: $(basename "$CWD" | head -c 20)" 47 echo "╚══════════════════════════════════════════════════════════════════╝" 48 echo "Project: $CWD" 49 echo "" 50 51 # Session counts 52 session_count=$(find "$PROJECT_DIR" -maxdepth 1 -name "*.jsonl" ! -name "agent-*.jsonl" 2>/dev/null | wc -l | tr -d ' ') 53 agent_count=$(find "$PROJECT_DIR" -maxdepth 1 -name "agent-*.jsonl" 2>/dev/null | wc -l | tr -d ' ') 54 echo "📁 SESSIONS" 55 echo "────────────────────────────────────────────────────────────────────" 56 echo "Main Sessions: $session_count" 57 echo "Agent Sessions: $agent_count" 58 if [ "$session_count" -gt 0 ]; then 59 ratio=$(echo "scale=2; $agent_count / $session_count" | bc) 60 echo "Delegation Ratio: ${ratio}:1" 61 fi 62 echo "" 63 64 # Model usage 65 echo "🤖 MODEL USAGE" 66 echo "────────────────────────────────────────────────────────────────────" 67 find "$PROJECT_DIR" -maxdepth 1 -name "*.jsonl" -size +1k -exec cat {} + 2>/dev/null | \ 68 jq -r 'select(.message.model != null) | .message.model' 2>/dev/null | \ 69 sort | uniq -c | sort -rn 70 echo "" 71 72 # Tool usage 73 echo "🔧 TOOL USAGE" 74 echo "────────────────────────────────────────────────────────────────────" 75 find "$PROJECT_DIR" -maxdepth 1 -name "*.jsonl" -size +1k -exec cat {} + 2>/dev/null | \ 76 jq -r '.message.content[]? | select(.type == "tool_use") | .name' 2>/dev/null | \ 77 sort | uniq -c | sort -rn | head -15 78 echo "" 79 80 # Size 81 echo "📊 DATA SIZE" 82 echo "────────────────────────────────────────────────────────────────────" 83 total_size=$(du -sh "$PROJECT_DIR" 2>/dev/null | cut -f1) 84 msg_count=$(find "$PROJECT_DIR" -maxdepth 1 -name "*.jsonl" -exec cat {} + 2>/dev/null | wc -l | tr -d ' ') 85 echo "Total Size: $total_size" 86 echo "Message Records: $msg_count" 87 echo "" 88 89 # Collect tool data once 90 all_tools=$(find "$PROJECT_DIR" -maxdepth 1 -name "*.jsonl" -size +1k -exec cat {} + 2>/dev/null | jq -r '.message.content[]? | select(.type == "tool_use") | .name' 2>/dev/null) 91 all_models=$(find "$PROJECT_DIR" -maxdepth 1 -name "*.jsonl" -size +1k -exec cat {} + 2>/dev/null | jq -r '.message.model // empty' 2>/dev/null) 92 93 # Model counts 94 opus=$(echo "$all_models" | grep -c "opus" || echo 0) 95 sonnet=$(echo "$all_models" | grep -c "sonnet" || echo 0) 96 haiku=$(echo "$all_models" | grep -c "haiku" || echo 0) 97 model_total=$((opus + sonnet + haiku)) 98 99 # Tool counts 100 bash_count=$(echo "$all_tools" | grep -c "^Bash$" || echo 0) 101 grep_count=$(echo "$all_tools" | grep -c "^Grep$" || echo 0) 102 glob_count=$(echo "$all_tools" | grep -c "^Glob$" || echo 0) 103 todo_count=$(echo "$all_tools" | grep -c "^TodoWrite$" || echo 0) 104 task_count=$(echo "$all_tools" | grep -c "^Task$" || echo 0) 105 106 # Calculate scores 107 score=0 108 warnings="" 109 110 # 1. Model score (30 pts): 50% opus = 30pts, 100% opus = 0pts 111 if [ "$model_total" -gt 0 ]; then 112 opus_pct=$((opus * 100 / model_total)) 113 model_score=$((30 - (opus_pct - 50) * 30 / 50)) 114 [ "$model_score" -lt 0 ] && model_score=0 115 [ "$model_score" -gt 30 ] && model_score=30 116 score=$((score + model_score)) 117 [ "$opus_pct" -gt 80 ] && warnings="${warnings}⚠️ Opus ${opus_pct}% - apply --model haiku for exploration\n" 118 else 119 opus_pct=0 120 model_score=15 121 score=$((score + model_score)) 122 fi 123 124 # 2. Delegation score (25 pts): 3:1 = 25pts, 0:1 = 0pts 125 if [ "$session_count" -gt 0 ]; then 126 delegation_ratio_x100=$((agent_count * 100 / session_count)) 127 delegation_score=$((delegation_ratio_x100 * 25 / 300)) 128 [ "$delegation_score" -gt 25 ] && delegation_score=25 129 score=$((score + delegation_score)) 130 [ "$delegation_ratio_x100" -lt 100 ] && warnings="${warnings}⚠️ Low delegation - apply Task agents more\n" 131 else 132 delegation_score=0 133 fi 134 135 # 3. Tool efficiency score (25 pts): native tools vs bash 136 native_search=$((grep_count + glob_count)) 137 if [ "$bash_count" -gt 0 ]; then 138 tool_ratio_x100=$((native_search * 100 / bash_count)) 139 tool_score=$((tool_ratio_x100 * 25 / 50)) 140 [ "$tool_score" -gt 25 ] && tool_score=25 141 score=$((score + tool_score)) 142 [ "$tool_ratio_x100" -lt 10 ] && warnings="${warnings}⚠️ Bash/Native ratio - prefer Grep/Glob tools\n" 143 else 144 tool_score=25 145 score=$((score + tool_score)) 146 fi 147 148 # 4. TodoWrite score (20 pts): task tracking 149 if [ "$msg_count" -gt 0 ]; then 150 todo_ratio_x1000=$((todo_count * 1000 / msg_count)) 151 todo_score=$((todo_ratio_x1000 * 20 / 50)) 152 [ "$todo_score" -gt 20 ] && todo_score=20 153 score=$((score + todo_score)) 154 [ "$todo_count" -eq 0 ] && warnings="${warnings}⚠️ No TodoWrite - apply for task tracking\n" 155 else 156 todo_score=0 157 fi 158 159 # Output 160 echo "📈 EFFICIENCY SCORE" 161 echo "────────────────────────────────────────────────────────────────────" 162 echo "" 163 echo " ┌─────────────────────────────────────┐" 164 printf " │ SCORE: %3d / 100 │\n" "$score" 165 echo " └─────────────────────────────────────┘" 166 echo "" 167 echo " Breakdown:" 168 printf " Model efficiency: %2d/30 (Opus %d%%)\n" "$model_score" "$opus_pct" 169 del_ratio=$(echo "scale=1; $agent_count / ($session_count + 0.001)" | bc) 170 printf " Task delegation: %2d/25 (ratio %s:1)\n" "$delegation_score" "$del_ratio" 171 printf " Tool efficiency: %2d/25 (Grep+Glob: %d, Bash: %d)\n" "$tool_score" "$native_search" "$bash_count" 172 printf " Task tracking: %2d/20 (TodoWrite: %d)\n" "$todo_score" "$todo_count" 173 echo "" 174 175 if [ -n "$warnings" ]; then 176 echo " Warnings:" 177 printf " $warnings" 178 fi 179 180 echo "" 181 echo "═══════════════════════════════════════════════════════════════════" 182 echo "Generated: $(date '+%Y-%m-%d %H:%M')" 183 ``` 184 185 ## Output 186 187 Present the results and provide recommendations based on: 188 189 1. Model usage distribution (aim for <50% Opus) 190 2. Tool efficiency (Grep > bash grep, Glob > bash find) 191 3. Task delegation ratio (aim for >2:1) 192 4. TodoWrite usage for task tracking
htlin222/dotfiles/tree/main/claude.symlink/archived-skills/context-report commit 0b70d2cf05
Frequently asked questions How do I install the Context Report skill? Run npx skillmds@latest add htlin222/context-report in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
What does the Context Report skill do? Analyze Claude Code context efficiency. Use when evaluating session token usage. It is listed under Docs & Writing on SkillMD.
Is Context Report safe to use? This skill has not completed SkillMD's automated safety review yet. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
Which AI agents work with Context Report? This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Is Context Report free to use? Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
Who published Context Report? htlin222 (@htlin222) published this skill. Their other Agent Skills are listed on their SkillMD profile.