Back to Articles

Breaking the 200-Session Ceiling: How to Build Unlimited Analytics for Claude Code

[ View on GitHub ]

Breaking the 200-Session Ceiling: How to Build Unlimited Analytics for Claude Code

Hook

Claude Code’s built-in /insights command artificially caps analysis at 200 sessions and 500 tokens per summary. If you’ve used Claude heavily for months, you’re getting insights from less than 10% of your actual work—and there’s no technical reason for it.

Context

Claude Code stores every conversation you have as structured JSONL files in ~/.claude/projects/, creating a rich dataset of your AI-assisted development patterns. The built-in /insights command analyzes these sessions to surface usage trends, common workflows, and friction points. But it’s deliberately constrained: 200 sessions maximum, 500-token summaries, and 50 facets sent to the report generator. For developers who’ve accumulated thousands of sessions across multiple machines over months of daily use, these limits mean the insights become less representative over time.

The claude_enhanced_insights repository solves this by reimplementing the entire analytics pipeline without artificial constraints. It processes 9,999 sessions (50x more), generates 2048-token summaries (4x richer), and sends 200 facets to reports (4x more context). More importantly, it introduces intelligent caching and multi-machine aggregation—features that make comprehensive analysis both practical and cost-effective. This isn’t just about lifting limits; it’s about building a proper analytics foundation for power users who treat Claude as a core development tool.

Technical Insight

Phase 2: API (Cached)

Phase 1: Local (Free)

Read JSONL files

Tool counts, tokens,

languages, git activity

Check cache

Yes

No

Qualitative insights:

goals, outcomes, friction

Write to disk

Aggregate data

Claude Projects Directory

~/.claude/projects/

Local Metrics Extraction

Session Facets

JSON objects

Facet Exists?

Load Cached Facet

~/.claude/usage-data/facets/

Claude API Analysis

Generate New Facet

Usage Report

Trends & Insights

System architecture — auto-generated

The architecture reveals some clever engineering decisions that balance thoroughness with practicality. At its core, the tool is a two-phase pipeline: extract metrics locally, then enrich them via API calls.

Phase one reads JSONL session files directly from ~/.claude/projects/ and extracts quantifiable metrics programmatically—no API calls needed. It counts tool invocations (bash, edit_file, view_file), tallies programming languages, tracks token consumption, and monitors git activity. This happens entirely locally and is essentially free. The extracted data gets structured into “facets”—JSON objects representing each session’s characteristics.

Phase two is where it gets interesting. The tool calls Claude’s API to analyze each session’s transcript and generate qualitative insights: What was the user trying to accomplish? Did they succeed? Where did they hit friction? Here’s where the caching architecture shines. Facets are written to ~/.claude/usage-data/facets/ with filenames matching session IDs. On subsequent runs, the tool checks for existing facet files and skips API calls for sessions it’s already analyzed:

def get_cached_facets(session_id, cache_dir):
    facet_path = cache_dir / f"{session_id}.json"
    if facet_path.exists():
        with open(facet_path) as f:
            return json.load(f)
    return None

def analyze_session(session, cache_dir, client):
    cached = get_cached_facets(session['id'], cache_dir)
    if cached:
        return cached
    
    # Only call API for new sessions
    response = client.messages.create(
        model="claude-3-5-sonnet-20241022",
        max_tokens=2048,  # 4x the built-in limit
        messages=[{
            "role": "user",
            "content": build_analysis_prompt(session)
        }]
    )
    
    facets = parse_response(response)
    write_cache(session['id'], facets, cache_dir)
    return facets

This caching strategy transforms the economics. The first run might analyze 1,000 sessions at ~$0.02 each ($20 total), but subsequent runs only pay for new sessions. If you run weekly reports, you’re only analyzing perhaps 20-50 new sessions each time—completely manageable.

The multi-machine aggregation feature shows sophisticated thinking about real-world usage patterns. Many developers use Claude on both laptop and desktop, or across work and personal machines. The tool includes an SSH/rsync script that pulls session files from remote machines, using path hashing to ensure unique session identifiers even when project names collide:

