codebase-snapshot
This MCP server exposes codebase-snapshot as an agent-facing index for inspecting, searching, planning, generating, and validating repository snapshots.
Inspect status and health: check snapshot presence, coverage, fingerprint, freshness, manifest/hash integrity, secret leakage, and host paths.
Explore structure: workspace members, entry points, tests, routes, import cycles, statistics, and recent commit history.
Navigate relationships: file imports/importers, dependents, test coverage links, and locate files, symbols, layers, kinds, or routes.
Search and read safely: search snapshot text, find symbol definitions/references, and page through file contents from the snapshot so exclusions and redactions are preserved.
Build bounded context: query the index, assemble context from files/symbols, plan a reading order for a question, or return budgeted answer context with omissions reported.
Review changes: validate freshness, run health checks, and gather head windows plus dependents for changed paths.
Plan, generate, and validate: preview snapshot effects, generate/update the snapshot, and validate it against the repository for drift.
Explain paths: determine why a file or directory would be included or skipped in the next snapshot.
Most tools are read-only and operate on the snapshot rather than the working tree; generation and validation are the stateful operations.
npx codebase-snapshot generate # no install: straight to the snapshot
snapshot # once installed: detects the project, sets it up, generatesThat writes ./snapshot/ — a directory you can drop into a chat, a prompt, a RAG pipeline or a
repository review. TypeScript and JavaScript first, but also Python, Go, Rust, Java/Kotlin,
C#/.NET, PHP, Ruby, C/C++, Vue, Svelte and Astro, without configuration.
Why
Feeding a real repository to a model is awkward: files are too big, context windows are too small, and choosing what matters by hand neither scales nor repeats. This does it deterministically.
A hard ceiling, not a target.
maxPartBytesis a limit, and nothing overflows it silently: a file too big for a part becomes a head/tail excerpt with an omission marker, andmanifest.jsonrecords it inincomplete[]with the line ranges it lost.An index, not just text.
manifest.jsonlists every included file with its layer, kind, language, part, hash and a structural summary, every excluded file with the reason, and anincomplete[]list of every file it could only emit in part, with the line ranges it lost.Provably current.
validatere-hashes the repository against the snapshot and exits non-zero on any drift, so a pipeline can gate on the context being fresh.Repeatable. Two runs over unchanged input give byte-identical parts and the same
manifest.fingerprint; only the artifacts that carry a timestamp, run id or pid differ.
Related MCP server: DevProjex MCP Server
Install
npm install -g codebase-snapshot # puts `snapshot` on your PATH
npx codebase-snapshot generate # or no install at all, one-off
npm install -D codebase-snapshot # or add it to a projectcodebase-snapshot is the canonical name to script against; snapshot is the short command a
global install provides, and from a project dependency the same binary is npx snapshot or the
npm run snapshot script init writes.
Requires Node.js 18+. Any npm client works — npm, yarn (classic and Berry with strict PnP), pnpm
and bun. Published from GitHub Actions with build
provenance, so npm audit signatures
verifies the tarball came from this repository at a tagged commit.
This is a 0.x release: the CLI surface may still change in a minor release until 1.0.0, so pin an exact version if you need a fixed surface today.
Quick start
Type it. That is the whole first run.
snapshotIt recognises the project and says what it keyed on — Detected nextjs / Because next.config.ts
— then offers the recommended setup in one keystroke, or a walk through every setting with each
question starting on its default. Either way it writes the config, adds the npm scripts and the
devDependency, installs with your package manager, and generates. A project that already has a
config just generates.
Nothing to press — CI, a container, an agent:
npx codebase-snapshot --autopilotA first run never guesses. With no terminal and no --autopilot it exits 2 and names the
three ways forward, because a snapshot built from settings nobody chose is a snapshot nobody can
check.
npx codebase-snapshot init --yes # config + scripts + devDependency + .gitignore
npm install # the package, into node_modules
npm run snapshot # generate
npm run snapshot:validate # exit 0 = current with diskThe fingerprint is printed in full — all 64 hex characters, never elided — and it is the same value
as manifest.fingerprint.
What you get
snapshot/
├── README.md human summary of this snapshot
├── PROMPT.md the instruction sheet to paste with it
├── manifest.json machine index: files, parts, hashes, config, skips
├── parts/part-001.md … the code, grouped and size-budgeted
└── reports/
├── project-tree.md directory tree of included files
├── navigation.md links between layers, kinds and parts
└── audit.md secrets, large files, parse diagnostics, git stateEvery artifact can be turned off (--skip-artifacts, --only-artifacts, or the config).
→ Snapshot output and manifest schema
Built to be trusted with a whole repository
A snapshot is only useful if you can believe it, so the tool is explicit about what it does not contain.
Nothing is dropped silently. Every excluded path is recorded in
manifest.skipped[]with a reason —binary,gitignore,sensitive-file,symlink,read-error,excludedand the rest — andexplain <path>answers the same question for any single file.Counts describe what was emitted.
includedBytesandincludedLinesare measured from the block in the part, not from the file on disk. A file that is not valid UTF-8 is kept and labelledutf-8-lossyrather than vanishing as "binary".Drift is checked, not assumed.
validatecompares every file's hash and a digest of the settings the snapshot was generated with, so a changed budget or secret pattern is drift rather than silence.The output directory is the tool's. Each run is written to a scratch directory and swapped in atomically, and it refuses to replace a directory it did not create —
--out-dir srccannot destroy source code.The brief travels with the payload.
PROMPT.mdis a brief, not a packing slip: the job, the system map the manifest can prove (layers, load-bearing modules, entry points, indexed surfaces), the recent commit history as claims to verify rather than rediscover, the evidence bar, the coverage owed, and calibration examples. Then the apparatus — this run's parts, partial files with their missing line ranges, fingerprint, and the attachment arithmetic. The judgement half can come from your own file (brief) and the job frompromptTask. A prompt that names the wrong snapshot is a lie that reads as current, so it is an artifact with a recorded digest andvalidatefails when it is edited.Credential files are excluded by default —
.env,*.pem,.npmrc,id_rsa,*.tfstateand more — and secret-shaped strings inside ordinary files are redacted by masking only the matched span, never the whole line.
Supported projects
25 presets, detected from the repository — each contributing layers, kinds, ecosystem ignore patterns and a recommended part budget.
Next.js | Nuxt | SvelteKit | Remix |
Astro | Angular | Solid | Vue + Vite |
React + Vite | NestJS | Express / Fastify / Koa | Node library |
Monorepo | Django | FastAPI / Flask | Python library |
Go | Rust | Java / Spring | .NET |
Laravel (PHP) | Rails (Ruby) | Terraform / Docker infra | Docs-only |
generic fallback |
Non-TypeScript languages get import/export/class/function summaries rather than being treated as
opaque text, and every summary is labelled ast, structural or heuristic so you know how much
to trust it.
→ Preset table and detection rules
Commands
Command | Does |
(none) | The guided first run. Asks once when the project has no config; generates otherwise. |
| Write the snapshot. |
| Config, npm scripts, devDependency, install and generate, in one command. |
| Compare the snapshot with the repository; exit |
| Snapshot health, layer metrics, secret audit. |
| Interactive (or |
| Why one path is included, which part it lands in, or why it was skipped. |
| Compare two snapshots. |
| The machine-readable contract ( |
| Ask npm whether a newer release exists; exit |
| Print or install the agent skill. |
| Serve the repository to an MCP client over stdio. |
Exit codes: 0 success · 1 drift, refused generation, or nothing to snapshot · 2 usage error,
or a first run with no terminal and no --autopilot.
Once a day it checks the npm registry for a newer release and mentions it on stderr — skipped in CI,
in any --format json run, and in mcp. Turn it off with --no-update-check.
For AI agents
Everything an agent needs is available as data, and the tool can install its own skill.
npx codebase-snapshot describe --format json # contract: workflow, options, exit codes
npx codebase-snapshot skill --install # into .claude/skills + .cursor/rules
npx -y codebase-snapshot@0.20.13 mcp # or serve it over MCPAn agent told only "use npx codebase-snapshot" can read the contract, follow its ordered
workflow, and produce a validated snapshot unaided — that path is covered by a test.
The MCP server exposes 26 tools — status, health, budget, history, tests, workspace, entrypoints, neighbors, routes, cycles, search, stats, review, diff_context, symbol, context, query, plan_for, answer, plan, generate, validate, locate, dependents, read and explain — plus
snapshot:// resources and seven prompts. Its reads come from the snapshot rather than the working
tree, so an excluded file stays excluded and a redacted value stays redacted, and
snapshot_validate answers the question an agent otherwise cannot ask: is the context I was given
still true?
It speaks both protocol eras, including the 2026-07-28 revision: stateless server/discover,
required MCP-Protocol-Version/Mcp-Method/Mcp-Name HTTP headers, cache hints on every
cacheable result, and the modern resource-not-found code. The suite drives it through the official
MCP v2 client over both modern stdio and modern HTTP.
→ Using this with an AI agent · MCP server · AGENTS.md · llms.txt
Configuration
snapshot.config.json is written by init with every setting at its current value, so it
doubles as the reference. Deleting any line is safe: the defaults are real. JSON is deliberate:
the MCP server and serve refuse executable repository configs.
{
"maxPartBytes": "120k",
"excludePatterns": ["vendor/**", "**/*.min.js"],
"artifacts": { "monolith": false },
"budgets": { "default": "120k", "byLayer": { "docs": 40000 } },
"includeSensitiveFiles": false
}Programmatic API
import { generateSnapshot, resolveConfig, validateSnapshot, loadConfigFile } from "codebase-snapshot";
// Pass the repository explicitly: loadConfigFile returns only the config it found, so a
// directory with no config file would leave resolveConfig scanning process.cwd() instead.
const dir = "/path/to/repo";
const config = resolveConfig(await loadConfigFile(dir), { cwd: dir });
const manifest = generateSnapshot(config);
const validation = validateSnapshot(config);CommonJS works too (require("codebase-snapshot")), with type definitions for both. The CLI, the
API and the MCP server share one implementation, so anything one of them does is available in the
others.
Documentation
Every client, version pinning, agent skill install | |
Commands, options, exit codes, examples | |
Every setting, all 25 presets, budgets, hooks, secrets | |
Directory layout and the full manifest schema | |
Leak, integrity and token audit of a generated snapshot | |
| |
| |
| |
| |
| |
Reproducible token and time numbers for the three modes | |
Threat model, controls, tests and residual risks | |
Container, compose and systemd, with the token requirement | |
What changed from 0.12.14 to 0.20.13, and the behaviour changes that matter | |
| |
| |
The half of PROMPT.md only you can write, and what is refused | |
The contract, the skill, what an agent should avoid | |
26 tools, resources, both protocol eras, modern HTTP conformance | |
Every message and what to do about it | |
Release history and breaking changes |
Guides: feeding a codebase to ChatGPT, Claude or Cursor · stale LLM context is a bug · how many tokens a codebase is · budgeting a context window · vs repomix · vs gitingest · vs code2prompt
Contributing
Issues and pull requests are welcome — see CONTRIBUTING.md and the code of conduct. Security reports: SECURITY.md.
License
MIT © Ankur Halder
Available Tools
26 toolssnapshot_answerQuestion in, budgeted context outARead-onlyIdempotent
The one-call version of plan-then-read: plan a question, then return each chosen file as a head window with line numbers within the token budget. Every included file says why it is there; every planned file that did not fit says so. Read-only.
Inputs: question (required), root, outDir, maxTokens, +2 more. Returns: files, omitted, question, usedTokens, +1 more
snapshot_budgetWhat a larger budget would buyARead-onlyIdempotent
Run the planner at several token budgets and report what each one adds: files, tokens used, entry points kept and the files gained over the previous budget. Answers "should I raise the budget, and what would I get?" without writing a snapshot. Read-only.
Inputs: root, outDir, budgets, question, +1 more. Returns: budgets
snapshot_contextAssemble a bounded context blockARead-onlyIdempotent
Given file paths, symbol names, or both, return their contents (from the snapshot, so redacted and preview-bounded) as one context block within a token budget. Each file contributes a head window; files that do not fit are reported, never silently dropped.
Inputs: root, files, outDir, symbols, +2 more. Returns: files, missing, usedTokens, budgetTokens
snapshot_cyclesImport cyclesARead-onlyIdempotent
Strongly connected components in the import graph: files that import each other in a loop. Computed with the same resolver the generator uses, so a reported cycle is one the snapshot really has. Read-only.
Inputs: root, outDir, maxComponents. Returns: components, filesInCycles
snapshot_dependentsFollow the import graphARead-onlyIdempotent
For one file in the snapshot: what it imports, and which files import it. Answers "what breaks if I change this?" without reading the parts.
Inputs: path (required), root, limit, outDir, +1 more. Returns: path, imports, importedBy, unresolved
snapshot_diff_contextContext for a set of changed filesARead-onlyIdempotent
Given the paths a change touched, return each one head window plus the files that import it, within a token budget. The dependents are what a reviewer usually misses. Read-only.
Inputs: paths (required), root, outDir, maxTokens, +1 more. Returns: changed, missing, dependents, usedTokens, +1 more
snapshot_entrypointsLikely entry pointsARead-onlyIdempotent
The files a reader should start from: conventional entry points (index, main, app, server, cli) and manifests, with their importer counts. The same heuristic the token-budget planner uses, exposed so an agent can start where a maintainer would. Read-only.
Inputs: root, outDir. Returns: entries
snapshot_explainExplain one pathARead-onlyIdempotent
Explain how the next snapshot would treat one path: its layer, kind, language and part, or the exact reason it is excluded. Answers "why is this file missing".
Inputs: path (required), only, root, sarif, +7 more. Returns: path, reason, included
snapshot_generateGenerate the snapshotAIdempotent
Write the snapshot to its output directory and return its fingerprint, parts and counts. Replaces the previous snapshot in that directory. A large repository can take several seconds.
Inputs: only, pack, root, sarif, +16 more. Returns: files, parts, skipped, fingerprint, +3 more
snapshot_healthSnapshot health auditARead-onlyIdempotent
Audit the generated snapshot against the repository: manifest shape, part hashes, the artifacts it claims, unmasked secrets anywhere in the written text, values from files that were excluded as sensitive, host paths, the recorded token count and freshness. Returns a score and one entry per check. Read-only; it never regenerates anything.
Inputs: deep, root, outDir, maxScanBytes. Returns: score, checks, counts
snapshot_historyRecent commits behind the snapshotARead-onlyIdempotent
The commits the snapshot was built from, from reports/log.md. Answers "when was this written and why" without leaving the snapshot. Generate the report with includeLogs. Read-only.
Inputs: root, limit, outDir. Returns: commits, recorded
snapshot_locateLocate code in the snapshotBRead-onlyIdempotent
Find which part holds the code you need. Matches file paths, exported symbols, component names and routes from the snapshot's index, so one part can be read instead of all of them.
Inputs: query (required), by, root, limit, +1 more. Returns: total
snapshot_neighborsImports and importers of a fileARead-onlyIdempotent
Both directions of the import graph for one path: what it imports and what imports it, resolved against the snapshot and listed with their parts. The question a change asks first. Read-only.
Inputs: path (required), root, outDir. Returns: imports, importedBy
snapshot_planPreview a snapshotARead-onlyIdempotent
Preview a snapshot without writing anything: how many files and parts it would contain, and why every excluded file was excluded. Use it to choose a part budget before generating.
Inputs: only, root, sarif, ignore, +7 more. Returns: files, parts, preset, skipped, +2 more
snapshot_plan_forPlan a reading order for a questionBRead-onlyIdempotent
Given a question and a token budget, return the smallest set of files from the snapshot that answer it, in reading order, each with the reason it was chosen and the part it lives in. Deterministic: path and symbol matches first, then the imports of the strongest matches, packed to the budget. Read-only.
Inputs: question (required), root, outDir, maxTokens, +1 more. Returns: files, notes, skipped, question, +2 more
snapshot_queryQuery the snapshot indexARead-onlyIdempotent
Filter the snapshot by layer, kind, a path regular expression or a symbol name, and return the matching files with their part, line count and token estimate. Use it to find a starting set before snapshot_context or snapshot_read. Read-only.
Inputs: kind, root, layer, outDir, +3 more. Returns: files, matched, returned
snapshot_readRead a file from the snapshotARead-onlyIdempotent
Return a line window of one file as the snapshot contains it: redacted, and bounded to a preview when the source is large. Reports the next fromLine when more remains.
Inputs: path (required), root, lines, outDir, +1 more. Returns: part, path, reason, fromLine, +4 more
snapshot_reviewReview a change set against the snapshotARead-onlyIdempotent
One call for a review: is the snapshot current, what does the health audit say, and what do the given paths contain? Combines validate, health and bounded reads so a reviewer does not have to ask three questions to start. Read-only.
Inputs: root, paths, outDir, linesPerFile. Returns: files, score, failed, routes, +2 more
snapshot_routesRoutes and handlersBRead-onlyIdempotent
Every route a summary recorded - HTTP methods from decorators, framework attributes and route tables - with the file and part that declare it. Read-only.
Inputs: root, outDir, pattern. Returns: total, routes
snapshot_searchSearch the snapshot textARead-onlyIdempotent
Case-insensitive text search across the emitted parts, bounded by a match cap and a scan budget. Returns the path, part and line number of each match with a short snippet. Reads only what the snapshot contains, so redacted values and excluded files are never found.
Inputs: query (required), root, regex, outDir, +2 more. Returns: matches, scanned, truncated
snapshot_statsSnapshot statisticsARead-onlyIdempotent
Counts and costs: files by layer and kind, part sizes, token estimate, the largest files and the most expensive parts. Read from the manifest, so it is cheap and always agrees with what the snapshot claims.
Inputs: root, outDir. Returns: files, kinds, parts, layers, +3 more
snapshot_statusSnapshot statusARead-onlyIdempotent
Report whether a snapshot exists for this repository, when it was built, and what it covers. Reads the manifest rather than the repository, so it is cheap. Call it before deciding whether a snapshot needs to be generated.
Inputs: root, outDir. Returns: root, outDir, present, partCount, +7 more
snapshot_symbolFind a symbol definitionARead-onlyIdempotent
Find where a function, class, interface, type or constant is defined in the snapshot and return a window around the definition with line numbers. Searches the emitted parts, so redaction still applies. Read-only.
Inputs: name (required), root, lines, outDir, +3 more. Returns: found, matches, references
snapshot_testsTests that cover a file, and files a test coversARead-onlyIdempotent
The test side of the graph. Given a path, the tests that import it (plus the ones named after it); with no path, every test file and how many files it exercises. Read-only.
Inputs: path, root, outDir, maxFiles. Returns: tests, covered
snapshot_validateValidate the snapshotARead-onlyIdempotent
Re-read the repository and report whether the snapshot on disk still matches it. Use it before trusting context that came from an earlier session, or after changing the config.
Inputs: only, root, sarif, ignore, +6 more. Returns: current, manifestPresent
snapshot_workspaceWorkspace indexARead-onlyIdempotent
The members of a multi-repository workspace and the imports that cross between them, from WORKSPACE.json. Answers which member depends on which before a change. Read-only.
Inputs: root, outDir. Returns: links, members
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 26 tools
Several tools overlap sharply: snapshot_neighbors and snapshot_dependents both return a file's imports and importers, while snapshot_context/read/answer/plan_for and snapshot_status/validate/health/review form layered clusters where an agent must infer the intended granularity. Descriptions explain the differences, but 26 tools still create real misselection risk.
All tools use the snapshot_ prefix and snake_case, so names are predictable and scannable. The convention is mostly noun-based with some verb-based names (generate, validate, read), which is a minor inconsistency but not confusing.
26 tools exceed the rubric's 25+ threshold and feel heavy for a snapshot/context server. Many are convenience composites or narrow graph queries that could be consolidated, so each does not clearly earn its place.
The surface covers the snapshot lifecycle well: plan/generate/validate/health/status/history plus broad read/search/graph navigation. Gaps are minor, such as no explicit delete/prune for stale snapshots and no incremental refresh, but core workflows are covered.
Maintenance
Related MCP Connectors
Turn a GitHub repo or docs site into agent-ready context: pack it or search it, over MCP.
LLM cost optimization gateway, repo token-waste auditor & model arbitrage MCP server.
Shared memory MCP server for Claude Code, Codex, Gemini CLI and Cursor. Cited, editable.
Document-to-Markdown MCP server — convert PDF, Office and HTML into LLM-ready Markdown.
Related MCP Servers
- AlicenseAqualityCmaintenanceGenerates AI context files (CLAUDE.md, AGENTS.md, Cursor/Windsurf/Cline/Continue/Kilo Code/Trae rules, GEMINI.md, Copilot, Aider, Junie, Warp) for any repository. Runs as CLI or MCP server, 100% local.334 npm1MIT
- AlicenseAqualityBmaintenanceTurn any folder or Git repository into token-efficient context for Claude Code, Codex, and Cursor: up to 40% fewer tokens than Repomix, secrets always masked. MCP server with code search, a dependency graph, Git diff review, and Live Context. No embeddings, no vector database.8648Apache 2.0
- AlicenseAqualityBmaintenanceLocal-first code context CLI + MCP server: discover, index, and search repos; generate task-aware context packs, code maps, agent harnesses, and PR-review/merge-readiness gates for coding agents and reviewers.14466 npm3MIT
- AlicenseNot gradedqualityBmaintenanceEnables local LLM tools and agentic IDEs to inspect repository token maps, retrieve clean token-bounded codebase snapshots, and audit code for hardcoded secrets via MCP over stdio.4MIT