Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 68 additions & 28 deletions scripts/global-report.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#!/bin/bash
# Generate a 7-day global analytics report
# Outputs to /tmp/session-analytics-report.md
#
# Restructured for RFC #41 with focus on actionable insights:
# - Removed: languages (curiosity only), sessions (too verbose), mcp-usage (secondary)
# - Added: agents (token split), trends (comparison), classify (session types), failures

set -e

Expand All @@ -10,7 +14,6 @@ CLI="session-analytics-cli"

# Check if CLI is available
if ! command -v "$CLI" &> /dev/null; then
# Try the venv version
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
CLI="$SCRIPT_DIR/../.venv/bin/session-analytics-cli"
if [[ ! -x "$CLI" ]]; then
Expand All @@ -19,95 +22,132 @@ if ! command -v "$CLI" &> /dev/null; then
fi
fi

echo "Generating $DAYS-day global report..."
echo "Generating $DAYS-day analytics report..."

{
echo "# Claude Code Session Analytics Report"
echo "# Claude Code Analytics Report"
echo ""
echo "Generated: $(date '+%Y-%m-%d %H:%M:%S')"
echo "Period: Last $DAYS days"
echo ""

echo "## Status"
# ============================================================
echo "## Overview"
echo ""

echo "### Database Status"
echo '```'
"$CLI" status
echo '```'
echo ""

echo "## Tool Usage"
echo ""
echo "### Trends (vs previous $DAYS days)"
echo '```'
"$CLI" frequency --days "$DAYS"
"$CLI" trends --days "$DAYS"
echo '```'
echo ""

echo "## Command Breakdown"
# ============================================================
echo "## Cost & Usage"
echo ""

echo "### Token Usage by Day"
echo '```'
"$CLI" commands --days "$DAYS"
"$CLI" tokens --days "$DAYS" --by day
echo '```'
echo ""

echo "## MCP Server Usage"
echo "### Agent vs Main Session"
echo ""
echo "How much work are Task subagents doing vs your main session?"
echo '```'
"$CLI" mcp-usage --days "$DAYS"
"$CLI" agents --days "$DAYS"
echo '```'
echo ""

echo "## Language Distribution"
# ============================================================
echo "## Tools & Commands"
echo ""

echo "### Tool Usage"
echo '```'
"$CLI" languages --days "$DAYS"
"$CLI" frequency --days "$DAYS"
echo '```'
echo ""

echo "## Project Activity"
echo ""
echo "### Command Breakdown"
echo '```'
"$CLI" projects --days "$DAYS"
"$CLI" commands --days "$DAYS"
echo '```'
echo ""

echo "## File Activity (Top 20, worktrees collapsed)"
# ============================================================
echo "## Projects & Files"
echo ""

echo "### Project Activity"
echo '```'
"$CLI" file-activity --days "$DAYS" --limit 20 --collapse-worktrees
"$CLI" projects --days "$DAYS"
echo '```'
echo ""

echo "## Tool Sequences"
echo ""
echo "### Most Touched Files"
echo '```'
"$CLI" sequences --days "$DAYS" --min-count 5
"$CLI" file-activity --days "$DAYS" --limit 15 --collapse-worktrees
echo '```'
echo ""

echo "## Token Usage by Day"
# ============================================================
echo "## Session Analysis"
echo ""

echo "### Session Classification"
echo ""
echo "What type of work are you doing?"
echo '```'
"$CLI" tokens --days "$DAYS" --by day
"$CLI" classify --days "$DAYS"
echo '```'
echo ""

echo "## Session Overview"
echo "### Failure Patterns"
echo ""
echo "Errors, rework, and recovery patterns."
echo '```'
"$CLI" sessions --days "$DAYS"
"$CLI" failures --days "$DAYS"
echo '```'
echo ""

echo "## Permission Gaps"
# ============================================================
echo "## Workflow Improvements"
echo ""

echo "### Permission Gaps"
echo ""
echo "Commands to add to \`~/.claude/settings.json\`:"
echo '```'
"$CLI" permissions --days "$DAYS" --min-count 3
echo '```'
echo ""

echo "### Common Tool Sequences"
echo ""
echo "Patterns that could be automated:"
echo '```'
"$CLI" sequences --days "$DAYS" --min-count 5
echo '```'

} > "$OUTPUT"

echo ""
echo "Report saved to: $OUTPUT"
echo ""
echo "View with: cat $OUTPUT"
echo "Or open in browser: open $OUTPUT"
echo "Sections:"
echo " 1. Overview (status, trends)"
echo " 2. Cost & Usage (tokens, agents)"
echo " 3. Tools & Commands"
echo " 4. Projects & Files"
echo " 5. Session Analysis (classify, failures)"
echo " 6. Workflow Improvements (permissions, sequences)"
echo ""
echo "View: cat $OUTPUT"
echo "Open: open $OUTPUT"
2 changes: 1 addition & 1 deletion src/session_analytics/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def _format_tokens(data: dict) -> list[str]:
return lines


@_register_formatter(lambda d: "summary" in d)
@_register_formatter(lambda d: "summary" in d and "total_tools" in d.get("summary", {}))
def _format_insights(data: dict) -> list[str]:
return [
"Pre-computed patterns for /improve-workflow",
Expand Down