def hash_project_path(machine_id, project_path):
    # Prevents collisions when same project name exists on different machines
    return hashlib.sha256(
        f"{machine_id}:{project_path}".encode()
    ).hexdigest()[:16]

def sync_remote_sessions(remote_host, local_cache):
    temp_dir = Path(f"/tmp/claude_sync_{remote_host}")
    subprocess.run([
        "rsync", "-avz",
        f"{remote_host}:~/.claude/projects/",
        str(temp_dir)
    ])
    
    for session_file in temp_dir.glob("*.jsonl"):
        session = parse_session(session_file)
        session['id'] = hash_project_path(remote_host, session['project'])
        merge_into_cache(session, local_cache)

The report generation phase demonstrates thoughtful parallelization. Rather than sending one massive prompt with all 200 facets, the tool splits analysis into 8 distinct dimensions (usage patterns, friction points, successful workflows, language trends, tool effectiveness, learning progression, collaboration patterns, and future opportunities) and makes 8 parallel API calls. This produces more focused, coherent analysis than asking for everything at once, and the parallelization keeps total runtime under 30 seconds.

One subtle but important detail: the tool reuses OAuth credentials from your existing Claude Code installation rather than requiring separate API key management. It reads from ~/.claude/credentials.json, the same file Claude Code uses. This eliminates a common setup friction point and ensures you’re using the same billing account. The code also sets restrictive file permissions (0600) on all output files since they contain potentially sensitive information about your development patterns and code.

Gotcha

The first major limitation is that this only works if you have Claude Code installed and have been using it actively. The tool requires local JSONL session files to exist in ~/.claude/projects/. If you primarily use Claude.ai through the web interface, or if you’ve deleted your session history for privacy reasons, there’s nothing to analyze. You need a substantial corpus—ideally hundreds of sessions—for the insights to be meaningful. Running it on 20 sessions won’t reveal patterns that justify the setup effort.

Cost estimation is crucial but imperfect. The repository includes a --dry-run flag that counts sessions and estimates API costs before actually analyzing anything. However, the estimates assume average token counts and don’t account for particularly long sessions or retries on API errors. One user reported a first-run cost of $47 for analyzing 2,300 sessions—higher than the $35 estimated. The caching makes subsequent runs cheap, but that initial analysis can be surprisingly expensive. If you’re on a tight budget or your organization has strict API spending controls, you’ll need to carefully review the dry-run output and potentially process sessions in batches.

The multi-machine sync functionality, while powerful, requires non-trivial setup. You need SSH key-based authentication configured for each remote host, and the sync script must be manually edited to list your machines. There’s no interactive configuration or auto-discovery. For developers who aren’t comfortable with SSH key management or shell scripting, this feature might be inaccessible despite being one of the tool’s unique capabilities. The documentation assumes familiarity with rsync flags and remote path specifications.

Verdict

Use if: You’re a heavy Claude Code user with 500+ sessions accumulated across daily development work, you want quantitative data about your AI-assisted workflows beyond what the built-in command provides, you use Claude on multiple machines and want unified analytics, or you’re willing to invest $20-50 in a comprehensive initial analysis that becomes incrementally cheap through caching. The tool genuinely delivers insights the official command can’t provide, and the caching architecture makes it sustainable for ongoing use. Skip if: You’re a casual Claude user with fewer than 100 sessions (the built-in /insights command is sufficient), you’ve deleted session history or primarily use Claude.ai web interface (no local data to analyze), API costs for initial analysis are prohibitive for your budget, or you’re looking for real-time analytics rather than periodic deep dives. The value proposition depends entirely on having a large corpus of sessions and wanting narrative insights about long-term patterns rather than simple usage statistics.

// ADD TO YOUR README
[![Featured on Starlog](https://starlog.is/api/badge/ai-dev-tools/dmaynor-claude-enhanced-insights.svg)](https://starlog.is/api/badge-click/ai-dev-tools/dmaynor-claude-enhanced-insights)