So, i wanted to build this code-insights into a platform that can be used to build a historical learnings and decisions for a given product/codebase. How can i use this learnings and decisions we generate from AI session conversations and attach them into the codebase to make the learnings and decisions stick with the repo and not just user's session within code-insights? I am trying to may be replicate entire.io related features but more native to code-insights.. Explore how entire.io works and then also look at our product to analyze how can we do this best.. Invoke multiple agents within our project and some exploratory agents to research into this..
Assistant
Launching three parallel agents: one to explore the code-insights codebase deeply, one to research entire.io and adjacent tools, and one for strategic product analysis.
Assistant
Now launching the external research agent and strategic analyst in parallel:
Assistant
Three agents are now running in parallel:
Codebase Explorer — tracing the session analysis pipeline, reflect feature, SQLite schema, and export capabilities in the actual code
Competitive Researcher — investigating entire.io, ADR tools, memory MCP servers, the Codebase Context Specification, and the dominant patterns for attaching knowledge to repos
Product Strategist (devtools-cofounder) — analyzing whether this fits the product vision, what the differentiation angle is vs. entire.io, and what the killer use case looks like
★ Insight ─────────────────────────────────────
Running these three agents in parallel is a key pattern for large brainstorming sessions: the codebase explorer grounds decisions in what already exists, the researcher prevents reinventing the wheel, and the strategist filters by user value rather than just technical feasibility. The convergence of these three lenses is where good product decisions come from.
─────────────────────────────────────────────────
I'll synthesize all three when they complete and then start the brainstorming dialogue with you — one question at a time per the process. This should give us a much richer foundation than starting cold.
Assistant
The codebase exploration is done — incredibly rich findings. Here's what jumped out as directly relevant to your idea:
★ Insight ─────────────────────────────────────
code-insights already captures exactly the right primitives for codebase-attached knowledge — decisions (title, situation, choice, reasoning, alternatives, trade_offs, revisit_when), learnings (symptom, root_cause, takeaway, applies_when), and friction attribution at the session level. The gap isn't data capture — it's linkage: there's no connection between these structured insights and the actual files/commits they relate to.
The analysis_usage table even tracks which git branch was active. And the export feature already generates CLAUDE.md-compatible "agent-rules" format — meaning there's a direct path from session insight → codebase instruction file.
─────────────────────────────────────────────────
Key structural observations worth holding onto for the design:
insights table already has a scope field (session | project | overall) and linked_insight_ids — designed for cross-linking but currently unused for codebase attachment
Export already produces "agent-rules" format (imperative CLAUDE.md/.cursorrules style) — the formatting pipeline is done, only the destination and trigger are missing
reflect → rules-skills section generates claudeMdRules[] and hookSuggestions[] already — these are candidate learnings that could be persisted to the repo
No git commit-level attribution yet — sessions capture gitBranch but not the commit SHA that was active during the session
Still waiting on the entire.io research and product strategy agents. Once those land, I'll synthesize everything and start the first clarifying question. The research foundation is shaping up to be very strong.
User
This comprehensive structure provides a strong foundation for attaching learnings to codebases while maintaining the local-first privacy model and supporting multiple AI coding tools.
<total_tokens>98100</total_tokens><tool_uses>32</tool_uses><duration_ms>108006</duration_ms>
/cli/src/analysis/native-runner.ts — Use claude -p (zero-config, via Claude Code subscription)
/cli/src/analysis/provider-runner.ts — Use configured LLM provider (OpenAI/Anthropic/Gemini/Ollama)
Assistant
The strategic analysis is in — and it's sharp. Still waiting on the entire.io researcher. While we wait, here's what the strategist landed on that I think is the most important framing shift:
★ Insight ─────────────────────────────────────
The strategist made a critical architectural argument: codebase-attached knowledge is not a 4th product layer — it's a new export target. The product journey stays Sessions → Insights → Reflect → Progress, and .code-insights.md is a write destination that sits alongside Obsidian/Notion in the existing Export pipeline. This means no new data model, no new architecture — just a new output format for intelligence that already exists.
─────────────────────────────────────────────────
Three things from the strategic analysis I want to hold for the design conversation:
The killer use case is onboarding: A new developer inheriting a codebase with 400+ AI sessions runs code-insights export --format repo and gets a .code-insights.md that tells the codebase's story — architectural decisions, friction hotspots, effective patterns. All from sessions the original developer never curated. Zero effort.
The moat is zero-effort generation: entire.io requires humans to write knowledge. code-insights extracts it from real session data. That's the fundamental differentiator — freshness + coverage with no authoring burden.
The privacy landmine is real: Sessions can contain sensitive data (API keys in error messages, internal service names). Any export-to-repo feature needs a prominent "review before committing" warning + a sensitive-pattern scrubber pass before the file is written.
Waiting on the competitive research agent to complete before we synthesize and start the first clarifying question.
User
That is the holy-shit moment: a codebase that can tell its own story, extracted from the actual work that happened in it, with zero effort from the original developer.
The key insight: this only works because code-insights already parses the sessions and generates insights. The .code-insights.md file is not a new capability — it is a new surface for existing intelligence. The previous developer did not do anything special. They just used Claude Code (or Cursor, or Codex) normally. Code Insights did the rest.
Where It Could Go Wrong
Three failure modes to watch:
Quality floor. If the generated .code-insights.md is vague, generic, or wrong, developers will never trust it again. The export LLM synthesis needs to be significantly better than "this codebase uses React and has some tests." It needs specific, dated, falsifiable claims. This is a prompt engineering challenge, not an architecture challenge.
Privacy landmine. AI session data can contain sensitive information — API keys in error messages, internal service names, infrastructure details. If someone commits a .code-insights.md to a public repo and it contains "debugging the AWS credentials rotation for prod account 123456789," that is a security incident. The export pipeline MUST strip sensitive patterns, and the file MUST have a prominent "review before committing" warning.
Scope creep toward team features. "Codebase knowledge" naturally leads to "team knowledge." Resist this. The moment you add "merge knowledge from multiple developers' sessions," you need conflict resolution, attribution, access control, and you have become a different product. The file is generated from one developer's sessions. If a team wants shared knowledge, they each generate their own and the team decides what to keep. That is a social process, not a product feature.
Bottom Line
Build it as an export format, not a product layer. The repo-attached file is a new output target for existing cross-session synthesis. Frame it as "your repo can remember what you learned" — not "codebase knowledge management." Start with a single .code-insights.md file, explicit opt-in, and the killer use case of onboarding context. If it gets traction, expand. If it does not, it cost you one new export format — not a major architectural bet.
The entire.io comparison is a red herring. They are building a team knowledge platform. You are building a personal learning tool that happens to produce artifacts useful enough to commit. Those are different products that happen to touch the same noun ("codebase knowledge"). Do not chase their feature set. Your moat is zero-effort generation from real session data across multiple AI tools. Lean into that.
<total_tokens>42610</total_tokens><tool_uses>5</tool_uses><duration_ms>116141</duration_ms>
User
Maya is a senior developer who just joined a team. She inherits a 3-year-old codebase. There is a README from 2023. There is a CLAUDE.md that says "use React" and not much else. The original developer left six months ago.
Maya installs code-insights. She runs code-insights sync --source claude-code. The tool discovers that the previous developer had 400+ Claude Code sessions in this project directory over the past year.
She runs code-insights export --format repo --project my-service --depth comprehensive.
A .code-insights.md file appears at the project root. It contains:
8 architectural decisions extracted from sessions where the developer debated approaches with Claude. "Chose event sourcing over CRUD for the audit log because of compliance requirements (2025-11-14)." "Switched from Prisma to Drizzle after hitting the N+1 query issue in the billing module (2026-01-08)."
Top friction hotspots: "The payment module consistently causes stale-assumptions friction — the Stripe API versioning has been a recurring source of bugs across 12 sessions."
Effective patterns: "Structured planning with acceptance criteria before implementation reduced rework by an estimated 40% in sessions after 2025-12."
Maya reads this file in 5 minutes and has more context about this codebase than she would get from a week of code archaeology. She commits it to the repo so the next person gets this too.
User
Strategic Assessment: Codebase-Attached Knowledge
1. Product-Market Fit: Does This Strengthen or Dilute?
This is the central question, and the answer is: it depends entirely on the framing.
Code Insights today is a personal learning tool. The value prop is clear: "understand your AI coding sessions, get better over time." The product journey is introspective — Sessions, Insights, Reflect, Progress (upcoming). Everything flows from "I had AI sessions" to "I learned something about myself."
Codebase-attached knowledge introduces a fundamentally different value prop: "this repo knows things about itself." That is not personal learning. That is institutional knowledge management. Those are different products serving different jobs-to-be-done.
The dilution risk is real. The moment you start talking about "attach knowledge to repos," you sound like a documentation tool, a wiki, a knowledge graph. You invite comparison to Notion, Confluence, entire.io, and every "living documentation" startup that has tried and mostly failed over the past decade.
But there is an additive version. The key insight is that code-insights already generates repo-scoped knowledge as a side effect. You already have:
Per-project friction patterns ("this codebase causes knowledge-gap friction 3x more than others")
Per-project decisions captured in session insights
Per-project effective patterns ("structured-planning works best in this repo")
The additive version is not "attach arbitrary knowledge to repos." It is: "surface what code-insights already knows about this project, in a format the project can keep." That is a natural extension of export — not a new product layer.
The dilutive version is: "let users write, edit, curate, and manage knowledge documents attached to their codebase." That is a content management system. Hard no.
2. Differentiation vs. entire.io
Entire.io (from what I can infer from its positioning) is a team-oriented SaaS tool that attaches institutional knowledge to codebases. It likely requires:
Team accounts and authentication
Cloud infrastructure for knowledge storage and search
Manual knowledge creation and curation workflows
Integration with code review and onboarding processes
Code Insights' unique angle is that the knowledge is generated, not authored. Nobody sits down and writes "here's what this repo has learned." The knowledge emerges automatically from analyzing actual AI coding sessions. This is a fundamentally different acquisition model:
Assistant
All three agents are done. Here's the full synthesis before we start the design dialogue:
★ Insight ─────────────────────────────────────entire.io's most interesting architectural choice is the orphan branch strategy (entire/checkpoints/v1) — a disconnected-history git branch that accumulates session metadata linked to commits via a Entire-Checkpoint: git trailer. It keeps your main history clean. But its fatal flaw: an orphan branch isn't fetched by default on git clone, so knowledge doesn't automatically travel with the repo. ADRs (doc/adr/) are 15 years old and still win on "stickiness" precisely because they're plain files committed to main — they survive clones, forks, team rotation, and offline use with zero extra tooling.
─────────────────────────────────────────────────
The convergence from all three agents:
Question
Consensus Answer
Architecture shape
Export format (not new product layer) — builds on existing export pipeline
Storage primitive
Markdown files committed to git repo (not orphan branch, not SQLite sidecar)
Where it fits
Alongside Obsidian/Notion in the Export page; new CLI format flag
Explicit opt-in command only — never auto-generated
Biggest risk
Privacy: sessions contain sensitive data that could be committed publicly
Differentiator
Zero-effort generation from real session data — nobody else does this
What entire.io does differently
Raw transcript preservation (the full conversation); code-insights does structured extraction (the meaning)
The two tools actually complement rather than compete: entire.io saves the raw "what happened", code-insights extracts the "what it means."
Now let me start the brainstorming questions. Only one at a time.
Question 1 of several:
When you imagine someone reading the codebase-attached knowledge file, who is the primary reader you're designing for?
A) Yourself, future sessions — You run a new AI session on this repo three months from now, and the file gives the AI agent instant context: past decisions, known friction hotspots, proven patterns. It feeds directly into CLAUDE.md or is auto-loaded into agent context.
Context rot — DEV Community
<total_tokens>56465</total_tokens><tool_uses>42</tool_uses><duration_ms>441038</duration_ms>
User
Key Gaps Relevant to code-insights
Given code-insights already captures cross-session patterns and friction points in SQLite, the missing piece for "codebase-attached learnings" is:
No durable export layer — learnings live only in SQLite, not committed to the repo alongside the code. A developer who clones the repo gets none of the accumulated insights.
No per-repo knowledge attachment — code-insights is a global tool (~/.code-insights/data.db), but learnings are most useful when repo-scoped and co-located.
No replay/resume mechanism — unlike entire.io, there's no way to start a new session and say "show me what I learned last time I worked on this repo."
No staleness tracking — there's no mechanism to detect when a captured learning has become stale (the code it referred to has changed significantly).
The opportunity: code-insights is already doing the hard part (extracting structured friction points, effective patterns, and prompt quality insights from AI sessions). The feature gap is surfacing those back as repo-attached files — a docs/ai-learnings/ or .code-insights/learnings/ directory of committed markdown, generated from the SQLite analysis, that travels with the codebase.
User
4. The Stickiness Problem
"Stickiness" = does the knowledge stay with the codebase, not the person?
The scorecard across scenarios:
Storage Approach
git clone
git fork
Team rotation
Offline
Rebuild-able
Markdown files in repo
YES
YES
YES
YES
N/A
ADRs in doc/adr/
YES
YES
YES
YES
N/A
SQLite sidecar (gitignored)
NO
NO
NO
YES
YES (from files)
SQLite committed
YES*
YES*
YES*
YES
N/A
Orphan git branch (entire.io)
PARTIAL**
NO
PARTIAL**
YES
YES
Memory MCP server (local)
NO
NO
NO
YES
NO
External cloud service
NO
NO
NO
NO
NO
Inline code comments
YES
YES
YES
YES
N/A
*Committing a SQLite binary is technically valid but generally terrible practice — diffs are unreadable, merges are impossible, file size grows unboundedly.
**entire.io's orphan branch: a git clone does NOT fetch orphan branches by default. You need git fetch origin entire/checkpoints/v1 explicitly. This is a significant gap in the model — knowledge doesn't transfer on a standard clone.
The best-practice answer from the ecosystem: The tools that solve stickiness best are those that use plain files committed to the repo. ADRs are 15 years old and still the gold standard precisely because they survive everything — a developer reading a 10-year-old doc/adr/ folder gets the full decision history with zero tooling.
The pattern emerging in 2025 is a two-layer hybrid:
Durable layer: markdown files committed to git (docs/learnings/, docs/decisions/, CLAUDE.md updates) — for long-lived institutional knowledge that must survive team rotation and forks
Fast index layer: SQLite (local, rebuilt from the durable layer) — for querying, semantic search, aggregation, and surfacing knowledge in dashboards
The tools that conflate these two layers (only SQLite, only orphan branch, only memory server) are solving the wrong half of the problem. Knowledge that isn't committed to the main repo eventually gets lost.
# WHY: polling instead of webhooks — vendor API doesn't support event subscriptions as of 2025-03
# DECISION: SQLite over PostgreSQL — local-first constraint, no multi-user requirement
# TRADEOFF: synchronous DB writes sacrifice throughput for simplicity in the hook path
Pros:
Maximum "stickiness" — lives in the code file itself, can't get out of sync
Survives forks, team rotation, clones, IDE searches, grep
Naturally decays with the code it describes (not a stale doc somewhere)
Zero tooling to read
Cons:
Not queryable or aggregatable across the codebase
Undiscoverable unless you happen to read that file
No structured schema — freeform
Pollutes code with non-code
Doesn't capture session-level learnings, only file-level decisions
Best for local-first, open-source? Useful as a complementary layer for point-of-decision capture, not as the primary store. Repowise's approach of extracting these into a structured decision graph is the right amplifier for this pattern.
User
Approach 2: Sidecar Database (SQLite alongside the repo)
Doesn't survive team rotation unless the DB file is explicitly shared/committed (bad idea for binary blobs)
Requires tooling to query — can't be read in a terminal or IDE
Best for local-first, open-source? YES as the queryable/fast layer, but never as the sole store. The pattern is: markdown files as source of truth (committable, portable), SQLite as the index (local, fast, rebuiltable). This is exactly what basic-memory and sqlite-memory do.
User
3. The Four Dominant Approaches
Approach 1: File-in-Repo (Markdown/YAML committed to git)
No semantic retrieval (can't ask "what decision covered this pattern?")
Gets stale if not maintained actively — "context rot"
Monolithic files don't scale past medium codebases
Manual capture — requires developer discipline to write
Best for local-first, open-source developer tools? YES, this is the foundation layer. It's the only approach that survives all the "stickiness" scenarios (rotation, fork, clone, offline). Treat it as the durable/canonical store.
User
sourcebook (maroondlabs, 2025)
Convention-inference focused. Samples source files to detect naming, import/export patterns, error handling conventions, and type annotation styles. Outputs to CLAUDE.md / AGENTS.md. Runs as an MCP server. Smart about token budgets: critical constraints at top/bottom of output, supplementary info in the middle (exploiting LLM attention patterns). Generates what agents "keep missing" — conventions not inferable from code, fragile areas, hidden dependencies.
User
Repowise (emerging, 2025)
The most architecturally interesting new entrant. Combines four intelligence layers in one self-hosted tool:
Dependency graph — tree-sitter AST parsing across 14 languages, file/symbol relationships stored in NetworkX graphs + LanceDB embeddings
Git history analysis — classifies files as hotspots (high churn + complexity), computes ownership, detects co-change coupling
Auto-generated docs — CLAUDE.md and wiki pages as output
Architectural decisions — captured three ways: CLI-guided capture (repowise decision add, ~90 seconds), git commit message mining (auto-proposes), and inline markers (# WHY:, # DECISION:, # TRADEOFF: in code comments)
Decisions link to specific graph nodes and track staleness as code evolves. Surfaced by get_why() whenever the AI agent touches a governed file. Seven MCP tools: get_overview(), get_answer(), get_context(), search_codebase(), get_risk(), get_why(), get_dead_code().
This inline-marker approach is underexplored and powerful: # WHY: we use polling here because the vendor API has no webhooks lives in the code itself, is never stale (it decays naturally when the code is deleted/changed), and requires zero tooling to read.
User
Greptile
Cloud SaaS, not local. Indexes GitHub repos via AST parsing → generates docstrings for every node → embeds docstrings → builds a graph of file/function/dependency relationships. Retrieval uses semantic similarity + keyword search + "agentic search" (agent traces references to find connections). Provides codebase Q&A via API. No local option. No "attach to repo" model — it's an external indexed service. Doesn't capture learnings from sessions; it indexes existing code.
User
Memory MCP Servers
Cline Memory Bank:
The canonical pattern for session-persistent AI context. Structure:
Cline reads ALL files at the start of EVERY task. Updates fire when new patterns are discovered, after substantial changes, or on explicit "update memory bank" command. Files stay brief (1-2 pages) to minimize context consumption.
The critical limitation: memory-bank lives outside the repo (or is gitignored). It does NOT survive team rotation or repo forks by default. It's personal/machine context, not codebase context.
basic-memory:
More sophisticated: stores knowledge as local markdown files indexed in SQLite (with optional PostgreSQL). Files use structured frontmatter + semantic observation syntax:
yaml
---
title: "Entity Title"
type: "note"
permalink: "entity-slug"
tags: [optional]
---
- [method] Pour over extracts more floral notes #brewing
- [tip] Grind size should be medium-fine for pour over
- [decision] Chose SQLite over PostgreSQL for local-first simplicity
Relations use WikiLink syntax: - related_to [[Other Entity]]
Exposed via MCP tools: write_note(), read_note(), build_context(url, depth), search() (full-text + semantic vector via FastEmbed). The knowledge graph is traversable. Optional cloud sync available.
Key design insight: the dual-layer model (Markdown as source of truth + SQLite as query layer) is the right architecture for local-first tools. Markdown is human-readable and git-committable; SQLite is fast and queryable.
OpenMemory MCP (mem0):
Docker-first (Postgres + Qdrant + API). Heavy infrastructure. Overkill for local dev tools. Adds ACL between apps and memories. Not repo-attached by design — it's a shared cross-app personal memory layer.
User
Codebase Context Specification (CCS)
Proposed by Agentic Insights, archived October 2025 (meaning it was superseded by CLAUDE.md/AGENTS.md becoming de facto standards).
Directory: .context/ at project root (and optionally at significant module levels).
Three-tier hierarchy: root (project-wide) → module (component-specific) → feature (implementation detail), each inheriting from parent.
Why it was archived: CLAUDE.md became the winner for this space. Research showed 72.6% of Claude Code projects specify application architecture in a root CLAUDE.md, and presence of AGENTS.md was associated with 29% reduction in median runtime and 17% reduction in output tokens. The format war settled on flat markdown files over structured YAML directories.
# NUMBER. TITLE
Date: YYYY-MM-DD
## Status
Accepted | Proposed | Deprecated | Superseded by [ADR-NNNN]
## Context
The issue motivating this decision, and any context that influences or constrains it.
## Decision
The change that we're proposing or have agreed to implement.
## Consequences
What becomes easier or more difficult, and any risks introduced.
When one ADR supersedes another, adr-tools automatically inserts hyperlinks between them.
100% files in git — survives forks, team rotation, clones natively.
MADR (Markdown Any Decision Records, v4.0.0 released 2024-09-17):
Directory: docs/decisions/
Naming: NNNN-title-with-dashes.md
Richer template adds: Decision Drivers, Considered Options (with pros/cons per option), Validation section, optional metadata frontmatter.
Four variants: adr-template.md, adr-template-minimal.md, adr-template-bare.md, adr-template-bare-minimal.md.
log4brains:
Wraps MADR, hosts as a searchable static website.
Date-based filenames (YYYYMMDD-adr-name) to avoid git merge conflicts.
Adds concept of "knowledge bases" per package in monorepos.
Status: mostly dormant maintenance mode as of 2025.
Key insight for code-insights: ADRs are the most battle-tested "file-in-repo" pattern for institutional decisions. The immutability of ADRs (only status can change) is a deliberate design — it prevents revisionism and creates an audit trail. The critical missing piece: ADRs document decisions made before writing code; they don't capture learnings extracted from AI sessions after the fact.
User
1. entire.io — Deep Dive
What it is: entire.io is a git-native, MIT-licensed CLI tool (open source at github.com/entireio/cli) that captures AI agent sessions alongside git commits. The core pitch: when you push code, the "why it was written this way" — the full agent conversation, prompts, token usage, file diffs — is preserved and searchable.
The problem it solves: Three hard problems: (1) lost session context ("why was this written this way?"), (2) agent amnesia between sessions (new sessions have zero knowledge of past decisions), (3) attribution — which lines were human vs. agent-written.
Technical architecture — storage model:
The storage model is the most interesting part. Entire uses a dual-branch git strategy:
Shadow branches (ephemeral, local-only): entire/<hash> — named by combining the first 7 chars of HEAD + a worktree ID. These are temporary working refs during an active session.
Orphan metadata branch (persistent): entire/checkpoints/v1 — a disconnected-history branch that accumulates all session metadata and gets pushed alongside your normal branches, keeping main history clean.
Your working branch never gets any Entire commits. The metadata branch carries everything.
Checkpoint file structure on entire/checkpoints/v1:
Checkpoints are identified by 12-char hex IDs (6 random bytes, sharded into 2-char directories for filesystem performance). A git commit trailer Entire-Checkpoint: a3b2c4d5e6f7 links each code commit back to its session metadata.
Configuration files:
.entire/settings.json — committed to repo, team-shared settings
.entire/settings.local.json — personal overrides, gitignored
Each AI tool gets its own hook file (claude/settings.json, .cursor/hooks.json, .codex/hooks.json, .gemini/settings.json).
User
Research Summary: Codebase-Attached Learnings — Ecosystem & Design Patterns
User
I'd say both.. It should help both AI Agents and Humans who want to know why we built what we built and how we built it..
Assistant
Good — both as equal first-class readers. That's actually the harder design challenge, because the two audiences want the same content in very different shapes:
AI agents want dense, imperative instructions: "Use event sourcing for audit logs. Never mock the payment module. Grind size is medium-fine." Think CLAUDE.md rules format — terse, actionable, scannable.
Humans want narrative + reasoning: "We chose event sourcing on 2026-01-08 after hitting audit retention issues with CRUD. Alternatives considered: CDC with Debezium, but operational complexity was too high." Think ADR format — dated, reasoned, with context.
Same underlying knowledge, very different presentation.
Question 2:
Should this be one unified file that tries to serve both, or two distinct outputs — one AI-optimized and one human-optimized?
A) One file, two sections — A single .code-insights.md (or docs/LEARNINGS.md) with clearly separated sections: a "Rules & Patterns" block at the top (AI-readable, CLAUDE.md-importable) followed by an "Architectural Decisions" block below (human-readable narrative with dates and reasoning).
B) Two separate outputs — The AI-optimized content updates/feeds CLAUDE.md directly (or .cursorrules), while a separate docs/decisions/ folder gets ADR-style markdown files generated per decision. Two files, two jobs, no compromise.
C) One structured file with a machine-readable header — A single file with YAML frontmatter (rules, patterns in structured form) followed by human-readable narrative sections — so both a human reading it and an AI parsing it can consume it well.
The choice here determines the file structure, the update model, and whether this feels like a "document" or a "configuration."
User
C might be better.. In fact, i want to post this on LinkedIn and ask for user feedback.. Build a post talking about my message and your research insights and converge at this point seeking feedback and put out my opinion as well instead of leaving it blindly on user feedback.. Build a draft for LinkedIn and save the research insights into docs somewhere and commit
Assistant
Good. Now let me draft the LinkedIn post:
LinkedIn Post Draft:
I've been thinking about a problem that bothers me every time I start a new AI coding session.
Six months of working with Claude Code, Cursor, and Copilot have generated hundreds of sessions. In those sessions: hard-won architectural decisions, friction patterns that keep recurring, techniques that actually work. All of it extracted, analyzed, and sitting in a local SQLite database on my machine.
But when I open a new session? The AI agent knows nothing. When a new developer joins the project? They start from zero.
The knowledge generated FROM working on a codebase never sticks TO the codebase.
I've been researching how others have tried to solve this:
entire.io captures full AI session transcripts alongside git commits via an orphan branch strategy — brilliant for preservation, but the transcripts don't survive a standard git clone
ADRs (Architecture Decision Records) are 15 years old and still the gold standard for stickiness — plain markdown files committed to git, surviving clones, forks, team rotation, and offline use with zero extra tooling
Cline Memory Bank, basic-memory, mem0 — good at per-session persistence, but fundamentally personal. Doesn't travel with the repo.
Repowise takes an interesting approach: inline # WHY: / # DECISION: markers in code itself — knowledge that decays naturally when the code changes
The pattern I keep coming back to: the tools that solve "stickiness" best are always the ones that commit plain markdown files to the repo itself.
Here's what I want to build into code-insights:
A code-insights export --format repo command that generates a .code-insights.md file at your project root — structured YAML frontmatter for AI agents to parse, followed by human-readable sections for developers to read.
Not another documentation tool. Not a wiki. The content is generated automatically from AI session analysis — decisions extracted from your actual coding sessions, friction hotspots that keep recurring, patterns that consistently work. Zero authoring effort.
The killer use case: you inherit a codebase where the original developer had 400+ AI sessions. Run one command. Get a file that tells the codebase's story — dated architectural decisions, known friction areas, proven approaches — in 5 minutes instead of a week of code archaeology.
My take: This should be an export format, not a new product layer. Build on what already exists. Keep it a single file — reviewable, deletable, optionally -able (personal) or committed (shared).
Assistant
docs/plans/ is intentionally gitignored — it's marked "Transient implementation plans" in .gitignore. The research doc is saved locally and will stay there as a working reference. That's actually correct — it's a brainstorming artifact, not production docs. Once we design this feature and write a proper spec, that will also live in docs/plans/ locally.
★ Insight ─────────────────────────────────────
The docs/plans/ gitignore pattern is an interesting project convention — it keeps in-progress design thinking local and out of the repo history, preventing half-baked ideas from cluttering the public codebase. Only finished features get their architectural decisions captured in docs/ARCHITECTURE.md. This is a clean separation between "thinking" and "decided."
─────────────────────────────────────────────────
So the state is:
Research doc saved at docs/plans/2026-04-20-codebase-knowledge-research.md — local working reference, not committed (by design)
LinkedIn post draft above — ready for you to review and edit
A few things you might want to adjust in the post:
The closing question — I framed it as root vs. docs/decisions/. You could sharpen this if you already have a leaning toward the single-file approach.
Length — It's ~500 words, which is on the longer side for LinkedIn but works well for thought-leadership posts in the dev tools space. Could be trimmed if you prefer.
The call-to-action — Currently asking about file location. Could instead ask "have you tried entire.io or similar tools — what was your experience?" to get more competitive intelligence from your network.
Want me to adjust the draft before you post? Also — back to the brainstorming: we were at Question 2 (file shape) with Option C as the preferred direction. Shall I continue the remaining questions after you've posted, or run them now?
User
the post feels too large.. shorten it.. don't use jargon - keep it natural and conversational
Assistant
Here's a tighter version:
Every time I start a new AI coding session, I feel this gap.
Months of working on a codebase with Claude Code and Cursor. Hundreds of sessions. Hard-won decisions, patterns that worked, mistakes I'll never repeat. All of it analyzed, structured, sitting in a database on my machine.
But the next session? The AI knows nothing. A new developer joining? Starts from scratch.
The knowledge built from working on a codebase never sticks to the codebase.
I've been digging into how others solve this — entire.io (stores full AI session transcripts alongside your git commits), ADR tools (plain markdown decisions files committed to the repo), memory banks. Each solves part of it.
What I want to build: a single command that generates a file at your project root — auto-written from your actual AI session history. Architectural decisions you debated, recurring problems, patterns that consistently worked. Nothing to author. Just runs against sessions you already have.
The use case that keeps pulling me in: a developer inheriting a codebase where the original dev had 400+ AI sessions. One command, five minutes of reading, and you understand why things were built the way they were.
One question I'm genuinely unsure about: Would you want this as a single file at the project root, or individual decision files inside docs/?
Curious what developers who've used entire.io, ADRs, or Cursor's memory features think — what actually stuck, and what didn't?
About 230 words. Want me to adjust the open question or tweak the ending?
User
this is good. but now, design the solution for this.. seek inputs from @"ux-engineer (agent)" and @"technical-architect (agent)" and design a product requirement so it can be reviewed with @"devtools-cofounder (agent)" and @"technical-architect (agent)" again before starting any implementation work..
Assistant
We have rich enough context from the research phase to move into design. Launching UX-engineer and Technical-architect in parallel — each will explore their domain, then I'll synthesize their findings into a PRD, which goes to devtools-cofounder + technical-architect for a final review pass before any implementation begins.
Assistant
Both design agents are running in parallel:
UX-engineer — exploring the existing export CLI flow, dashboard Export page, and current format patterns, then designing the full user experience: CLI commands, terminal output, the .code-insights.md file structure with real example content, dashboard integration, discoverability, and the update flow
Technical-architect — reading the export pipeline, reflect routes, schema, and types, then designing: export pipeline extension, project root detection, file generation mechanics, the update/merge strategy (including sentinel comment patterns), sensitive data scrubbing, schema changes, AI agent consumption model, and every file that needs to change
★ Insight ─────────────────────────────────────
Running UX and TA in parallel before writing the PRD is a key pattern: UX explores the "what does the user experience" axis while TA explores the "what does the system do" axis. They often surface different constraints — UX might design a "preview before write" flow that TA then needs to assess for feasibility against the SSE streaming architecture. Having both complete before writing the PRD means the spec won't have UX decisions that are technically awkward, or technical shortcuts that produce bad UX.
─────────────────────────────────────────────────
Once both complete, I'll synthesize their findings into the full PRD, then run it past devtools-cofounder and technical-architect for a final review pass. Nothing gets implemented until that review is done and you've approved the spec.
Assistant
Excellent — the Technical Architect has delivered a very thorough design. Let me capture the key decisions while waiting for the UX-engineer to complete.
Assistant
★ Insight ─────────────────────────────────────
The TA made two particularly sharp calls worth noting: (1) YAML frontmatter is code-generated, not LLM-generated — this is the right separation of concerns. The structured, machine-readable data must be deterministic. LLMs hallucinate in structured formats; letting code generate it from SQLite aggregations guarantees correctness. (2) No schema change needed — the feature is stateless. The .code-insights.md file is the artifact, always regenerable from existing data. Deferring a repo_exports tracking table is disciplined scope control.
─────────────────────────────────────────────────
The sentinel-based merge strategy is also elegant — <!-- code-insights:generated-start --> / <!-- code-insights:generated-end --> lets the tool refresh its own sections while preserving anything the user adds outside those bounds. It's the same pattern used by tools like Prettier's // prettier-ignore and ESLint's /* eslint-disable */ — a well-understood convention developers already trust.
Still waiting on the UX-engineer. Once that lands, I'll synthesize both into the PRD.
User
Summary of Key Decisions
Decision
Rationale
Reuse /api/export/generate endpoint
Avoids duplicating ~100 lines of query/orchestration code
YAML frontmatter is code-generated, not LLM-generated
Guarantees structural correctness for machine parsing
Sentinel-based merge (not overwrite)
Preserves user-added content while refreshing generated sections
No schema change (V10 deferred)
Feature is stateless -- file on disk is the artifact, always regenerable
Recommendation: Reuse the existing /api/export/generate endpoint with format: 'repo'
The repo format fits cleanly into the existing pipeline. The endpoint already supports multiple formats, SSE streaming, scope/depth/projectId parameters, and LLM synthesis. The only difference is that the CLI writes the output to a file instead of displaying it in the dashboard -- but that is a CLI-side concern, not a server concern.
What changes on the server:
Add 'repo' to the ExportFormat union in server/src/llm/export-prompts.ts:
Update the format validation in server/src/routes/export.ts (both POST and GET handlers) to accept 'repo'.
Add a new system prompt pair in export-prompts.ts and wire it into getExportSystemPrompt().
Why not a separate endpoint: The data fetching logic (fetchScopedInsights, fetchSessionContext, applyDepthCap, buildInsightContext) is identical. The only novel part is the system prompt and a post-processing step to prepend YAML frontmatter. Creating a separate endpoint would duplicate ~100 lines of identical query and orchestration code.
The repo format needs additional data beyond insights. The existing export pipeline only sends insights to the LLM. For .code-insights.md, we also need:
This means the repo format requires a richer context builder that supplements insight data with facet aggregations. The cleanest approach is a new function buildRepoExportContext() in export-prompts.ts that fetches this additional data, called only when format === 'repo'.
New server-side code:
-- new and , new function
Assistant
Both agents are done. One important conflict to resolve before writing the PRD:
TA recommended: Sentinel-based merge (<!-- code-insights:generated-start/end -->) so user-added content is preserved on regeneration.
UX recommended: Full regeneration + diff preview. No user-editable sections — the file is a pure knowledge artifact. Custom rules go in CLAUDE.md.
The UX argument wins here. The file should have a single, clear job: extracted knowledge from sessions. Any content a developer wants to add themselves already has a home (CLAUDE.md). Sentinels create an implicit contract ("everything outside this block is mine") that breaks the file's identity as a read-only artifact. I'll go with full regeneration + diff in the PRD.
Assistant
PRD written to docs/superpowers/specs/2026-04-20-codebase-knowledge-design.md. Now launching the final review pass — devtools-cofounder and technical-architect in parallel:
Assistant
Both reviewers are running in parallel:
Strategic reviewer (devtools-cofounder) — checking the value proposition, scope discipline, the "no merge/pure artifact" decision, adoption friction, privacy warning approach, and whether the PRD is ready to hand to an engineer
Technical reviewer (technical-architect) — grounding the PRD against the actual export.ts and export-prompts.ts code, checking the frontmatter+LLM body split in SSE streaming, the write-to-filesystem endpoint safety, type system impact, and whether the design is complete enough for an implementation plan
★ Insight ─────────────────────────────────────
This two-reviewer pattern mirrors the triple-layer code review process code-insights already uses for PRs — but applied earlier, at the design stage. Catching architectural mismatches or strategic misalignments in a PRD costs almost nothing to fix. The same issue caught after implementation begins costs significantly more. The technical reviewer grounding their feedback in the actual source files (not just the PRD in isolation) is what makes this review meaningful rather than theoretical.
─────────────────────────────────────────────────
Once both land, I'll synthesize their feedback, apply any necessary revisions to the PRD, and then we're ready to move into implementation planning with /writing-plans.
User
Summary of Key Design Decisions
Decision
Choice
Alternative Considered
Rationale
Command name
export --format repo
Dedicated attach command
Reuses existing pipeline; one verb for all exports
The file is fully regenerated every time. No merge, no user-editable sections, no conflict resolution.
Why no merge:
The file mixes YAML frontmatter and narrative markdown. Merging structured YAML with free-form text is a recipe for corruption.
"User-editable sections" sounds good but creates a maintenance trap. Which sections can the user edit? How do we detect their edits during merge? What if they edit the YAML? Every boundary between "auto" and "manual" sections is a bug surface.
Developers already have a file for custom rules: CLAUDE.md. The .code-insights.md file is the extracted knowledge artifact, not a configuration file. If you want to add a custom rule, put it in CLAUDE.md.
Why diff on re-run:
Shows the developer exactly what changed (new rules, updated decisions, revised friction counts).
Familiar mental model -- it's a git diff before committing.
Low complexity -- generate the new file, diff against the old file, show the diff.
Dashboard Update Flow
When the user picks Repo format and a .code-insights.md already exists (detected by the server checking the filesystem):
code
User
4. Discoverability
Where Users First Learn About It
Primary discovery: Export page itself. The Repo format card has a slightly longer description than the others, explaining the dual-audience value prop. No separate announcement, no modal, no banner.
Secondary: After Reflect generates rules. On the Patterns page, where CLAUDE.md Rules are shown, add a one-line hint below the rules card:
code
+--------------------------------------------------------------+
| CLAUDE.md Rules |
| Add these to your AI assistant configuration |
+--------------------------------------------------------------+
| > USE WAL mode for all SQLite connections |
| > Write SQLite migrations as raw SQL... |
| ... |
+--------------------------------------------------------------+
| (info) Want these rules in your repo? Export as Repo File |
| to generate .code-insights.md {Go to Export ->} |
+--------------------------------------------------------------+
This is a single <p> with a link, not a card or CTA block. It appears only when rules exist (not an empty state).
Tertiary: CLI hint after code-insights reflect. After the Rules & Hooks section in the CLI reflect output:
code
Rules & Hooks
CLAUDE.md rules:
→ USE WAL mode for all SQLite connections
→ Write SQLite migrations as raw SQL...
Tip: Run `code-insights export --format repo` to write these
rules (and more) to .code-insights.md in your project.
This hint appears only on the first reflect run (tracked via a config flag hints.repoExportShown). After that, it is silent.
When to Suggest
Do not proactively suggest. The user finds it when they visit Export or Patterns. No pop-ups, no badges, no notification dots. The feature is discoverable through normal navigation, not interruption.
The one exception is the first-time CLI hint after reflect, which is the natural moment when the user is already thinking about rules and where they go.
User
3. Dashboard UX
Export Page: Adding the 5th Format
The existing Step 2 "Output Format" grid currently shows 4 cards in a lg:grid-cols-4 layout. Adding a 5th card breaks this grid.
Solution: Promote the "Repo" format to a visually distinct position -- it is fundamentally different from the other four (writes to filesystem vs. downloads/copies to clipboard).
code
+------------------------------------------------------------------+
| EXPORT [STATUS: draft] |
| Context: /export page, Step 2 (Configure) |
| Breakpoint: desktop |
+------------------------------------------------------------------+
Step 2: Configure
─────────────────
Output Format
+---------------------------+ +---------------------------+
| (FileCode) | | (BookOpen) |
| Repo File | | Agent Rules |
| .code-insights.md with | | Imperative instructions |
| YAML rules + narrative | | for CLAUDE.md or |
| sections. Lives in your | | .cursorrules |
| repo, readable by AI | | |
| agents AND humans. | | |
+--[*SELECTED*]-------------+ +---------------------------+
+---------------------------+ +---------------------------+
| (BookOpen) | | (NotebookPen) |
| Knowledge Brief | | Obsidian |
| Readable markdown — | | Markdown with YAML |
| decisions, learnings, | | frontmatter and |
| and techniques | | wikilinks |
+---------------------------+ +---------------------------+
+---------------------------+
| (StickyNote) |
| Notion |
| Notion-compatible |
| markdown with toggle |
| blocks and callouts |
+---------------------------+
TAILWIND MAPPING:
- Grid: grid gap-3 md:grid-cols-2 lg:grid-cols-2 (NOT 5-col)
- Repo card: same ExportTypeCard component, new icon
- First row: Repo + Agent Rules (the two "for AI agents" formats)
- Second row: Knowledge Brief + Obsidian
- Third row: Notion (alone, left-aligned)
ANNOTATIONS:
- @A: Repo card selected -> Step 3 button changes to "Generate & Preview"
(not "Generate with AI" — signals the different output flow)
- @B: When Repo format selected, depth selector still applies (controls
how many insights feed the synthesis)
User
2. The .code-insights.md File Structure
Design Principles
YAML frontmatter = machine-readable. AI agents parse this block for rules and metadata.
Markdown body = human-readable. Developers scan this for context.
No user-editable sections. The entire file is regenerated on each run. If users want to add custom rules, they put them in CLAUDE.md (which is already the convention). The .code-insights.md file is a read-only knowledge artifact, not a config file.
Deterministic structure. Every section appears in the same order every time. Sections with no data are omitted entirely (not shown as empty).
But there is no CLI export command today -- the export flow is dashboard-only (SSE through the server). The CLI would need a new export command. Given that the dashboard wizard is the primary path, I recommend:
Primary path: Dashboard Export page (wizard, preview, write-to-disk).
CLI shortcut:code-insights export command that hits the same server endpoint.
The core insight shaping every decision below: this file serves two audiences simultaneously -- AI agents (which need structured, parseable rules in YAML) and humans (who need narrative context about why those rules exist). The existing Export pipeline already handles scope selection, depth control, LLM synthesis, and SSE streaming. This format slots in as a 5th option, reusing all of that infrastructure, with one critical difference: the output writes to the filesystem instead of downloading to ~/Downloads.
Assistant
Sharp review from the strategist. Still waiting on the technical architect. While we wait, here are the headline findings so far:
★ Insight ─────────────────────────────────────
The strategist confirmed the "full regeneration, no merge" call and drew a great parallel: package-lock.json, yarn.lock — generated artifacts developers understand not to hand-edit. The clear mental model matters: .code-insights.md = extracted knowledge (read-only). CLAUDE.md = your instructions (editable). No overlap. But they flagged a real gap: token budget and section count caps are unspecified. A project with 400 sessions could produce an unreadable 50-rule, 30-decision file. That's a hard requirement the PRD missed.
─────────────────────────────────────────────────
Strategic review summary — required changes:
Issue
Fix
No token budget defined
Add max input token cap + section count limits (top 12 rules by confidence, top 5 friction by frequency, top 8 decisions by recency)
--yes / -y flag missing
Needed for CI/automation; blocking automation use case
.gitignore suggestion UX
After first write, ask "Add to .gitignore? [y/N]" — default NO (share it)
Recommended but non-blocking: Cut --depth from V1 (ship standard only), add code-insights attach alias, add "file appears hand-edited" detection warning on re-run.
Waiting for the technical architect review to land before applying all changes to the PRD.
User
7. Overall Verdict
PROCEED WITH CHANGES.
This PRD is 85% ready for implementation planning. The core concept is sound, the architecture is elegant (5th export format, no schema change, stateless), and the competitive positioning is strong. The research doc demonstrates genuine strategic thinking.
Required changes before handing to engineering:
Specify token budget and section count caps (gap #1 and #2 above)
Add --yes flag for non-interactive overwrite (friction #3)
Clarify --no-llm behavior with respect to pre-existing reflect rules (gap #6)
Add .gitignore suggestion UX touchpoint after first generation (scope pull-in)
Recommended but non-blocking:
Cut --depth flag from V1 (ship standard only, add later if asked)
Add code-insights attach alias for discoverability
Add "file was hand-edited" detection on re-run
Specify version compatibility contract for frontmatter schema
The feature strengthens Code Insights' unique position as the neutral knowledge extraction layer across AI tools. No competitor does multi-tool retrospective knowledge synthesis to a repo-portable artifact. Ship this.
<total_tokens>39850</total_tokens><tool_uses>2</tool_uses><duration_ms>74848</duration_ms>
User
6. Missing Requirements
Six gaps:
Token budget for LLM call. The PRD specifies no max input/output tokens for the synthesis prompt. A project with 400 sessions and 217 insights could produce a massive context. What is the input cap? How are insights prioritized when they exceed it? The --depth levels hint at this but don't specify the mechanism. Even if you cut --depth, you need a "standard" budget defined.
File size governance. What happens when a project has 50 architectural decisions, 30 friction hotspots, and 40 rules? The file becomes unreadable. The PRD should specify maximum counts per section (e.g., top 10 rules by confidence, top 5 friction by frequency, top 8 decisions by recency). This is a hard cap in the prompt and/or frontmatter builder.
Multi-project monorepo. The PRD handles "monorepo with multiple paths" (line 441: "Use common ancestor with .git") but doesn't address the case where a developer uses Code Insights for multiple distinct projects within one git repo (e.g., apps/frontend and apps/backend as separate Code Insights projects). Should they get one file at the git root or two files? The "require --path" fallback is insufficient UX for this real scenario.
No versioning strategy. The frontmatter has version: 1 but no discussion of what triggers version: 2. When you change the YAML schema (add fields, rename keys), old files become unparseable by new agents. Define the compatibility contract now, even if V2 is far away.
Cost transparency. The LLM call for synthesis will cost money. The PRD doesn't mention estimated cost or whether to show it before/after. Given that other Code Insights features show cost (insights analysis), this should be consistent. Show estimated cost before running, actual cost after.
Offline/no-LLM experience. The --no-llm mode "generates YAML frontmatter only" — but the YAML frontmatter rules array requires LLM synthesis (the rules come from reflect snapshots, which are LLM-generated). Clarify: does --no-llm skip the export LLM call but use previously-generated rules from reflect? Or does it produce a file with friction/patterns from aggregation but no rules? The distinction matters for the zero-config use case.
User
5. The Privacy Warning
The PRD shows the warning in three places:
In the generated file header (HTML comment)
In the CLI terminal output after generation
In the dashboard Step 4 review panel
Assessment: This is the right level. It is not too noisy because:
The HTML comment is invisible in rendered markdown (only appears when viewing raw)
The CLI warning appears once per invocation, which is appropriate
The dashboard warning is contextual (in the review step)
One improvement: The warning text ("file may contain project-specific details from your AI sessions") is vague. Make it specific: "May contain: internal service names, architecture details, error messages from sessions. Does NOT contain: API keys, tokens, or credentials (scrubbed automatically)." This tells the developer what to actually look for during review, rather than a generic "be careful."
User
4. Adoption Friction
Three friction points:
Step
Friction
Severity
Fix
Command invocation
code-insights export --format repo --project my-service is 7 tokens of muscle memory
Medium
Add alias: code-insights attach [project]. Keep export --format repo as the canonical form, but attach is discoverable and memorable. WakaTime uses wakatime-cli --write-summary — short, verb-first.
Project matching
"fuzzy matched; required if multiple projects" — what does fuzzy mean? Levenshtein? Contains?
Low
Specify: if ambiguous, show numbered list and let user pick. Don't silently pick the closest match.
Re-run confirmation
The Overwrite? [y/N] prompt (line 248) blocks CI/automation
Medium
Add --yes / -y flag to skip confirmation. Precedent: npm init -y, rm -f. Needed for any automation use case.
The dashboard flow (Section 4.3) is well-designed — the diff tab on re-run is the right UX. No friction there.
User
3. The "Full Regeneration, No Merge" Decision
Strongly agree. This is the correct call and the rationale in Section 4.5 is persuasive. Three reasons I back it:
Precedent:package-lock.json, yarn.lock, compiled assets — generated artifacts that you don't hand-edit work well in practice. Developers understand "this file is regenerated, don't touch it."
Complexity avoidance: YAML/markdown boundary merging is a bug factory. I have seen this fail in tools like all-contributors (.all-contributorsrc + README injection with sentinels). It is fragile and creates support burden disproportionate to value.
Clear mental model:.code-insights.md = extracted knowledge (read-only). CLAUDE.md = your instructions (editable). No overlap, no confusion.
One risk to acknowledge: If a developer manually tweaks the narrative in .code-insights.md (fixes a factual error in a decision record), their edit gets blown away on next regeneration. The HTML comment "Do not edit" mitigates this, but some users will ignore it. Consider: on re-run, if the file's content doesn't match what the previous generation would have produced (i.e., it was hand-edited), show a warning: "File appears to have been manually modified. Overwrite will lose those changes." This is a low-cost safety net.
User
2. Scope Discipline
Well-scoped overall. Two flags:
Cut candidate: The --depth flag (essential | standard | comprehensive). This adds complexity to the LLM prompt, the CLI UX, and the mental model — and I suspect 90%+ of users will use the default. Ship without depth levels. If users ask for more or less detail, add it then. Convention over configuration.
Pull-in candidate: The PRD says nothing about .gitignore guidance. When the file is first generated, the CLI should explicitly ask or suggest: "Add .code-insights.md to .gitignore? [y/N]" — with the default being NO (share it). This is the privacy-sensitive moment and it deserves an explicit UX touchpoint, not just a "review before committing" warning. The research doc mentions "suggest .gitignore entry, make sharing explicit opt-in" but the PRD dropped this in implementation. Pick it back up.
User
1. Value Proposition Clarity
Strong. The "why" is well-articulated and the killer use case (onboarding developer inheriting a codebase) is genuinely compelling. The research doc nails the competitive gap: entire.io stores raw transcripts, ADRs require manual authoring, memory MCPs don't survive git clone. Code Insights does zero-effort extraction from sessions that already happened, across multiple tools. That is a real moat.
One concern: the killer use case implies the original developer runs the export before handing off the codebase. But it's framed as zero-authoring-effort. This is slightly dishonest — someone still has to invoke the command and review/commit the file. The PRD should be explicit: "Zero authoring effort, one deliberate generation step." That's still compelling but more honest.
The dual-audience pitch (AI agents parse YAML, humans read markdown) is smart and well-precedented (.editorconfig serves editors and humans; package.json serves npm and humans). This framing should be in marketing, not just the PRD.
Assistant
Both reviews complete. Now synthesizing and applying all required changes to the PRD before marking it implementation-ready.
Assistant
Now applying all required changes. Writing the updated PRD:
Assistant
PRD is updated and marked Approved for implementation planning. Here's everything that changed based on the two reviews:
★ Insight ─────────────────────────────────────
The two-reviewer pattern caught 12 distinct gaps in the original PRD — some strategic (.gitignore prompt, --yes flag, --depth cut) and some technical (CLI invocation model, diff computation mechanism, write-repo endpoint guardrails, --no-llm ambiguity). The technical reviewer's most valuable contribution was grounding the review in the actual source code — they found two specific format validation locations in export.ts that both need 'repo' added, which a design-only review would never have caught.
─────────────────────────────────────────────────
What changed from v1 → v2 of the PRD:
Change
Source
Cut --depth from v1
Strategic
Added code-insights attach alias
Strategic
Added --yes / -y flag for CI
Strategic
Added .gitignore commit/ignore/skip prompt after first write
Added hand-edited file detection with mtime comparison
Strategic
Made privacy warning specific ("May contain... Does NOT contain...")
Strategic
Added token budget (80 insights in, 3000 tokens out)
Strategic
The PRD is ready. When you're ready to move to implementation, I'll invoke writing-plans to turn this into a detailed step-by-step implementation plan.
User
9. Verdict
The PRD is 85% complete for implementation planning. The architecture is sound, the approach is pragmatic (reusing existing pipeline), and the scope is well-contained. The YAML/markdown split and stateless design are good calls.
Gaps that need resolution before implementation:
Gap
Severity
Resolution needed
CLI-to-server invocation model
HIGH
Explicit: does CLI start its own server or use internal modules?
Diff computation mechanism
MEDIUM
Define: separate endpoint? Inline in write-repo response? Client-side diff?
--no-llm rules source
MEDIUM
Explicit: pull from reflect_snapshots? Or empty rules array if no reflect?
Reflect snapshot query (missing)
LOW
Add query specification for fetching latest claudeMdRules
--depth interaction with frontmatter
LOW
Clarify: depth caps insights to LLM only, frontmatter always uses full data
Recommendation: Resolve the HIGH item (CLI invocation model) and the two MEDIUM items, then this PRD is implementation-ready. The LOW items can be resolved during implementation with sensible defaults (empty rules if no reflect, frontmatter always uses full data).
<total_tokens>50123</total_tokens><tool_uses>9</tool_uses><duration_ms>129476</duration_ms>
User
8. Implementation Sequencing
Recommended order (safest, minimizing rework):
cli/src/utils/project-root.ts — Pure utility, no dependencies. Testable in isolation.
cli/src/utils/scrub.ts — Pure utility, no dependencies. Testable in isolation.
server/src/llm/repo-export-prompts.ts — New file with system prompt, buildRepoExportContext(), buildRepoFrontmatter(). Depends on understanding getAggregatedData() return type.
server/src/llm/export-prompts.ts — Add 'repo' to ExportFormat union, add ExportContext case. Small change, unlocks route changes.
server/src/routes/export.ts — Add 'repo' to validation, conditional branch for repo context, new POST /api/export/write-repo endpoint. Depends on steps 3-4.
cli/src/commands/export.ts + cli/src/index.ts — New CLI command. Depends on steps 1-2 and the server endpoints from step 5.
Dashboard changes (ExportPage.tsx, api.ts) — Last, because they depend on the server API being stable.
Hidden dependency: Step 3 depends on knowing the exact shape of getAggregatedData() return value (AggregatedData type from shared-aggregation.ts). The implementation plan should read that type definition first.
User
7. Missing Technical Details
Items that would block implementation:
CLI command calling the server. The PRD describes a CLI command (code-insights export --format repo) but doesn't specify whether it:
Starts a server instance (like code-insights dashboard does), calls the API, then stops it
Calls the server directly using internal modules (bypassing HTTP)
Requires the server to already be running
Given the existing pattern (code-insights reflect calls the server), the answer is likely "start server, call API, stop server." But this should be explicit.
Reflect snapshot rules query. The PRD mentions fetching claudeMdRules[] from reflect_snapshots but doesn't show the query or how to handle the case where no reflect has been run (no snapshots exist). Should --no-llm mode still include rules in YAML frontmatter if reflect snapshots exist?
Diff generation for re-run. The PRD describes a "Diff tab" in the dashboard and "Changes from last generation" in CLI output. How is the diff computed? The server would need to:
Read the existing file from disk (requires filesystem access)
Compute a unified diff
Return it to the dashboard
This implies either: (a) a separate endpoint like GET /api/export/repo-diff?projectId=x, or (b) the write-repo endpoint returns the diff alongside the content. Neither is specified.
The --depth flag interaction with facet data.applyDepthCap() limits insights sent to the LLM. But the YAML frontmatter friction/pattern data comes from getAggregatedData(), which has no depth cap — it aggregates ALL session facets for the project. Should --depth also limit frontmatter data? The PRD is silent on this.
Error handling for LLM-less YAML generation.--no-llm mode generates "YAML frontmatter only." This means the rules array in the frontmatter must be generated WITHOUT LLM synthesis. Where do the rules come from? The PRD says rules are "derived from recurring session patterns" — but if the LLM isn't doing the derivation, are they pulled from reflect_snapshots.claudeMdRules? This needs to be explicit.
User
6. Type System Impact
Verdict: Minimal, well-contained.
Changes needed:
cli/src/types.ts line 368:ExportTemplate union — does NOT need changing. ExportTemplate is for the old markdown export ('knowledge-base' | 'agent-rules'). The new repo format uses the ExportFormat type in export-prompts.ts.
server/src/llm/export-prompts.ts line 5:ExportFormat needs 'repo' added. This type is server-internal (not in cli/src/types.ts), so no cross-boundary propagation concern.
New types for the CLI export command: The CLI command (cli/src/commands/export.ts) will need to call the server's /api/export/generate endpoint with format: 'repo'. The CLI doesn't import ExportFormat from the server — it just sends a string. No type propagation issue.
No new types needed in cli/src/types.ts — the PRD is correct that this feature is stateless from the CLI's type perspective.
One gap: The PRD proposes a new cli/src/commands/export.ts file. Currently there is no CLI export command — the export functionality only exists as server API endpoints consumed by the dashboard. The PRD should acknowledge this is a new CLI command registration, not just a format addition. It does list cli/src/index.ts as modified (to register the command), so this is covered.
User
5. buildRepoExportContext() Function
Verdict: Data path exists, minor concern about scope filtering.
The PRD says:
> "Friction aggregations from session_facets (reusing getAggregatedData() from shared-aggregation.ts)"
getAggregatedData() takes (db, where, params, project?, source?). It returns friction categories, effective patterns, outcome distribution, and more. The function already exists and is battle-tested in facets.ts and reflect.ts.
Concern: scope alignment. The existing export pipeline filters by projectId using the insights table. The getAggregatedData() function filters session_facets joined to sessions. These are different filter paths:
Insights: WHERE i.project_id = ?
Facets: WHERE s.project_id = ? (via the where clause passed in)
For repo format, both must use the same project scope. The implementation needs to ensure the where clause passed to getAggregatedData() matches the project filter used for insights. This is straightforward but must be explicit.
Performance concern: Adding getAggregatedData() to the export pipeline adds 4-5 SQLite queries (friction, patterns, outcomes, streak, etc.). These are fast (indexed, small result sets for a single project), but it's worth noting that the repo format will be slightly slower than other formats due to this extra data fetch. Not a blocker.
Reflect snapshot rules: The PRD mentions fetching claudeMdRules[] from reflect_snapshots.results_json. This is a separate query not covered by getAggregatedData(). Implementation needs to add this fetch explicitly (likely a simple SELECT results_json FROM reflect_snapshots WHERE project = ? ORDER BY created_at DESC LIMIT 1).
User
4. POST /api/export/write-repo Endpoint
Verdict: This is the highest-risk item in the PRD. Needs stronger guardrails.
Path traversal. The server resolves the write path from sessions.project_path in the database, not from user input. This is safe — the attacker would need to inject a malicious path into the SQLite database first.
Arbitrary write. The endpoint writes content (user-controlled string from the request body) to a path derived from the database. If the dashboard is compromised (XSS, extension injection), an attacker could write arbitrary content to .code-insights.md at the project root. This is acceptable risk given the server runs locally.
Remote scenario. The PRD doesn't address this, and it matters:
> "What happens if the server is running but the project path is on a different machine?"
The server always runs locally (localhost:7890). The dashboard is also accessed locally. There is no remote scenario in the current architecture — the server, database, and filesystem are all on the same machine. This is fine.
Validation needed:
Verify the resolved path ends with .code-insights.md (never write to arbitrary filenames)
Verify the target directory exists
Reject if content is empty or exceeds a reasonable size limit (e.g., 100KB)
The endpoint should NOT accept a path parameter from the client — always resolve from DB
The PRD's design (resolve from DB, not from user input) is the right call. But these validation rules should be explicit in the implementation plan.
User
3. Project Root Detection
Verdict: Adequate for v1, with caveats.
The PRD proposes (Section 5.2):
typescript
export function findGitRoot(startPath: string): string | null {
let current = resolve(startPath);
while (true) {
if (existsSync(join(current, '.git'))) return current;
const parent = dirname(current);
if (parent === current) return null;
current = parent;
}
}
Platform concerns:
Windows:dirname('C:\\') returns 'C:\\' — the termination condition works.
Symlinks:resolve() resolves symlinks, so if project_path is a symlink, this walks up from the real path. This is correct behavior.
.git as a file (worktrees): Git worktrees use a .git file (not directory) pointing to the main repo's .git/worktrees/. existsSync catches this — a .git file still means "this is a git root." Correct.
The real concern is stale paths. The PRD handles this:
> "Path no longer exists — Error: Project path /old/path no longer exists."
Good. But there's a subtler case: the path exists but the .git was removed (repo moved, or the directory is now part of a different repo). The walk-up would find an ancestor's .git. This is edge-case enough to accept for v1.
Monorepo case is the trickiest:
> "Monorepo (multiple paths, common ancestor) — Use common ancestor with .git; if disjoint, require --path"
This logic (finding common ancestors across multiple project_path values) needs explicit implementation. The PRD acknowledges it but doesn't show the algorithm. Implementation plan should detail this.
User
2. YAML Frontmatter + LLM Markdown Body Split
Verdict: Clean design, but the streaming model needs clarification.
The PRD says (Section 5.1):
> "The server combines: HTML comment header + YAML frontmatter + LLM markdown body = final file content."
Looking at the actual export flow, client.chat() returns response.content as a single string. The server currently returns this directly:
This fits cleanly. The content field in the response already carries the full output — the client (dashboard or CLI) doesn't need to know about the split. The split is an internal server concern.
For the SSE stream variant: The stream currently sends one complete event with the full content. Same approach works — concatenate before sending the complete event. No architectural issue.
One concern: The frontmatter includes data like sessions: 142 and friction/pattern counts. If these are computed from the same queries used to build the LLM context, they should be computed once and shared. The PRD doesn't explicitly state this, but it's implied. Implementation should compute aggregations once, use them for both frontmatter and LLM context.
1. Architecture Soundness — "5th Export Format on Existing Pipeline"
Verdict: The approach is sound, but the PRD oversimplifies the integration.
The PRD states (Section 5.1):
> "Extend the existing POST /api/export/generate endpoint to accept format: 'repo'. Do not create a separate endpoint — the data fetching, SSE streaming, and LLM orchestration logic is identical across formats."
The repo format needs additional data beyond insights (friction aggregations, pattern aggregations, reflect snapshot rules). This means the "identical data fetching" claim is false. The route handler will need a conditional branch:
This is achievable but makes the endpoint less uniform than the PRD suggests. Not a blocker, but the implementation should be honest about this being a conditional branch, not a pure format swap.
The validation lists in export.ts will need updating. Currently line 211:
typescript
if (!['agent-rules', 'knowledge-brief', 'obsidian', 'notion'].includes(format))
This appears in both the sync endpoint (line 211) and the stream endpoint (line 309). Both need 'repo' added.
The ExportFormat type in export-prompts.ts (line 5):
Needs 'repo' added. The ExportContext interface and getExportSystemPrompt() switch statement both need the new case. Straightforward.
User
commit and store this PRD in a feature branch and create PR.. i will review later and ask for implementation
Assistant
PR is live at melagiri/code-insights#288.
★ Insight ─────────────────────────────────────
The entire CLI pushed session logs to origin when we ran git push — that's the entire.io hook in action. It captured this session (the brainstorming + research + design process itself) alongside the commit. Somewhat poetic: we used entire.io to record the session that produced the PRD for a feature that competes with entire.io's approach.
─────────────────────────────────────────────────
What's been done:
Feature branch feature/codebase-knowledge-prd created
PRD committed at docs/superpowers/specs/2026-04-20-codebase-knowledge-design.md (649 lines)
Research notes saved locally at docs/plans/2026-04-20-codebase-knowledge-research.md (gitignored by design — working notes)
PR #288 open and ready for your review
When you're ready to implement: merge the PR (or just say "let's build it"), and I'll invoke writing-plans to turn the PRD into a detailed, step-by-step implementation plan for /start-feature.
The moat is zero-effort generation. If you can say "run code-insights for a month, and your repo will have a living document of architectural decisions, friction hotspots, and effective patterns — all generated automatically," that is genuinely differentiated. Nobody else has that because nobody else parses multi-tool AI session data.
What you cannot do that entire.io can: team knowledge aggregation (multiple developers' sessions into shared knowledge), search across an organization's codebases, structured onboarding flows. And you should not try. Those are team features. That is a different company.
3. The Right Primitive
This is where I have the strongest opinion. Let me work through the options:
Git notes: Dead on arrival. Almost no developer knows they exist. They do not survive forks. They require separate push/fetch commands. The DX is hostile.
CLAUDE.md injection: Tempting but wrong. CLAUDE.md is for agent instructions, not knowledge documentation. Mixing "how to behave" with "what this repo has learned" creates a messy file. Also, you do not own the CLAUDE.md format — Anthropic does, and they may change it.
ADR-style markdown in a dedicated folder: This is the right direction but needs refinement.
.code-insights/ folder at repo root: This is what I would recommend, with caveats.
My recommendation: a single file, not a folder.
The primitive should be: .code-insights.md — a single markdown file at the project root.
Here is why:
One file is reviewable. Developers can look at a single PR that adds/updates .code-insights.md and make a judgment call. A folder with multiple generated files feels invasive.
One file is deletable. If you do not want it, rm .code-insights.md. Done. No recursive folder cleanup.
One file survives everything. Clones, forks, shallow clones, zip downloads — a single root-level markdown file is the most portable artifact possible.
One file is .gitignore-able. If you want it personal, add it to .gitignore. If you want it shared, commit it. The developer chooses.
Precedent:.editorconfig, .nvmrc, .tool-versions, ARCHITECTURE.md — single root files that describe project properties are well-understood by developers.
The file should be structured with clear sections (Decisions, Friction Hotspots, Effective Patterns, Generated Rules) and a header that says "Auto-generated by code-insights. Edit freely — regeneration will merge, not overwrite."
A folder (.code-insights/) could come later if there is demand for multiple documents (per-module knowledge, historical snapshots). But start with one file. Less is more.
4. Developer Adoption Risk
Developers are indeed suspicious of files added to their repos. The adoption risk hierarchy, from lowest to highest:
Low risk (do this):
Explicit opt-in command: code-insights export --to-repo or code-insights attach
File goes to .code-insights.md (not buried in a folder)
First line of the file: "This file was generated by code-insights. It is safe to delete, gitignore, or edit."
Never auto-generated. Never created by a hook. Always a conscious user action.
Add .code-insights.md to the suggested .gitignore patterns in docs, so the default is personal
Medium risk (proceed with caution):
Auto-updating the file on code-insights reflect — only if the user has previously opted in
Suggesting the file in PR descriptions or commit messages
High risk (do not do this):
Creating the file automatically on code-insights sync or code-insights dashboard
Adding multiple files or a folder structure without user initiation
Modifying any existing repo files (CLAUDE.md, README, etc.)
The trust equation: Value delivered must visibly exceed the cost of a new file. The file needs to be immediately useful the first time a developer reads it. If it is generic boilerplate, they will delete it and never try the feature again.
Codebase-attached knowledge is NOT a 4th layer. It is not a step in the introspective journey. It is an export target — a different output format for knowledge that already exists.
Think of it this way:
code
Sessions -> Insights -> Reflect -> Progress
| |
v v
Export .code-insights.md
(Obsidian, (repo-attached)
Notion, etc.)
The Export page already does cross-session LLM synthesis into Agent Rules, Knowledge Brief, Obsidian, and Notion formats. .code-insights.md is a 5th export format — one that targets the repo itself rather than an external tool.
The implementation path is:
Add a "Repo Knowledge" format to the Export page (alongside Agent Rules, Knowledge Brief, Obsidian, Notion)
Add a CLI command: code-insights export --format repo that writes .code-insights.md
The content is project-scoped (already supported via --project flag)
This means: no new architecture, no new data model, no new product layer. It is a new output format for an existing capability. That is the right scope.
If it proves valuable, you can later add:
Auto-refresh on reflect (with opt-in flag)
Section-level merge (preserve user edits, update generated sections)
.code-insights/ folder with per-module breakdowns
But start with "it is an export format." If nobody uses it, you have not built a feature nobody wants — you have added one option to an existing dropdown.
6. Killer Use Case
Here is the narrative:
B) A new developer joining the project — Someone inheriting the codebase (or reviewing a PR) gets the "why was this built this way" context that usually lives only in the original developer's head. Think of it as a generated /docs/decisions/ folder.
C) Both, as equal first-class use cases — The file serves both the AI agent and the human, with sections structured for each.
The answer shapes everything: format, content depth, update frequency, and whether the file lives in .gitignore (personal) or gets committed (shareable).
Data captured per session: transcripts, user prompts, modified files, token counts, tool calls (parsed from Claude Code's JSONL tool_use blocks), and line-level attribution (agent-written vs human lines, with percentages).
How knowledge is surfaced:
entire explain — review a session's checkpoints with original prompts + resulting commits
entire rewind — interactive picker to restore any checkpoint
entire resume — continue from a previous save point (switches branch + restores context)
Integration: git hooks (prepare-commit-msg, post-commit, pre-push). Works with Claude Code, Gemini CLI, Cursor, GitHub Copilot CLI, Codex, OpenCode, FactoryAI.
Business model: MIT open source, free. No hosted service, no external database. Transcripts live in your git repo on the orphan branch — public repos expose session data.
Weaknesses and criticism:
Reviewer noted: "running a separate CLI adds friction — this should be native to the agent." The hooks + setup mean it's another tool in the stack.
Security: automatic secret redaction is best-effort only. Public repos = visible transcripts.
The orphan branch strategy means git clone alone doesn't bring the metadata — you have to explicitly fetch the entire/checkpoints/v1 ref (it's not fetched by default).
Fork survivability is partial: the orphan branch must be explicitly fetched/pushed — it's not part of normal git push origin unless configured.
.gitignore
The moat against entire.io and others: zero-effort retroactive generation from sessions that already happened, across ALL your AI tools (Claude Code, Cursor, Copilot CLI, Codex). Nobody else parses multi-tool session data into structured knowledge. That's the edge.
One open question I'm wrestling with:
When you think about codebase-attached AI knowledge — should the file live at the project root (like .editorconfig or ARCHITECTURE.md), or deeper in docs/decisions/ as individual ADR-style files per decision? Root = discoverable but potentially noisy. docs/ = organized but buried.
Where would YOU look first when trying to understand why a codebase was built the way it was?
Would love to hear from developers who've felt this pain, or from anyone who's tried entire.io, memory banks, or ADRs in practice. What worked? What didn't?
Building code-insights — open source, local-first AI session analyzer. No accounts, no cloud, no data leaving your machine.
Now let me commit the research doc:
server/src/llm/export-prompts.ts
REPO_PROJECT_SYSTEM_PROMPT
REPO_ALL_SYSTEM_PROMPT
buildRepoExportContext()
server/src/routes/export.ts -- format validation update, conditional call to buildRepoExportContext() when format is repo
New LLM prompt structure:
The repo prompt is distinctive because the LLM does not produce the entire file. The YAML frontmatter is deterministic (generated in code from aggregated data). The LLM produces only the markdown body sections. This keeps the machine-readable portion exact and avoids LLM hallucination in structured data.
code
SYSTEM: You are a technical writer producing a codebase knowledge document from
AI coding session analysis for the project "{projectName}". This document travels
with the repository and serves two audiences:
1. AI coding agents — who read the YAML frontmatter for structured context
2. Human developers — who read the markdown sections for project knowledge
Produce markdown sections ONLY (no frontmatter, no preamble). Structure:
- ## Key Decisions (with trade-offs, alternatives rejected, revisit conditions)
- ## Learnings (grouped by topic, not by session)
- ## Common Friction Points (what keeps causing problems and why)
- ## Effective Patterns (what works well in this codebase)
- ## Rules for AI Agents (imperative instructions derived from patterns)
Rules:
- Deduplicate overlapping items — merge into single entries
- Be specific to THIS codebase, not generic advice
- Decisions must include WHY, not just WHAT
- Friction and patterns must be actionable, not observational
- Rules must be imperative mood: "DO X", "NEVER Y", "WHEN Z, do W"
- Do NOT include session IDs, timestamps, or any data that identifies specific sessions
- Do NOT include file paths from the user's machine
- Do NOT include API keys, tokens, passwords, or any credential-like strings
- Output clean markdown only — no meta-commentary
USER prompt feeds the same insight context (decisions, learnings, techniques) plus supplementary aggregated friction/pattern data and any existing CLAUDE.md rules from reflect snapshots.
2. Project Root Detection
How the CLI resolves --project to a filesystem path
The projects table already stores path TEXT NOT NULL for every project. The sessions table stores project_path TEXT NOT NULL per session. Both are populated during sync from the session file's cwd field.
Resolution chain:
code
--project "code-insights"
|
v
1. Fuzzy-match project name against projects.name (reuse stats/data/fuzzy-match.ts)
|
v
2. Look up projects.path for the matched project_id
|
v
3. Verify path exists on disk (existsSync)
|
v
4. Walk up to find .git directory (project root confirmation)
|
v
5. Write .code-insights.md at that root
Edge cases:
Scenario
Handling
Project has multiple paths (monorepo sub-paths)
Query SELECT DISTINCT project_path FROM sessions WHERE project_id = ? AND deleted_at IS NULL. If multiple paths share a common ancestor with a .git directory, use that ancestor. If truly disjoint, prompt user to pick via --path override.
Path no longer exists on disk
Error with clear message: "Project path /old/path no longer exists. Use --path /new/path to specify the current location."
--project not provided
Auto-detect from process.cwd() -- look up sessions whose project_path starts with the current directory, then resolve to the git root. If no match, error.
No git root found
Write to the project path directly (some projects are not git repos). Warn that the file will not be version-controlled.
New --path flag:
typescript
.option('--path <dir>', 'Override output directory for .code-insights.md')
This takes precedence over all detection logic. Useful when the project moved or for monorepo sub-projects.
Code sketch for project root detection:
typescript
// cli/src/utils/project-root.ts
import { existsSync } from 'fs';
import { dirname, join, resolve } from 'path';
/**
* Walk up from startPath to find the nearest directory containing .git.
* Returns the directory path, or null if no .git found up to filesystem root.
*/
export function findGitRoot(startPath: string): string | null {
let current = resolve(startPath);
while (true) {
if (existsSync(join(current, '.git'))) return current;
const parent = dirname(current);
if (parent === current) return null; // filesystem root
current = parent;
}
}
/**
* Resolve the target directory for .code-insights.md given a project's known paths.
* Priority: --path override > git root of stored path > stored path directly.
*/
export function resolveProjectRoot(
storedPaths: string[],
pathOverride?: string
): { root: string; source: 'override' | 'git-root' | 'stored-path' } {
if (pathOverride) {
const resolved = resolve(pathOverride);
if (!existsSync(resolved)) {
throw new Error(`Specified path does not exist: ${resolved}`);
}
return { root: resolved, source: 'override' };
}
// Find the longest common prefix with a .git directory
for (const storedPath of storedPaths) {
if (!existsSync(storedPath)) continue;
const gitRoot = findGitRoot(storedPath);
if (gitRoot) return { root: gitRoot, source: 'git-root' };
return { root: storedPath, source: 'stored-path' };
}
throw new Error(
`None of the known project paths exist on disk: ${storedPaths.join(', ')}. ` +
`Use --path to specify the current location.`
);
}
<!-- code-insights:generated-start -->
## Key Decisions
### SQLite over Firestore for local-first architecture
**Choice:** SQLite with WAL mode via better-sqlite3
**Reasoning:** Fully local, no cloud dependency, synchronous API avoids async overhead...
**Alternatives rejected:** Firestore (cloud dependency), Supabase (requires account)
**Revisit when:** Multi-device sync becomes a requirement
### Commander.js over yargs for CLI framework
...
## Learnings
### Tailwind v4 + shadcn/ui Integration
- Requires `@custom-variant dark`, `@theme inline`, `@import "tw-animate-css"`
- Radix UI Sheet requires SheetDescription for ARIA compliance
...
## Common Friction Points
### Wrong Approach (12 occurrences, avg severity: high)
Repeatedly starting with an approach that needs to be abandoned mid-session...
**Root cause:** Jumping to implementation without reading existing patterns first.
### Knowledge Gap (7 occurrences)
...
## Effective Patterns
### Structured Planning (18 occurrences, 82% confidence)
Planning the approach before implementation, creating task breakdowns...
**Primarily user-driven** — works best when the user provides clear structure upfront.
### Verification Workflow (14 occurrences)
...
## Rules for AI Agents
> These rules are derived from recurring patterns across 142 analyzed sessions.
> Add them to your CLAUDE.md or .cursorrules file.
- USE WAL mode for SQLite — concurrent reads during CLI sync require it
- ALWAYS run `pnpm build` from repo root after merging dashboard/server changes
- NEVER add non-nullable columns without a migration plan — existing data will crash
- WHEN adding a new source tool provider, follow the 6-step checklist in docs/ARCHITECTURE.md
...
<!-- code-insights:generated-end -->
Generation pipeline (code-side)
code
1. CLI resolves project → projectId
2. CLI calls POST /api/export/generate { format: 'repo', scope: 'project', projectId }
3. Server fetches:
a. Scoped insights (existing fetchScopedInsights)
b. Aggregated facets (getAggregatedData with project filter)
c. Latest reflect snapshot's claudeMdRules (if exists)
4. Server builds:
a. YAML frontmatter (deterministic, from aggregated data)
b. Supplemented insight+facet context for LLM
5. Server sends context to LLM → LLM returns markdown body
6. Server combines: frontmatter + sentinel-start + LLM body + sentinel-end
7. Server returns complete file content to CLI
8. CLI writes to {projectRoot}/.code-insights.md
Why not overwrite: Users will add project-specific notes, onboarding tips, or team conventions below the generated sections. Destroying those on re-run would make the file feel hostile. Nobody will adopt a tool that eats their edits.
Why not git diff approach: Requires interactive confirmation, which breaks hook-based automation. The sentinel approach is fully automatable while being safe.
function mergeGeneratedContent(existingContent: string, newGenerated: string): string {
const START = '<!-- code-insights:generated-start -->';
const END = '<!-- code-insights:generated-end -->';
const startIdx = existingContent.indexOf(START);
const endIdx = existingContent.indexOf(END);
if (startIdx === -1 || endIdx === -1 || endIdx <= startIdx) {
// No valid sentinel pair found — treat as first-time write.
// Preserve existing content by appending below the generated block.
return newGenerated + '\n\n' + existingContent;
}
// Replace only the sentinel-bounded region
const before = existingContent.slice(0, startIdx);
const after = existingContent.slice(endIdx + END.length);
return before + newGenerated + after;
}
The YAML frontmatter lives inside the sentinel block (above the markdown sections), so it also gets refreshed. Anything the user writes outside the sentinels is preserved exactly.
The schema_version field in frontmatter enables future format migrations: if a future version changes the YAML schema, the code can detect old versions and handle them.
--overwrite flag: For users who want a clean regeneration (no merge), provide --overwrite that skips the merge logic and writes the full file. Default behavior is merge.
--dry-run flag: Prints the file content to stdout instead of writing to disk. Combined with merge, shows what the file would look like after the merge.
5. Sensitive Data Scrubbing
Scrubbing happens at two layers: pre-LLM (input scrubbing) and post-LLM (output scrubbing).
Layer 1: Pre-LLM scrubbing (before sending to LLM)
The insight content and summary fields are the primary payload sent to the LLM. These are already LLM-generated summaries of sessions -- they rarely contain raw credentials. However, they can contain:
Internal service names / URLs
File paths from the user's machine
Package names that reveal internal tooling
Approach: Scrub the insight content before building the LLM prompt context. This runs in buildRepoExportContext().
Layer 2: Post-LLM scrubbing (before writing to disk)
The LLM output gets the same scrub pass applied. This catches cases where the LLM echoes back sensitive data or synthesizes realistic-looking credentials in examples.
typescript
// In the CLI, after receiving the response from the server:
const serverContent = response.content;
const scrubbedContent = scrubSensitiveData(serverContent);
Layer 3: Prompt-level instruction
The system prompt explicitly instructs the LLM to not include credentials, session IDs, user paths, or machine-specific data (already shown in section 1's prompt). This is the first line of defense but not sufficient alone -- LLMs don't reliably follow negative instructions.
--dry-run mode
Yes. Before writing to disk, --dry-run outputs the complete file to stdout with a header:
code
[dry-run] Would write to /Users/me/projects/code-insights/.code-insights.md
[dry-run] File size: 4.2 KB
---
<full file content>
This lets the user inspect for any sensitive data that slipped through scrubbing before committing the file.
6. Schema Changes
Recommendation: No schema change needed (V10 not required)
This feature is stateless from SQLite's perspective. Here is why:
The generated file is a derived artifact -- always regenerable from existing data (insights, session_facets, reflect_snapshots)
There is no need to track "when was the last repo export" because the YAML frontmatter contains generated_at and the file itself is the record
The sentinel-based merge strategy means the CLI reads the existing .code-insights.md from disk (if it exists) and merges -- no database tracking needed
Deduplication is handled by the merge algorithm (sentinels), not by tracking export history
Why not a repo_exports table: Adding a table to track "when was the last export for project X" would be useful only if we needed to show export history in the dashboard or trigger conditional re-exports. Neither is needed for the initial feature. If a dashboard "Export History" view is later desired, that would be the right time for a V10 migration. Think of it like a build artifact -- you don't need a database to track every time you ran npm run build.
If we later need export tracking (e.g., "show me all repo exports"), a V10 migration would look like:
typescript
function applyV10(db: Database.Database): void {
db.exec(`
CREATE TABLE IF NOT EXISTS repo_exports (
id TEXT PRIMARY KEY,
project_id TEXT NOT NULL REFERENCES projects(id),
file_path TEXT NOT NULL,
schema_version INTEGER NOT NULL DEFAULT 1,
generated_at TEXT NOT NULL DEFAULT (datetime('now')),
session_count INTEGER NOT NULL,
insight_count INTEGER NOT NULL,
file_hash TEXT
)
`);
db.exec(`CREATE INDEX IF NOT EXISTS idx_repo_exports_project ON repo_exports(project_id)`);
db.prepare('INSERT OR IGNORE INTO schema_version (version) VALUES (?)').run(10);
}
But I recommend deferring this. Ship stateless first.
7. AI Agent Consumption
How .code-insights.md gets consumed
There are two consumption paths, and we should support both.
Path A: Direct file discovery (recommended default)
AI coding agents that read repository files will naturally encounter .code-insights.md at the project root. The file header tells them how to use it:
markdown
---
# ... YAML frontmatter ...
---
<!--
This file contains codebase knowledge extracted from AI coding sessions by code-insights.
FOR AI AGENTS: Parse the YAML frontmatter above for structured data about this project's
friction patterns, effective practices, and rules. The `rules` array contains imperative
instructions to follow when working in this codebase.
FOR HUMANS: Read the markdown sections below for a narrative summary of project knowledge.
Regenerate: code-insights export repo --project "{projectName}"
Sections between code-insights:generated markers are auto-updated on regeneration.
Content outside those markers is preserved.
-->
Claude Code already auto-reads CLAUDE.md and many agents scan for convention files at project root. .code-insights.md follows this established pattern.
Path B: Explicit import into CLAUDE.md
For users who want the rules injected into their existing CLAUDE.md:
This appends a @import .code-insights.md directive (or the rules section content directly) to the project's CLAUDE.md. However, this is a secondary feature that should be deferred to a follow-up PR. The primary value is the standalone .code-insights.md file.
Why not code-insights init --import-learnings: The init command is for first-time setup of code-insights configuration (~/.code-insights/config.json). Injecting knowledge into a project's CLAUDE.md is a different concern -- it belongs on the export command since it is generating/exporting content.
Recommended .gitignore guidance
The CLI should print guidance after writing:
code
Written: /Users/me/projects/code-insights/.code-insights.md
This file is designed to be committed to your repository.
Review the contents before committing to ensure no sensitive data is included.
Add RepoExportFormat type alias or extend ExportTemplate union
server/src/llm/export-prompts.ts
Add 'repo' to ExportFormat union type
server/src/routes/export.ts
Accept 'repo' in format validation, call buildRepoExportContext() when format is repo, invoke scrubbing on insight content before LLM, combine frontmatter + LLM body in response
server/src/routes/export.ts
New endpoint POST /api/export/repo-context -- returns aggregated facets + reflect rules for frontmatter generation (or handle entirely in generate endpoint)
New Types in cli/src/types.ts
typescript
// Add to ExportTemplate union (or keep separate)
export type ExportTemplate = 'knowledge-base' | 'agent-rules';
// No change to ExportTemplate -- repo format uses the LLM pipeline, not the template pipeline.
// The 'repo' format is handled via ExportFormat on the server side.
Actually, no new types are needed in cli/src/types.ts. The ExportFormat type lives in server/src/llm/export-prompts.ts and just needs 'repo' added. The CLI command will be a standalone Commander command that talks to the server API.
New API Endpoints
None strictly required. The existing POST /api/export/generate and GET /api/export/generate/stream endpoints are extended to accept format: 'repo'. However, the repo format needs additional data beyond insights (facet aggregations, reflect rules), so the endpoint handler needs a conditional branch.
Optionally, one new convenience endpoint:
Route
Method
Purpose
GET /api/projects/:id/paths
GET
Returns distinct project_path values for a project -- needed by CLI to resolve write location
But this can also be handled by the CLI querying SQLite directly (it has DB access).
New CLI Flags
code
code-insights export repo [options]
--project <name> Project to export (fuzzy matched, required)
--path <dir> Override output directory
--depth <level> essential | standard | comprehensive (default: standard)
--dry-run Print output to stdout without writing
--overwrite Replace entire file instead of merging
--no-llm Generate frontmatter only (skip LLM synthesis for markdown body)
The --no-llm flag is a deliberate escape hatch. It generates a valid .code-insights.md with full YAML frontmatter and placeholder markdown sections. Useful for users without an LLM configured, or for CI pipelines that only need the machine-readable frontmatter.
CLI Command Registration
In cli/src/index.ts:
typescript
program
.command('export')
.description('Export project knowledge')
.command('repo')
.description('Write .code-insights.md to the project repository')
.requiredOption('--project <name>', 'Project name')
.option('--path <dir>', 'Override output directory')
.option('--depth <level>', 'Detail level: essential, standard, comprehensive', 'standard')
.option('--dry-run', 'Print to stdout without writing')
.option('--overwrite', 'Replace entire file instead of merging')
.option('--no-llm', 'Frontmatter only (skip LLM)')
.action(async (opts) => {
const { exportRepo } = await import('./commands/export.js');
await exportRepo(opts);
});
+--------------------------------------------------------------+
| Step 4: Review & Write |
+--------------------------------------------------------------+
| |
| +----------------------------------------------------------+ |
| | (info) Existing .code-insights.md detected | |
| | | |
| | Generated: 2026-03-15 · 10 rules · 3.8 KB | |
| | | |
| | The new version has 12 rules (+2), updated friction | |
| | counts, and 1 new decision. | |
| +--[muted bg, border-blue-500/30]-------------------------+ |
| |
| Tab: [Preview] [Diff] |
| |
| +--[when Diff tab selected]-------------------------------+ |
| | --- .code-insights.md (2026-03-15) | |
| | +++ .code-insights.md (2026-04-20) | |
| | @@ -14,6 +14,12 @@ | |
| | - id: sqlite-wal-mode | |
| | rule: "USE WAL mode for all SQLite connections" | |
| | + - id: avoid-orm-migrations | |
| | + rule: "DO NOT use ORM migration tools" | |
| | + category: database | |
| | ... | |
| +--[pre, mono, green/red highlighting]-------------------+ |
| |
| [Start Over] [Copy] [Download] [Overwrite]|
+--------------------------------------------------------------+
ANNOTATIONS:
- @A: Tab toggle between "Preview" (full file) and "Diff" (unified diff)
- @B: Diff generated client-side (simple line-by-line diff, no dep needed
for basic unified diff rendering — or use the `diff` npm package
if already available)
- @C: "Write to Repo" button text changes to "Overwrite" when file exists
- @D: Info card summarizes what changed (rule count delta, new sections)
— computed by comparing YAML frontmatter of old vs new
The server resolves the project's filesystem path from the sessions.cwd column (the working directory where sessions were started), writes the file, and returns the absolute path. If the file already existed, existed: true lets the dashboard show "Overwritten" vs "Created" in the toast.
<!--
AUTO-GENERATED by Code Insights (v4.10.2)
Do not edit — regenerate with: code-insights export --format repo
Review before committing to version control.
Generated: 2026-04-20
Project: code-insights
Sessions: 142 (2026-01-15 to 2026-04-20)
Insights synthesized: 80 of 217
-->
---
version: 1
generated: "2026-04-20"
project: code-insights
sessions: 142
source: code-insights-cli
rules:
- id: sqlite-wal-mode
rule: "USE WAL mode for all SQLite connections"
category: database
confidence: 95
context: "Prevents SQLITE_BUSY under concurrent reads from dashboard + CLI sync"
- id: migration-raw-sql
rule: "Write SQLite migrations as raw SQL in applyVN() functions, never use ORM migration tools"
category: database
confidence: 92
context: "ORM migrations failed silently on schema V6 upgrade; raw SQL is auditable"
- id: insert-or-ignore-schema
rule: "ALWAYS use INSERT OR IGNORE INTO schema_version, not bare INSERT"
category: database
confidence: 90
context: "UNIQUE constraint on version column; bare INSERT crashes on re-run"
- id: hono-deps-in-cli
rule: "@hono/node-server and hono must be in cli/package.json dependencies, not devDependencies"
category: packaging
confidence: 88
context: "npm-installed users get runtime errors when these are devDeps"
- id: pnpm-build-after-merge
rule: "Run pnpm build from repo root after merging dashboard or server changes"
category: workflow
confidence: 85
context: "Embedded dashboard serves pre-built assets; stale builds cause blank pages"
- id: tailwind-v4-shadcn
rule: "Tailwind v4 + shadcn/ui requires @custom-variant dark, @theme inline, @import tw-animate-css"
category: frontend
confidence: 85
context: "Missing any of these three causes silent dark mode or animation failures"
- id: no-mermaid-client-render
rule: "DO NOT render Mermaid diagrams client-side in static sites — pre-render as images"
category: frontend
confidence: 82
context: "Client-side Mermaid in Next.js static export is unreliable across browsers"
- id: fouc-sync-theme
rule: "FOUC prevention script in index.html must stay in sync with ThemeProvider logic"
category: frontend
confidence: 80
context: "Theme flash on load when the two diverge"
- id: radix-sheet-description
rule: "Radix UI Sheet components require SheetDescription for ARIA compliance"
category: accessibility
confidence: 78
context: "Accessibility audit flagged missing landmark descriptions"
- id: snake-case-dashboard-types
rule: "Dashboard types use snake_case matching SQLite column names and API responses"
category: conventions
confidence: 75
context: "Camel/snake mismatch caused silent data drops in InsightCard rendering"
- id: prompt-cache-content-blocks
rule: "Use ContentBlock[] with cache_control for Anthropic prompt caching; flattenContent() for non-Anthropic"
category: llm
confidence: 75
context: "Prompt caching reduces cost 80-90% on repeated analysis calls"
- id: sse-abort-handling
rule: "SSE streaming endpoints must handle AbortError gracefully — return 422, don't log as error"
category: api
confidence: 72
context: "Client cancellations flooded error logs before explicit abort handling"
friction_hotspots:
- category: stale-assumptions
severity: high
frequency: 23
description: "Outdated mental models about schema versions, API shapes, or component APIs"
mitigation: "Run sync after every schema change; check ARCHITECTURE.md before modifying shared types"
- category: knowledge-gap
severity: medium
frequency: 18
description: "Unfamiliarity with SQLite internals (WAL, PRAGMA), Tailwind v4 breaking changes, Hono middleware"
mitigation: "Documented in decisions below; key references linked"
- category: scope-creep
severity: medium
frequency: 14
description: "Feature PRs expanding beyond original scope, especially during refactors"
mitigation: "Strict PR scope enforcement; 'note and defer' for discovered improvements"
- category: wrong-approach
severity: medium
frequency: 11
description: "Initial implementation direction reversed after discovery (ORM to raw SQL, client to server render)"
mitigation: "Spike/prototype in isolated branch before committing to approach"
- category: context-loss
severity: low
frequency: 8
description: "Returning to a feature after days and re-discovering constraints already solved"
mitigation: "This file; also see decision log below"
proven_patterns:
- category: incremental-implementation
frequency: 34
description: "Building features in small, testable phases rather than big-bang PRs"
- category: verification-workflow
frequency: 28
description: "pnpm build gate before every PR; triple-layer code review"
- category: structured-planning
frequency: 22
description: "Written specs (docs/ux/*.md, docs/plans/*.md) before implementation"
- category: context-gathering
frequency: 19
description: "Extensive codebase reading (5+ files, cross-module) before modifying shared contracts"
- category: systematic-debugging
frequency: 15
description: "Reproducing issues with minimal cases before attempting fixes"
- category: self-correction
frequency: 12
description: "AI reversing initial approach mid-session after discovering constraints"
---
# Code Insights — Project Knowledge
> Extracted from 142 AI coding sessions (Jan 15 – Apr 20, 2026).
> Generated by [Code Insights](https://github.com/melagiri/code-insights).
> Regenerate: `code-insights export --format repo`
## Key Decisions
### SQLite over Postgres/Supabase (Jan 2026)
**Choice:** Local SQLite with WAL mode, no cloud database.
**Reasoning:** Privacy-first architecture — no data leaves the machine. SQLite handles the read/write patterns (single-writer CLI sync, multi-reader dashboard) well with WAL. Eliminated sign-up friction entirely.
**Trade-off:** No cross-device sync. Accepted — personal tool, single machine is the 95% case.
**Revisit if:** Users request team/shared features (currently a non-goal per VISION.md).
### Raw SQL migrations over ORM (Feb 2026)
**Choice:** Hand-written `applyVN()` functions with raw SQL, no Prisma/Drizzle.
**Reasoning:** Schema V6 migration failed silently with an ORM tool — the generated SQL didn't match SQLite's ALTER TABLE limitations. Raw SQL is auditable and predictable. Currently at V9 with zero migration failures.
**Trade-off:** More verbose migration code. Worth it for reliability.
### Embedded dashboard over separate app (Jan 2026)
**Choice:** Vite + React SPA bundled into the CLI package, served by Hono at localhost:7890.
**Reasoning:** Zero-config experience — `code-insights dashboard` starts everything. No separate install, no port config, no CORS. The SPA is pre-built at publish time.
**Trade-off:** Larger npm package size (~2MB). Acceptable for the UX gain.
### Multi-provider LLM abstraction (Mar 2026)
**Choice:** Unified `createLLMClient()` that wraps OpenAI, Anthropic, Gemini, Ollama, and llama.cpp behind a common interface.
**Reasoning:** Users have different API keys and local model preferences. The abstraction is thin — `chat()` method with messages array. Provider-specific features (prompt caching for Anthropic) handled via `ContentBlock[]` format with `flattenContent()` fallback.
**Trade-off:** Lowest-common-denominator API. Anthropic-specific features require conditional paths.
### ISO week-based navigation over sliding windows (Mar 2026)
**Choice:** Reflect uses `YYYY-WNN` ISO weeks instead of `7d/30d/90d/all` sliding windows.
**Reasoning:** Sliding windows are amnesiac — "last 7 days" changes meaning every day, making progress tracking impossible. Fixed weeks create stable snapshots that can be compared week-over-week.
**Trade-off:** Less intuitive for new users. Mitigated by defaulting to current week.
### Two-layer prompt quality output (Mar 2026)
**Choice:** Separate "takeaways" (user-facing before/after examples) from "findings" (categorized data for Reflect aggregation).
**Reasoning:** A single format can't serve both "show me how to improve this prompt" and "aggregate my prompting weaknesses across 50 sessions." Takeaways are narrative; findings are structured.
**Trade-off:** More complex analysis prompt and parsing. Worth it for both use cases.
### snake_case for dashboard types (Feb 2026)
**Choice:** Dashboard TypeScript interfaces use `snake_case` matching SQLite columns and API JSON.
**Reasoning:** Eliminated a class of bugs where camelCase/snake_case mismatch caused silent `undefined` values. The API returns what SQLite returns; the dashboard consumes it directly.
**Trade-off:** Non-idiomatic TypeScript. Team agreed consistency with data layer wins.
### Session character classification (Feb 2026)
**Choice:** 7 character types based on tool call patterns: deep_focus, bug_hunt, feature_build, exploration, refactor, learning, quick_task.
**Reasoning:** Users wanted to filter sessions by "what kind of work was this" without reading every conversation. Tool call distributions (ratio of Read/Edit/Bash/Grep) are strong signals.
**Trade-off:** Classification is heuristic, not perfect. Acceptable — it's a filter aid, not a judgment.
## Friction Hotspots
The most common sources of friction across sessions, ranked by frequency:
**Stale assumptions** (23 occurrences, high severity) — The most persistent friction source. Typically manifests as assuming a schema is still V7 when it's V9, or that a component API hasn't changed since last touch. Mitigation: always `grep` for current usage before modifying shared types. The `docs/ARCHITECTURE.md` file is the canonical reference.
**Knowledge gaps** (18 occurrences, medium severity) — SQLite WAL semantics, Tailwind v4 breaking changes from v3, Hono middleware ordering, and Radix UI accessibility requirements were the main gaps. Most were resolved once and captured as rules above.
**Scope creep** (14 occurrences, medium severity) — Feature PRs expanding during implementation. The "while I was here, I also..." pattern. Mitigated by strict PR scope discipline and the "note and defer" convention in CLAUDE.md.
**Wrong initial approach** (11 occurrences, medium severity) — Starting with an approach that gets reversed after discovering constraints. ORM-to-raw-SQL and client-to-server Mermaid rendering are the canonical examples. Mitigated by spiking in isolated branches for unfamiliar territory.
**Context loss** (8 occurrences, low severity) — Returning to a feature after a gap and rediscovering constraints. This file is part of the mitigation.
## Proven Patterns
Patterns that consistently led to successful session outcomes:
**Incremental implementation** (34 sessions) — Small, testable phases with `pnpm build` gates between each. The sessions-insights redesign (3 commits) and tier-2 redesign (10 commits) both used this pattern successfully.
**Verification workflow** (28 sessions) — `pnpm build` must pass before any PR. Triple-layer code review (TA insider + outsider + synthesis). No exceptions.
**Structured planning** (22 sessions) — Written specs in `docs/ux/` or `docs/plans/` before implementation. UX wireframes as ASCII art. The plan-first pattern catches scope issues before code is written.
**Context gathering** (19 sessions) — Extensive codebase reading (5+ files, cross-module exploration) before modifying shared contracts like types, schemas, or API routes. Prevents the "stale assumptions" friction pattern.
**Systematic debugging** (15 sessions) — Reproducing issues with minimal test cases before attempting fixes. Particularly effective for SQLite migration issues and SSE streaming bugs.
Format Notes
YAML frontmatter fields explained:
Field
Purpose
Consumer
version
Schema version for the YAML structure (start at 1)
AI agents, tooling
generated
ISO date of generation
Humans (staleness check)
project
Project name or "multiple"
AI agents (scope awareness)
sessions
Session count that fed this synthesis
Humans (coverage signal)
source
Always code-insights-cli
Provenance
rules[].id
Kebab-case stable identifier
AI agents (dedup across regenerations)
rules[].rule
Imperative instruction text
AI agents (direct consumption)
rules[].category
Topic grouping
AI agents (filtering)
rules[].confidence
0-100 score
AI agents (priority ordering)
rules[].context
One-line rationale
AI agents + humans
friction_hotspots[].category
From the 9-category taxonomy
Cross-reference with Reflect
friction_hotspots[].severity
high/medium/low
AI agents (triage)
friction_hotspots[].frequency
Occurrence count
Humans (impact signal)
proven_patterns[].category
From the 8-category taxonomy
Cross-reference with Reflect
Why rules are in YAML, not in the markdown body: AI agents like Claude Code parse YAML frontmatter reliably. Putting rules in markdown headings requires fragile regex parsing. The YAML block is a machine-readable API; the markdown body is the human-readable documentation.
Why id on rules: Enables diffing across regenerations. If rule sqlite-wal-mode exists in both the old and new file, a diff tool can show "rule text changed" vs "new rule added." Without IDs, every regeneration looks like a full rewrite.
Generating .code-insights.md...
Scope: code-insights (142 sessions)
Depth: standard (80 of 217 insights)
✔ Loading insights
◐ Synthesizing with AI... ← spinner, 10-30s
✔ Synthesis complete
Sections:
Rules (YAML) 12 rules
Decisions 8 entries
Friction Hotspots 5 categories
Proven Patterns 6 categories
⚠ REVIEW BEFORE COMMITTING
The generated file may contain project-specific details from your
AI sessions. Review the content before adding to version control.
Written to: /Users/dev/code-insights/.code-insights.md (4.2 KB)
Next steps:
cat .code-insights.md # Review the file
git add .code-insights.md # Add to version control
code-insights export --format repo # Re-generate after more sessions
Re-run Behavior
On re-run when .code-insights.md already exists:
code
Found existing .code-insights.md (generated 2026-03-15, 12 rules)
Options:
[R] Regenerate — overwrite with fresh synthesis (user edits will be lost)
[D] Diff — generate and show diff before writing
[C] Cancel
Choice [R/D/C]:
Default: Diff. The file is regenerated fully each time (no merge), but the user sees what changed before committing. This is the right trade-off because:
Merge is fragile (YAML + markdown mixed format, user edits in unknown locations)
Diff is familiar to developers (they already think in diffs)
The file has a clear "this is auto-generated" header, discouraging inline edits
If the user picks [D], show a unified diff:
code
--- .code-insights.md (current)
+++ .code-insights.md (regenerated)
@@ -12,6 +12,7 @@
rules:
- id: use-wal-mode
rule: "USE WAL mode for all SQLite connections"
+ - id: avoid-orm-migrations
+ rule: "DO NOT use ORM migration tools — write raw SQL migrations"
category: database
...
Apply changes? [y/N]:
Privacy Warning
The privacy warning appears on every generation (not just first run). It is a single line, not a wall of text -- developers will ignore anything longer.
code
⚠ REVIEW BEFORE COMMITTING — file may contain project-specific details from AI sessions.