Summary
Build a metrics analyzer that parses existing Claude Code session logs (~/.claude/projects/**/*.jsonl) to extract trajectory data and usage patterns. Use this data to provide evidence-based workflow improvement suggestions via the /improve-workflow command.
Problem / Motivation
The /improve-workflow command currently suggests improvements based on static analysis of the codebase and CLAUDE.md. Without usage data, it can't identify:
- Which commands are actually used frequently vs rarely
- Common tool call sequences that could be automated
- Friction points where users repeat operations or encounter errors
- Opportunities for new commands based on observed patterns
Example use cases for metrics:
- "You run
git status && git diff in 80% of sessions - create a /git-summary command?"
- "You always run
/pr-feedback twice in a row - should it auto-rerun after fixes?"
- "Your most common workflow: status → diff → edit → commit - streamline this?"
Context
- Discovered during: Discussion about improving the
/improve-workflow command
- Key discovery: Claude Code already logs all sessions to
~/.claude/projects/<project>/*.jsonl
- Log structure: JSONL format with timestamps, tool calls, token usage, user messages
- No new instrumentation needed: Can parse existing logs directly
Session Log Structure
Each .jsonl file contains one JSON object per line:
{
"type": "assistant",
"timestamp": "2025-12-30T01:26:10.964Z",
"sessionId": "8c7bdffa-6aa3-49de-8b4d-8f925596faeb",
"cwd": "/Users/evansenter/Documents/projects/dotfiles",
"gitBranch": "main",
"message": {
"role": "assistant",
"content": [
{
"type": "tool_use",
"name": "Bash",
"input": {
"command": "git status",
"description": "Check git status"
}
}
],
"usage": {
"input_tokens": 10,
"output_tokens": 8,
"cache_read_input_tokens": 46629
}
}
}
Proposed Solution
Design Decisions (Resolved)
- Parser language: Bash + jq (simple, no dependencies, fast JSONL parsing)
- Time window: Last 7 days (recent behavior, fast parsing)
- Scope: Both project-specific and global (with toggle/option)
- Performance: Parse on-demand (simple, always fresh data)
High-Level Approach
- Parser: Read
.jsonl logs and extract structured data using bash + jq
- Analyzer: Identify patterns, frequencies, sequences
- Suggester: Generate data-driven workflow improvements
- Integration: Extend
/improve-workflow to use metrics
Implementation
Phase 1: Metrics Parser (~/.claude/contrib/parse-session-logs.sh)
Extract from last 7 days of logs:
- Tool calls (name, frequency, timestamp)
- Command executions (
/slash-command patterns)
- Common sequences (e.g., Read → Edit → Write)
- Error patterns (failed tool calls)
- Session metadata (duration, token usage)
Phase 2: Pattern Analyzer (same script or separate)
- Identify top N most-used tools/commands
- Detect repeated sequences (same 3+ tools always run together)
- Find friction points (repeated failures, multiple attempts)
- Calculate session statistics (avg duration, tools per session)
- Support both
--project and --global flags
Phase 3: Suggestion Engine
- For each pattern, generate actionable suggestions
- Categorize by impact (high-value vs nice-to-have)
- Provide data evidence (e.g., "Used in 80% of sessions")
- Differentiate project-specific vs global patterns
Phase 4: Workflow Integration
- Update
/improve-workflow to call parser + analyzer
- Display data-driven suggestions first, static suggestions second
- Show usage stats alongside each suggestion
- Add
--metrics-only flag to show just data-driven suggestions
Assumptions
| Assumption |
Confidence |
Impact if Wrong |
| All tool calls are logged in .jsonl files |
High |
Would need fallback instrumentation |
| JSONL format is stable across CC versions |
Medium |
Would need version-aware parser |
| Parsing 7 days on-demand is fast enough (<2s) |
High |
Bash+jq is very fast for JSONL |
| Logs contain sufficient data for pattern analysis |
High |
Verified log structure includes tool calls, timestamps |
| User wants both project and global metrics |
High |
Confirmed by user |
Actionable Requirements
| # |
Requirement |
Owner |
Blocked By |
| 1 |
Build JSONL parser (bash + jq) for tool extraction |
Claude |
None |
| 2 |
Add time-window filtering (7 days) |
Claude |
#1 |
| 3 |
Implement frequency analyzer |
Claude |
#1 |
| 4 |
Implement sequence detector |
Claude |
#1 |
| 5 |
Implement friction detector |
Claude |
#1 |
| 6 |
Add project vs global scope support |
Claude |
#2 |
| 7 |
Build suggestion engine |
Claude |
#3, #4, #5 |
| 8 |
Integrate into /improve-workflow |
Claude |
#7 |
| 9 |
Test with real session data (7+ days) |
Human |
#8 |
| 10 |
Iterate on suggestions based on usefulness |
Claude |
#9 |
Implementation Checklist
Example Workflow Improvement Output
Before (static analysis only):
Suggested improvements:
- Consider adding a /commit-review command
After (with metrics from session logs):
Data-driven suggestions (dotfiles project, last 7 days):
- 🔥 High-value: You run `git status && git diff` in 12/15 sessions → create /git-summary alias?
- 📊 Pattern: You always run Read → Edit → Write on settings.json → create /edit-settings helper?
- ⚠️ Friction: /pr-feedback was run twice consecutively in 8/10 cases → auto-rerun after fixes?
- 📈 Usage: Top commands: /status-report (18x), /pr-feedback (15x), /watch-ci (12x)
Global patterns (all projects, last 7 days):
- 🔥 Bash tool used 450x across 25 sessions - most common: `git status` (85x), `git diff` (72x)
- 📊 Skill invocations: pr-review-toolkit:review-pr (22x), commit-commands:commit-push-pr (18x)
Static suggestions:
- Consider adding a /commit-review command
Advantages of Using Session Logs
- No new instrumentation: Leverages existing logging infrastructure
- Historical data: Can analyze past behavior immediately
- Complete trajectory: Captures all tool calls, not just commands
- Rich context: Includes timestamps, session IDs, token usage
- Cross-session analysis: Can aggregate patterns across multiple sessions
- Fast: Bash + jq can parse thousands of log lines in <1 second
Next Steps
- Immediate: Create
~/.claude/contrib/parse-session-logs.sh (ready to start)
- Then: Implement tool extraction with jq
- Then: Build pattern analysis logic
- Finally: Integrate into
/improve-workflow
Summary
Build a metrics analyzer that parses existing Claude Code session logs (
~/.claude/projects/**/*.jsonl) to extract trajectory data and usage patterns. Use this data to provide evidence-based workflow improvement suggestions via the/improve-workflowcommand.Problem / Motivation
The
/improve-workflowcommand currently suggests improvements based on static analysis of the codebase and CLAUDE.md. Without usage data, it can't identify:Example use cases for metrics:
git status && git diffin 80% of sessions - create a/git-summarycommand?"/pr-feedbacktwice in a row - should it auto-rerun after fixes?"Context
/improve-workflowcommand~/.claude/projects/<project>/*.jsonlSession Log Structure
Each
.jsonlfile contains one JSON object per line:{ "type": "assistant", "timestamp": "2025-12-30T01:26:10.964Z", "sessionId": "8c7bdffa-6aa3-49de-8b4d-8f925596faeb", "cwd": "/Users/evansenter/Documents/projects/dotfiles", "gitBranch": "main", "message": { "role": "assistant", "content": [ { "type": "tool_use", "name": "Bash", "input": { "command": "git status", "description": "Check git status" } } ], "usage": { "input_tokens": 10, "output_tokens": 8, "cache_read_input_tokens": 46629 } } }Proposed Solution
Design Decisions (Resolved)
High-Level Approach
.jsonllogs and extract structured data using bash + jq/improve-workflowto use metricsImplementation
Phase 1: Metrics Parser (
~/.claude/contrib/parse-session-logs.sh)Extract from last 7 days of logs:
/slash-commandpatterns)Phase 2: Pattern Analyzer (same script or separate)
--projectand--globalflagsPhase 3: Suggestion Engine
Phase 4: Workflow Integration
/improve-workflowto call parser + analyzer--metrics-onlyflag to show just data-driven suggestionsAssumptions
Actionable Requirements
/improve-workflowImplementation Checklist
~/.claude/contrib/parse-session-logs.sh/improve-workflowcommand--project/--global/--bothflagsExample Workflow Improvement Output
Before (static analysis only):
After (with metrics from session logs):
Advantages of Using Session Logs
Next Steps
~/.claude/contrib/parse-session-logs.sh(ready to start)/improve-workflow