Code Insights is a local-first analytics platform designed to turn AI coding sessions into actionable knowledge. It extracts structured insights, decisions, learnings, and prompt quality scores from tools like Claude Code, Cursor, Codex CLI, Copilot CLI, Gemini CLI, Hermes Agent, OpenCode, Crush, and Google Antigravity.
- Purpose: Help developers understand their AI coding patterns, track costs, and improve their AI fluency through automated session analysis and background processing.
- Architecture:
cli/: Node.js CLI (TypeScript) responsible for session discovery, parsing, and SQLite persistence. Includes a background Analysis Queue for asynchronous LLM processing.server/: Hono-based API server (TypeScript) that proxies LLM requests, serves the dashboard, and manages the analysis worker.dashboard/: React SPA (Vite + TypeScript) for visualizing sessions, analytics, cross-session patterns, and real-time analysis status.
- Database: Local SQLite database stored at
~/.code-insights/data.db. Uses WAL mode for concurrent access and high-performance writes. SeeRULES.mdfor database integrity and engineering standards.
The project uses pnpm workspaces for dependency management.
- Install Dependencies:
pnpm install - Build All Packages:
pnpm build - Run Tests:
pnpm test - CLI Usage:
code-insights sync # Discover and import new sessions code-insights insights # View or generate insights from the terminal code-insights queue # Manage the background analysis queue code-insights reflect # Generate cross-session synthesis (weekly/project) code-insights dashboard # Start the web dashboard (default: localhost:7890) code-insights config # Configure LLM providers and preferences
- CLI Development:
cd cli pnpm dev # Watch mode for CLI npm link # Link code-insights command locally
- Monorepo Management: Uses
pnpmworkspaces. Always runpnpm installfrom the root. - Type Safety: Strict TypeScript usage.
cli/src/types.tsis the single source of truth. - Database: Uses
better-sqlite3. Schema is defined incli/src/db/schema.ts. V9 introduces theanalysis_queuetable for robust background processing. All persistence MUST use WAL mode (PRAGMA journal_mode = WAL). - SFL-Compliant Analysis: The analysis pipeline (Session & Prompt Quality) enforces Systemic Functional Linguistics (SFL) constraints.
- Structured Prompts: Uses explicit XML boundaries (
<task>,<context>,<rules>,<output_schema>) for deterministic LLM behavior. - Rage Loop Detection: Includes a pre-analysis heuristic (
loop-detector.ts) to identify temporal loops and static token count stasis, flagged to the LLM as a dedicated friction category. - Methodological Narratives: Session summaries strictly forbid mechanical file listing; they must capture analytical methodology, power dynamics, and workflow milestones.
- SFL Breakdown: Findings and takeaways include a mandatory
sfl_breakdown(Ideational, Interpersonal, Textual) to log structural design choices. - Dimension Scoring: Scoring (0–100) is anchored by hard SFL constraints (0=catastrophic, 50=baseline, 100=flawless).
- Structured Prompts: Uses explicit XML boundaries (
- Analysis Queue: Asynchronous job system for LLM tasks. Managed via
cli/src/db/queue.tsand processed bycli/src/analysis/queue-worker.ts. Supports multi-level native fallbacks (Codex → Claude → Gemini). - Testing:
vitestis the primary test runner. Tests are in__tests__/directories adjacent to source. - Privacy: Local-first. No session data is sent to the cloud except to user-configured LLMs for analysis.
- Parsing: Robust structural lookahead and
jsonrepairfor handling malformed LLM responses. - Hooks: Automate sync and analysis via
code-insights install-hook. Includessession-endhook for immediate background queueing.
Code Insights supports multiple providers for analysis and synthesis.
- Native Runners: Zero-config analysis using locally installed CLIs. Supports Codex (default native), Claude Code, and Gemini CLI. Features automatic usage-limit fallback:
Codex→Claude→Gemini. Updated: Optimized native extraction to handle session-end hooks and background processing. - Supported Providers: OpenAI (GPT-4o), Anthropic (Claude 3.5), Google Gemini (2.0 Flash), OpenRouter, Mistral (Codestral), and Ollama (Local).
- Dynamic Discovery: Supports fetching latest models via
POST /api/config/llm/models. - Cost Tracking: Per-session and per-analysis cost tracking stored in
analysis_usage.
- OpenCode: Now features robust multi-schema support. Handles both legacy column-based storage and the latest JSON-in-SQLite
datacolumn format for messages and parts. - Sub-Agent Bundling: Providers like
Gemini CLIandHermes Agentnow align with a sub-agent model, recursively discovering and merging sub-agent interactions into the parent session for holistic analysis. - Background Sync: The
ON CONFLICTstrategy in the database layer ensures that forced syncs (--force) correctly refresh message content and metadata from the source providers.
- OpenRouter:
/openrouterteam/typescript-sdk - Mistral:
/mistralai/client-ts - Anthropic:
/anthropics/anthropic-sdk-typescript - OpenAI:
/openai/openai-node - Google Gemini:
/google/generative-ai
cli/src/index.ts: CLI entry point (Commander.js).cli/src/db/schema.ts: SQLite schema and migrations (V1–V7).cli/src/db/queue.ts: Analysis queue operations.cli/src/analysis/queue-worker.ts: Background worker logic.cli/src/providers/: implementations for 9+ source tool providers.server/src/index.ts: Hono server and API route mounting.dashboard/src/App.tsx: Main dashboard entry.docs/ARCHITECTURE.md: Detailed system architecture.docs/DEVELOPMENT.md: Comprehensive development guide.
This project has a graphify knowledge graph at graphify-out/.
Rules:
- Before answering architecture or codebase questions, read graphify-out/GRAPH_REPORT.md for god nodes and community structure
- If graphify-out/wiki/index.md exists, navigate it instead of reading raw files
- After modifying code files in this session, run
graphify update .to keep the graph current (AST-only, no API cost)