Evidence-backed reverse engineering and human-gated software planning for Pi and MCP coding agents.
Copy the AI prompt to install this server into Claude Code, Cursor, or another agent β or use 1-click editor setup below.
π‘ Paste into ~/Library/Application Support/Claude/claude_desktop_config.json (macOS) or %APPDATA%\Claude\claude_desktop_config.json (Windows)
Understand an unfamiliar codebase with an AI agent β and get a validated spec you can rebuild from. CodeCartographer turns a repository into layered architecture, behavioral contracts, defect findings, and a language-agnostic reimplementation spec, with each phase validated before the next one runs. Works with Pi, Claude Code, Cursor, Codex, or any MCP-capable agent.
Asking an LLM to "analyze this repo" loses context halfway through, hallucinates findings, and leaves no artifact the next session can pick up. CodeCartographer fixes three things:
The filesystem is the memory, not the conversation. Each phase writes a smaller, templated, evidence-tagged artifact to .codecarto/findings/. Later phases re-read the specific upstream files they need. A new session β or a context compaction β picks up from status.yaml without losing progress.
Every phase is validated before the pipeline advances. Completion criteria are real: a FAIL output stops the run. You can't accidentally build a reimplementation spec on top of hallucinated architecture.
The output is a spec, not a chat log. The final reimplementation-spec.md is language-agnostic, module-inventoried, and carries acceptance scenarios plus known unknowns. Hand it to another agent to rebuild from.
Every finding is tagged with an evidence level: observed fact, strong inference, portability hazard, or open question.
| What you get | Where it lives |
|---|---|
| Layered analysis pipeline β architecture β defect scan β behavioral contracts β protocols β porting β reimplementation spec | .codecarto/ template |
Validation gates between phases β no advancing past a FAIL output | core/ state machine |
| Three surfaces, one framework β Pi extension (recommended), MCP server (for other coding agents), or drop-in template (one-off / evaluation) | All three share core/ |
| Live progress widget while phase sub-agents work | Pi extension |
| HTML dashboard β single-file aggregate of progress, links, usage, narrative | .codecarto/dashboard.html |
| Per-phase token tracking | /codecarto-usage |
| Opt-in LLM steering of the next phase's seed prompt | /codecarto-next --llm-steer |
| Forward synthesis β vision + confirmed library specs β provenance-backed project plan | pipeline-synthesis.yaml |
Publish completed reimplementation specs from Pi or MCP, then run the synthesis pipeline to turn a product vision and explicitly confirmed library entries into a conflict-aware project-plan.md with a decision-level provenance ledger.
If CodeCartographer saves you a day of codebase archaeology, star the repo β it helps the next person find it.
OpenAI Build Week reviewers: see the new-vs-existing scope and one-command demo.
Three surfaces, in recommended order. All three share the same core/ and produce byte-identical phase prompts. Pi provides the richest orchestration UX; Pi and MCP both support the executable library and synthesis workflows; drop-in mode provides the analysis framework without those runtime operations.
.codecarto/ markdown + YAML for one-off evaluation or any LLM that can read and write files. Library and synthesis workflows are not available in pure drop-in mode; the analysis side works fully.Pi is a TUI coding agent. The CodeCartographer extension adds slash commands, a live agents widget, and the dashboard.
Don't run
npm install codecartographer-pifor the Pi use case. Plainnpm installputs the package on disk but doesn't register it with Pi. Usepi install npm:...so Pi writes the package into its own~/.pi/agent/settings.json.
For extension development, point Pi directly at the entrypoint:
Use this when your coding agent isn't Pi β Claude Code, Codex, opencode, Cursor, Claude Desktop, or anything else that speaks MCP. The host drives the conversation and runs the LLM; CodeCartographer provides phase prompts, validation, and experimental library publish/list/reindex operations.
30-second setup for Claude Code, Cursor, Codex, and Claude Desktop: see the MCP quickstart.
Add to your host config (~/.config/claude-code/config.json, claude_desktop_config.json, etc.):
Official MCP Registry listing: io.github.HuginnIndustries/codecartographer.
Use this to try CodeCartographer in any repo without installing anything, or in environments where neither Pi nor an MCP-capable agent is available. Works with any LLM that can read and write files.
Then in the LLM session: Read .codecarto/GUIDE.md and begin the analysis.
Limitation. Drop-in mode runs the analysis pipeline fully, but library + synthesis workflows require executable code through Pi or MCP.
Analysis turns repositories into reusable specifications. Synthesis runs the other direction: it combines a raw product vision with human-confirmed specifications and produces an implementation-ready plan without losing provenance.
Configure the library that contains specs published with /codecarto-publish or the MCP codecarto_publish tool:
Initialize a clean planning workspace and fill in its brief:
Edit .codecarto/inputs/vision.md with the audience, problem, desired outcome, constraints, and non-goals.
Run until CodeCartographer creates the candidate proposal:
The run intentionally stops before merging. Review .codecarto/findings/goal-synthesis/proposal.md and change one or more candidate boxes from [ ] to [x].
Resume:
The final .codecarto/findings/goal-synthesis/project-plan.md contains product scope, architecture, work packages, acceptance gates, an unresolved-conflict register, and a provenance ledger mapping every load-bearing decision back to the vision or a confirmed specification. Runtime preflight checks prevent merging or finalization before explicit human confirmation.
The "code" is structured Markdown + YAML inside .codecarto/:
GUIDE.md β LLM entry point. Every session reads this first.workflow/pipeline.yaml β phase definitions, dependencies, output paths.workflow/status.yaml β mutable per-project state. Single source of truth for progress.workflow/VALIDATE.md β validation protocol run after every phase.findings/<phase>/SKILL.md β detailed analysis instructions per phase.templates/ β output templates that enforce consistent structure.Phases form a DAG: contracts and protocols can run in parallel after architecture; porting waits for both; reimplementation-spec is last. The host (Pi, MCP, or your shell) reads the active pipeline, finds the next phase whose dependencies are all complete, hands the LLM that phase's instructions, validates the output, and advances status.yaml.
For multi-session work, every new session reads .codecarto/GUIDE.md (or the lighter NEW_THREAD_BLURB.md), checks workflow/status.yaml, and picks up where the last session left off. You don't explain what happened in previous sessions.
CodeCartographer is a progressive, evidence-tagged distillation of a codebase. It does not ask one context window to retain the entire investigation. Instead, each phase turns a large body of source evidence into a smaller, more task-specific artifact that the next phase can read:
This is deliberate distillation, not incidental chat summarization. Each artifact follows a template, preserves evidence levels and known unknowns, and must pass validation before it becomes an input to downstream phases.
The filesystem, not the conversation, is the durable memory of a run:
.codecarto/findings/. Later phases re-read the specific upstream artifacts declared by the active pipeline instead of relying on conversational recall.workflow/status.yaml records progress, terminal open_questions, in-pipeline carry_forward, and a separate post_pipeline backlog for optional spikes, amendments, deltas, decisions, and reruns after completion. Phase agents propose changes in .codecarto/scratch/handoffs/<phase>.yaml; completion validates and applies them under a lock with host timestamps, one canonical closeout, and an idempotent THREAD_LOG.md entry./resume, /tree, and /export, even when the active model context has been compacted..codecarto/scratch/checkpoints/<phase>.md.threshold, overflow, or manual) in local usage data and exposes the totals in the widget, /codecarto-usage, completion summaries, and dashboard.As a result, compactionβor even replacementβof the orchestrator session does not erase pipeline progress. A new session can reconstruct the relevant state from disk and continue.
The remaining limit is within a single oversized phase. Even Pi's phase-aware summary is still a lossy distillation, and MCP/drop-in compaction remains entirely host-controlled. Phase instructions therefore prioritize targeted reads, durable checkpoints, and explicit coverage accounting; if full coverage will not fit, the phase records PARTIAL validation and places unresolved work in open_questions or carry_forward. Cross-phase context loss is largely designed out; intra-phase context pressure is observed and bounded rather than hidden.
The porting bundle is the final intentional compression boundary. It carries a source index, load-bearing invariants, defect dispositions, and deep-read triggers. reimplementation-spec reads that bundle by default and opens lower-level reports only for a named gap, conflict, missing acceptance detail, or defect rationale.
| Artifact | Description |
|---|---|
| Architecture map | Layers, dependency direction, public surfaces, runtime lifecycle, concurrency model |
| Defect report | Multi-pass scan for logic errors, security issues, concurrency bugs, API violations |
| Defect fix tracker | Remediation log mapping each fix, deferral, or acceptance back to the defect report |
| Behavioral contracts | Feature-by-feature behavior with defaults, error handling, and acceptance tests |
| Protocols and state | Event flows, state machines, persistence formats, compatibility hazards |
| Porting bundle | Everything synthesized into a porting-oriented view with priority rankings |
| Reimplementation spec | Language-agnostic build plan with modules, acceptance scenarios, and known unknowns |
Every finding is tagged with an evidence level: observed fact, strong inference, portability hazard, or open question. Every phase output is validated against explicit completion criteria before the pipeline advances.
The default is a 7-phase run that splits the defect scan into a mechanical early pass and a semantic late pass β the reimplementation phase then designs around defects with full contracts and protocols context. Scale back if you want less:
| Variant | Phases | Use when |
|---|---|---|
| Full with deep audit (default) | 7 | Complete analysis with split defect scan; reimplementation grounded in contracts/protocols-aware defect findings |
| Full with audit | 6 | Single early defect scan; cheaper than the deep variant when defects are mostly mechanical |
| Full | 5 | Porting or reimplementation without any defect scan |
| Defect scan | 2 | Maintenance audit to surface latent problems |
| Lite | 3 | You need to understand behavior without porting plans |
| Architecture only | 1 | Quick structural overview |
| Synthesis | 4 | Turn a product vision and confirmed library specifications into a provenance-backed implementation plan |
Switch the active pipeline with /codecarto-switch-pipeline <variant> (Pi) or codecarto_switch_pipeline (MCP). This rewrites status.yaml in-place without deleting findings, handoffs, usage data, or closeouts. Phases that exist in both the old and new pipelines preserve their completion status.
On disk:
| Variant | Pipeline file |
|---|---|
| Full with deep audit (default) | workflow/pipeline-full-with-deep-audit.yaml |
| Full with audit | workflow/pipeline-full-with-audit.yaml |
| Full | workflow/pipeline.yaml |
| Defect scan | workflow/pipeline-defect-scan.yaml |
| Lite | workflow/pipeline-lite.yaml |
| Architecture only | workflow/pipeline-architecture-only.yaml |
| Synthesis | workflow/pipeline-synthesis.yaml |
Every state change re-renders .codecarto/dashboard.html β a self-contained single-file artifact you open in any browser. Aggregates everything a human wants to see at a glance:
No JavaScript. No external assets. Light/dark via prefers-color-scheme. Works opened directly from file://.
Opt-in narrative summary. /codecarto-dashboard --narrate runs the orchestrator's model as a one-shot session that writes a 200β400 word executive summary citing specific findings from recent closeouts. Cached to .codecarto/.dashboard-narration.local.md and preserved across deterministic re-renders with a "(N runs since)" staleness note.
Beyond the slash commands, the Pi extension layers on:
Phase sub-agents. /codecarto-next spawns each phase as an isolated AgentSession. Tool calls, file reads, and reasoning live in the child's own context window β they never accumulate in the orchestrator. Your TUI stays on the orchestrator session and remains responsive while phases work in background.
Live agents widget above the editor showing tool count, token usage, elapsed time, and current activity.
File-backed phase sessions. Phase transcripts persist to the same Pi session directory the orchestrator uses, so /resume, /tree, and /export browse them as first-class sessions. Each appears as CodeCartographer phase: <id> with lineage back to the orchestrator's session.
Phase-aware compaction and checkpoints. Only isolated sessions named CodeCartographer phase: <id> receive the specialized compaction prompt. It preserves the phase goal, evidence, inspected files, output progress, open questions, and validation gaps, then writes the resulting summary to .codecarto/scratch/checkpoints/<phase>.md. Orchestrator and unrelated Pi sessions retain normal host compaction.
Phase-completion summary in the orchestrator transcript. When a phase finishes, a Markdown closeout block is appended to the orchestrator's session via pi.sendMessage(...). Visible in the TUI scrollback; available to the orchestrator's LLM as context on your next message. No auto-trigger β you stay in control.
Opt-in LLM-steered seed prompts. Set orchestrator.llm_steer_next_phase: true in .codecarto/workflow/config.yaml (or pass --llm-steer per invocation), and the orchestrator's LLM rewrites the next phase's seed prompt to highlight relevant prior findings. Off by default β extra orchestrator-side tokens, opt-in. The rewritten prompt is injected into the orchestrator transcript so you can audit what the rewriter chose to emphasize.
Per-phase usage tracking. Each phase run is appended to .codecarto/workflow/.usage.local.yaml. /codecarto-usage reports cumulative + per-phase token, runtime, tool-use, and compaction totals, including threshold/overflow/manual triggers and successful/failed/aborted outcomes.
Tool interception. bash is blocked outright; edit and write are confined to .codecarto/, plus the configured, marker-validated CodeCartographer library when one is configured. Same rules apply to phase sub-agents.
| Command | Purpose |
|---|---|
/codecarto-init [variant] | Copy .codecarto/ into the current repository, select pipeline variant |
/codecarto-open | Activate an existing .codecarto/ workspace in a new Pi session without resetting durable state |
/codecarto-vision | Run a guided product discovery interview to produce inputs/vision.md for the synthesis pipeline |
/codecarto-switch-pipeline <variant> | Switch the active pipeline in-place without losing findings or progress |
/codecarto-status | Current phase, progress, open questions |
/codecarto-next [--auto [--strict]] [--llm-steer | --no-llm-steer] | Spawn the next eligible phase as a sub-agent. After the sub-agent finishes, auto-validates and auto-completes the phase so status.yaml advances without manual steps. --auto walks the full pipeline end-to-end (same validate + complete + advance loop, repeated); --strict flips the PASS WITH GAPS rule from "advance" to "pause". |
/codecarto-phase <id> | Force a specific phase, even out of pipeline order |
/codecarto-validate [phase] | Validate a phase output against completion criteria |
/codecarto-complete [phase] | Validate and atomically apply the phase handoff, canonical status, closeout, and log entry |
/codecarto-skill <name> | Run a post-pipeline skill once all phases are complete |
/codecarto-publish | Publish the reimplementation spec to the configured library after reviewing an explicit confirmation preview |
/codecarto-library-init <path> [--namespace <name>] | Create a library directory with marker and write the config β fixes the first-publish dead end |
/codecarto-config | Show the effective merged configuration (global + workspace) and library marker status |
/codecarto-usage | Cumulative + per-phase token usage |
/codecarto-dashboard [--narrate] | Regenerate .codecarto/dashboard.html; --narrate for the LLM executive summary |
/codecarto-next --auto walks the entire pipeline without intervention. The loop spawns each next-eligible phase, auto-validates the output, auto-marks it complete, and advances until the pipeline finishes β or until something stops it (FAIL / MISSING validation, sub-agent error, or ctx.signal abort). The orchestrator's TUI stays responsive throughout; per-phase summaries land in the transcript as usual, and a final codecarto-auto-summary block reports the outcome with cumulative tokens, wall time, and a recovery hint if the run stopped early.
--auto reads status.yaml and picks up from getNextEligiblePhase.--strict (requires --auto) treats PASS WITH GAPS as a stop β useful when you want to triage gaps before advancing.--auto --llm-steer runs the rewriter on every phase transition; the per-phase steering blocks land in the orchestrator transcript so the run is auditable.The current parallel-sub-agent design landed in 0.2.0 and has been incrementally enriched: file-backed sessions (0.3.0), summary injection (0.4.0), opt-in LLM steering (0.5.0), usage tracking (0.6.0), HTML dashboard (0.7.0), end-to-end auto mode (0.8.0), experimental library foundations plus MCP library tools (0.9.0), and Pi overlay activation gating (0.9.1). 0.1.x workspaces don't need migration β existing .codecarto/ directories work unchanged. See CHANGELOG.md for details.
The same framework is packaged as a Model Context Protocol server. The MCP path returns prompt text for the host to dispatch and never runs sub-agents itself, so the Pi-only orchestration features (sub-agents, live widget, dashboard, usage tracking) don't apply β but phase prompts and validation are byte-identical with the Pi path because both import the same core/. v0.9.0 also exposes experimental library tools so MCP-capable hosts can publish, list, and reindex reusable reimplementation-spec.md artifacts.
Implements MCP spec revision 2025-11-25 via @modelcontextprotocol/sdk β₯ 1.29.0. The negotiated protocolVersion reflects whatever the connecting client requests; the server accepts every revision the SDK supports (currently 2025-11-25, 2025-06-18, 2025-03-26, 2024-11-05, 2024-10-07).
| Tool | Pi equivalent |
|---|---|
codecarto_init | /codecarto-init |
codecarto_status | /codecarto-status |
codecarto_next | /codecarto-next |
codecarto_phase | /codecarto-phase |
codecarto_validate | /codecarto-validate |
codecarto_complete | /codecarto-complete |
codecarto_skill | /codecarto-skill |
codecarto_publish | MCP-only library publish |
codecarto_library_list | MCP-only library listing |
codecarto_library_reindex | MCP-only library reindex |
Each workflow tool accepts an absolute cwd for the target repository. codecarto_init requires force: true to overwrite an existing .codecarto/ (instead of Pi's interactive confirmation). The library tools accept an explicit absolute library_path or resolve library.path from .codecarto/workflow/config.yaml / ~/.codecarto/config.yaml. The library schema is experimental and may break before v2.
| Environment | Recommended surface |
|---|---|
| Pi | Native Pi extension β slash commands + widget + dashboard. |
| Claude Code / Codex / opencode | MCP server. All three speak MCP cleanly. |
| Cursor / Windsurf / IDE copilots | MCP server where supported; otherwise drop-in template (.codecarto/GUIDE.md). |
| Claude Desktop | MCP server. |
| Aider | Drop-in template β point at .codecarto/GUIDE.md. |
| Claude.ai / ChatGPT (web chat) | Drop-in, paste file contents manually. Tedious for multi-phase runs. |
| API-based agents | Load files programmatically, pass to the model, write outputs back. Drop-in semantics. |
CodeCartographer is token-intensive β it reads source code multiple times across phases and produces thousands of words of structured output. Plan accordingly.
Every session reads the guide, pipeline definition, status, and validation protocol. Each phase additionally reads its own SKILL.md and output template. Fixed regardless of codebase size:
| Component | Tokens (input) |
|---|---|
| Per-session base (GUIDE + pipeline + status + VALIDATE) | ~2,600 |
| Architecture phase instructions | ~1,500 |
| Defect scan phase instructions (includes 6 pass files) | ~5,000 |
| Contracts phase instructions | ~1,500 |
| Protocols phase instructions | ~1,200 |
| Porting phase instructions | ~1,200 |
| Reimplementation spec phase instructions | ~1,100 |
| Total template overhead, 6-phase run | ~27,000 |
| Total template overhead, 7-phase deep-audit | ~32,000 (split defect scan adds one more SKILL load) |
The dominant cost. Each phase reads some or all of your source code; the architecture phase reads the most. Rough guide: expect 1β3Γ your codebase size in tokens per phase. A 50k-token codebase might consume 100β200k input tokens across a full pipeline run.
From a real 6-phase run (CodeCartographer analyzing itself β a small ~14k-word template):
| Phase | Output size |
|---|---|
| Architecture map | ~3,100 tokens |
| Defect report | ~2,400 tokens |
| Behavioral contracts | ~4,500 tokens |
| Protocols and state | ~3,900 tokens |
| Porting bundle | ~3,400 tokens |
| Reimplementation spec | ~4,400 tokens |
| Total output | ~21,800 tokens |
Larger codebases produce proportionally larger outputs.
For a medium-sized codebase (~100k tokens of source):
| Pipeline | Estimated input | Estimated output | Total |
|---|---|---|---|
| Architecture only | ~130k | ~5k | ~135k tokens |
| Defect scan (2-phase) | ~260k | ~10k | ~270k tokens |
| Lite (3-phase) | ~370k | ~15k | ~385k tokens |
| Full (5-phase) | ~570k | ~22k | ~592k tokens |
| Full with audit (6-phase) | ~700k | ~27k | ~727k tokens |
| Full with deep audit (7-phase, default) | ~830k | ~32k | ~862k tokens |
At current API pricing (~$3/M input, ~$15/M output for Claude Sonnet), a full 5-phase run on a 100k-token codebase costs roughly $2β4. Larger codebases scale linearly.
architecture-only to see if the output quality is useful before committing to a full run.open_questions in status.yaml shows what was skipped.lite pipeline (3 phases) gives 80% of the value for understanding a codebase without porting-specific phases.--llm-steer unless you're hitting cross-phase coherence issues β the rewriter costs orchestrator-side tokens per phase.LLM-agnostic by design, but model choice affects both what you can analyze and how good the results are. Two independent constraints: context window size and model capability.
Each phase runs in its own session, so the context window limits how much source code can be read per phase β not across the whole pipeline. After template overhead, prior-phase findings, and output generation:
| Phase | Available for source (128k model) | Available (200k model) |
|---|---|---|
| Architecture | ~121k | ~193k |
| Defect scan | ~115k | ~187k |
| Contracts | ~114k | ~186k |
| Protocols | ~115k | ~187k |
| Porting | ~104k | ~176k |
| Reimplementation spec | ~103k | ~175k |
Practical limits by codebase size:
| Codebase | 128k context | 200k context |
|---|---|---|
| <30k tokens | All phases comfortable | All phases comfortable |
| 30β60k tokens | Feasible, some PARTIAL results | Comfortable |
| 60β100k tokens | Marginal β heavy PARTIAL use | Feasible with prioritization |
| >100k tokens | Not viable | Feasible, later phases may PARTIAL |
The pipeline handles context exhaustion gracefully: phases write PARTIAL validation and log remaining work in open_questions.
The harder constraint. Tasks that degrade fastest on weaker models:
observed fact from strong inference from open question requires calibrated self-awareness about certainty. Weaker models over-classify inferences as facts and skip open question tagging.| Tier | Examples | Recommended pipeline | Notes |
|---|---|---|---|
| Frontier | Claude Opus 4.6, Claude Sonnet 4.6 | Full-with-deep-audit (default) | Full quality on codebases up to ~100k tokens; the deep audit's semantic pass benefits most from frontier reasoning. |
| Strong mid-tier | Claude Haiku 4.5, GPT-4o | Lite (3-phase) | Architecture and contracts are solid. Skip defect scan β false-positive rate too high. |
| Smaller / faster | GPT-4o-mini, Gemini Flash, small open-weight models | Architecture only | Fair structural overview. Multi-phase runs produce significant quality loss. |
If you're testing a new model, start with pipeline-architecture-only.yaml on a codebase you already understand and compare the output against your own knowledge. Fast signal on whether to trust the model with deeper phases.
The .codecarto/.gitignore excludes generated findings, scratch files, the dashboard, and the local usage / narration caches. Template files (workflow definitions, skills, output templates) are safe to commit so teammates can run their own analyses.
workflow/status.yaml.complete and whose dependencies are all complete.skill_path and required_reads to the agent.current_phase to complete when done.The MCP server does steps 1β3 directly; the Pi extension wraps them as slash commands plus the parallel-sub-agent runner described above.
status.yaml tracks progress; no duplicated state..codecarto/. No symlinks, no copying source code, no runtime daemon.Bug reports, feature requests, and pull requests are welcome. See CONTRIBUTING.md for development setup, branch model, and the maintainer release process. All participants are expected to follow the Code of Conduct. For security issues, follow SECURITY.md instead of filing a public issue.
MIT β see LICENSE.
Showcase your server listing on GitHub or your project documentation. Embed this dynamic SVG badge to highlight official listing status and live engagement.
[](https://allmcps.com/mcp/codecartographer)<a href="https://allmcps.com/mcp/codecartographer"><img src="https://allmcps.com/api/badge/codecartographer?style=directory" alt="CodeCartographer on AllMCPs" /></a>