> your AI agent picks dependencies from memory; give it dated facts — try starlog.dev ↗ vet your agent's deps ↗ vibe-coding is fine. vibe-importing isn’t. — try starlog.dev ↗ vibe-importing isn’t fine ↗ your agent has never seen your private packages — try starlog.dev ↗ facts for private packages ↗ a linter for the dependencies your AI agent picks — try starlog.dev ↗ a linter for agent deps ↗

Back to Articles

Breaking Claude Code's 200-Session Analysis Limit: A Deep Dive into claude_enhanced_insights

[ View on GitHub ]

Breaking Claude Code's 200-Session Analysis Limit: A Deep Dive into claude_enhanced_insights

Hook

Claude Code's built-in insights feature caps analysis at 200 sessions with 500-token summaries. If you're a power user drowning in thousands of coding sessions, you've probably hit this wall hard—and you're leaving critical usage patterns on the table.

Context

Claude Code's /insights command is a brilliant feature for understanding how you use AI assistance, but it was designed with conservative guardrails: analyze at most 200 sessions, generate 500-token summaries, extract around 50 facets total. For casual users, this is perfect—zero setup, no API costs, instant feedback. But for development teams running hundreds of sessions weekly across multiple projects and machines, these limits become a data blindspot.

The fundamental tension is between cost control and comprehensiveness. Anthropic understandably doesn't want the insights feature to rack up massive API bills analyzing every keystroke. But for organizations genuinely trying to understand how AI coding assistance impacts their workflow—where developers get stuck, which types of tasks benefit most, how usage patterns differ across teams—the 200-session cap makes trend analysis nearly impossible. You're essentially looking at a snapshot when you need a time-series. dmaynor/claude_enhanced_insights solves this by moving the analysis client-side, giving you control over the tradeoffs between API costs and analytical depth.

Technical Insight

The architecture is elegantly simple: parse local transcript files, cache expensive extractions, parallelize API calls for report generation. Claude Code stores session data in ~/.claude/projects/*.jsonl files—newline-delimited JSON containing every prompt, response, and interaction. claude_enhanced_insights reads these directly, bypassing the built-in insights API entirely.

The critical innovation is the two-tier caching strategy. First, it extracts basic metrics locally (token counts, timestamps, project IDs) without any API calls. Then it makes targeted Claude API calls to analyze each session for "facets"—structured extractions of goals, outcomes, and friction points. Here's the facet extraction logic:

# Simplified from the actual implementation
def extract_facets(session_data, cache_dir):
    cache_key = hashlib.sha256(
        session_data['prompt'][:200].encode()
    ).hexdigest()
    cache_file = cache_dir / f"{cache_key}.json"
    
    if cache_file.exists():
        return json.loads(cache_file.read_text())
    
    # Make API call to Claude for facet extraction
    facets = anthropic_client.messages.create(
        model="claude-3-5-sonnet-20241022",
        max_tokens=2000,  # 4x the built-in limit
        messages=[{
            "role": "user",
            "content": f"""Analyze this coding session:
            {session_data['prompt'][:1000]}
            {session_data['response'][:1000]}
            
            Extract: goal, outcome, friction_points"""
        }]
    )
    
    cache_file.write_text(json.dumps(facets))
    os.chmod(cache_file, 0o600)  # Security: owner-only
    return facets

This caching means you pay for facet extraction once per session, then can regenerate reports indefinitely. The tool supports up to 9,999 sessions (vs. 200), 2,000-token summaries (vs. 500), and 200 total facets (vs. 50). These aren't arbitrary limits—they're calculated to stay under typical Claude API tier rate limits while providing meaningful depth.

The multi-machine aggregation feature is particularly clever for teams. It uses SSH and rsync to pull session files from remote developer workstations, then matches sessions across machines by hashing project paths. This means you can analyze how your entire team uses Claude Code without centralizing credentials:

# Sync sessions from remote machines
python enhanced_insights.py \
  --sync-from user@dev-box-1:~/.claude/projects \
  --sync-from user@dev-box-2:~/.claude/projects \
  --output team_report.html

Report generation happens in parallel with 8 concurrent API calls—enough to maximize throughput without hitting rate limits. Each report section (overview, friction analysis, outcome patterns) is generated independently, then stitched together into an HTML document with embedded charts. The tool reuses your existing ~/.config/claude/auth.json credentials, so there's no separate authentication flow.

The security posture is interesting: file permissions are locked down (0600 on caches and reports), and it never transmits your full session data anywhere except Anthropic's API. But prompt excerpts (first 200 characters) are stored in cache files and included in reports, which could be problematic if you're working with API keys or secrets in your prompts.

Gotcha

The biggest footgun is cost control. Unlike the built-in insights feature (which is free), this tool makes real API calls that incur real charges. Analyzing 5,000 sessions with 2K-token summaries could easily cost $50-100 depending on your Claude API tier. There's a --dry-run flag, but no built-in budget limits or cost estimation before you commit. You're expected to understand the implications of parallel API calls at scale.

The coupling to Claude Code's internal file structure is also fragile. This tool literally depends on ~/.claude/projects/*.jsonl existing in a specific format and ~/.config/claude/auth.json containing valid OAuth tokens. If Anthropic changes either format, the tool breaks completely. There's no version detection or graceful degradation—it'll just fail with cryptic JSON parsing errors. The 4-star GitHub count suggests this is early-stage software used by a handful of people, so expect to read source code when things go wrong.

Finally, the prompt excerpt inclusion in cache files means you need to audit what's in your sessions before aggregating across teams. If a developer accidentally pasted an AWS secret key into a Claude Code prompt, that excerpt will live in the cache indefinitely. The 200-character limit mitigates this somewhat, but it's not a security boundary you should rely on.

Verdict

Use if: You're analyzing hundreds or thousands of Claude Code sessions and need to understand patterns the built-in insights can't surface—especially across multiple projects or team members. The multi-machine sync and comprehensive facet extraction genuinely unlock analysis that's otherwise impossible. The API costs are worth it if you're making data-driven decisions about AI tooling adoption. Skip if: You're a casual Claude Code user satisfied with the built-in /insights command, uncomfortable with unpredictable API costs from large-scale analysis, or working with sensitive prompts where even 200-character excerpts pose a risk. Also skip if you expect polished software—this is a power tool for people willing to debug Python and understand the Claude API contract.