Skip to content

feat: backfill check + recovery for unanalyzed sessions #242

@melagiri

Description

@melagiri

Context

Part of the Native Analysis via Claude Code Hooks feature (Phase 12, v4.8.0).
Plan: docs/plans/2026-03-28-native-analysis-hooks.md

Issue 5 of 6 — Depends on #240 (insights command).

Problem

When the analysis hook fails, or a user installs Code Insights after having existing sessions, unanalyzed sessions accumulate. We need a recovery mechanism.

Solution

code-insights insights check subcommand

code-insights insights check [options]
  --days <n>       Lookback window (default: 7)
  --quiet, -q      Machine-readable output (just count)

Behavior by Count

Unanalyzed (last 7d) Behavior
0 Silent exit
1-2 Auto-analyze silently (calls insights <id> --native for each)
3-10 Print count + suggest: "Run code-insights insights check --analyze to process them"
11+ Print count + time estimate + suggest command

Query

SELECT s.id, s.title, s.started_at
FROM sessions s
LEFT JOIN analysis_usage au ON au.session_id = s.id AND au.analysis_type = 'session'
WHERE s.started_at > datetime('now', '-7 days')
  AND s.deleted_at IS NULL
  AND au.session_id IS NULL
ORDER BY s.started_at DESC

Optional SessionStart Hook

For automatic detection, users can add a SessionStart hook:

{
  "SessionStart": [{
    "hooks": [{ "type": "command", "command": "node <cli> insights check -q" }]
  }]
}

This is informational only (prints a notice), not installed by default.

Acceptance Criteria

  • insights check queries unanalyzed sessions in last 7 days
  • 1-2 sessions: auto-analyzes with --native
  • 3+ sessions: prints suggestion message with count
  • --days <n> overrides lookback window
  • --quiet outputs just the count (for scripting)
  • --analyze flag processes all found sessions
  • Progress output during batch processing: [1/8] session-title ... done (12s)
  • Non-blocking — single notice, no nag on repeat invocations

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestfeatureNew functionality

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions