@ankurhalder/codebase-snapshot

中文文档
4.4.1发布于 2026/11/05MITTypeScriptESM + CJS构建来源已验证近 30 天下载 3666

Production-grade LLM codebase snapshot generator, auditor, and AST partitioner

此软件包已被标记为弃用

Renamed to codebase-snapshot, which is the supported package. Run: npx codebase-snapshot@latest setup

原始使用文档
文档目录14 节
  1. Why
  2. Install
  3. Quick start
  4. What you get
  5. Built to be trusted with a whole repository
  6. Supported projects
  7. Commands
  8. For AI agents
  9. Configuration
  10. Programmatic API
  11. Documentation
  12. Safety
  13. Contributing
  14. License

codebase-snapshot

Turn any repository into an LLM-ready snapshot: code packed into size-budgeted markdown parts, indexed by a JSON manifest, with a secret audit — in one command.

npm version npm downloads license node

npx @ankurhalder/codebase-snapshot generate

That writes ./snapshot/ — a directory you can drop into a chat, a prompt, a RAG pipeline or a repository review. It works on TypeScript and JavaScript projects, and on Python, Go, Rust, Java/Kotlin, C#/.NET, PHP, Ruby, C/C++, Vue, Svelte and Astro, without configuration.

How it works


Why

Feeding a real repository to a model is awkward: files are too big, context windows are too small, and picking what matters by hand does not scale or repeat. codebase-snapshot does it deterministically:

  • One file per part, never over budget. maxPartBytes is a hard ceiling. A file bigger than the budget is truncated with an explicit omission marker naming the budget rather than blowing the limit — and above largeFileBytes it becomes a head/tail excerpt instead.
  • An index, not just text. manifest.json lists every included file with its layer, kind, language, part, hash and a structural summary — and every excluded file with the reason.
  • Provably current. validate re-hashes the repository against the snapshot and exits non-zero on any drift, so a pipeline can gate on context being fresh.
  • Deterministic where it matters. Two runs over unchanged input give byte-identical parts/, reports/navigation.md and reports/project-tree.md, and the same manifest.fingerprint. Only manifest.json, the snapshot's README.md, reports/audit.md and .codebase-snapshot change between runs, because they carry timestamps, a run id and a pid.
  • Safe by default. Credential files are skipped unless asked for, secret-shaped strings are redacted, and a mistyped output directory cannot delete source code.
  • Usable by agents, not just humans. A machine-readable contract and an installable skill let an agent with no prior knowledge drive the whole thing.

Install

npx @ankurhalder/codebase-snapshot generate      # no install, one-off
npm install -D @ankurhalder/codebase-snapshot    # or add it to a project

Any npm-compatible client works — npm, yarn (classic and Berry with strict PnP), pnpm and bun — each verified against the packed tarball before release. Requires Node.js 18+.

→ Installation guide

Quick start

One command does the whole first run — detects the project, writes a commented config, adds the npm scripts and the devDependency, installs it, and generates the snapshot:

npx @ankurhalder/codebase-snapshot setup
# Or step by step, if you want to see each stage:
npx @ankurhalder/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 disk

setup keeps a config the repository already has, and setup --no-install skips the install (CI, offline, or a lockfile you would rather not touch).

📸 Generating snapshot for: /Users/you/project
   Branch: main | Part budget: 300 KB

✅ Snapshot generated in 0.14s:
   - Tracked files: 128
   - Total lines:   9,431
   - Total size:    0.41 MB
   - Parts written: 3 under snapshot/parts/
   - Reports:       snapshot/reports/ (project-tree, navigation, audit)
   - Manifest:      snapshot/manifest.json
   - Fingerprint:   e4607b570268c8def0911babbace97e4a0196d9eaf2cac22c8847500883d70aa
   - Integrity:     passed

The 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
├── 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 state

Every 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 everything it does not contain:

  • Nothing is dropped silently. Every excluded path is recorded in manifest.skipped[] with a reason — binary, gitignore, default-ignore, sensitive-file, sensitive-path, symlink, outside-root, read-error, not-file, nested-repository, excluded — and explain <path> answers the same question for any single path.
  • Encoding is stated, not guessed. UTF-16 files are transcoded instead of vanishing as "binary"; a file that is not valid UTF-8 is kept but labelled utf-8-lossy with the count of undecodable bytes, so you never mistake mojibake for source.
  • Counts describe what was emitted. includedBytes and includedLines are measured from the block in the part, not from the file on disk.
  • Drift is checked, not assumed. validate compares every file's hash and a digest of the settings the snapshot was generated with, so a changed budget, layer rule or secret pattern is drift rather than silence.
  • Memory is bounded. Files above 2 MB are not parsed for a structural summary (that is where a 50 MB file used to reach 3 GB of resident memory), and 130 000 files in one directory or a 3 000-level path scan without crashing.
  • diff compares payloads, not just paths. Two snapshots of identical sources with different settings say so instead of reporting "0 changed".
  • When git cannot list files — an interrupted clone, a dehydrated .git, safe.directory — the run refuses rather than quietly scanning something different, and --discovery walk is the documented escape hatch.

Supported projects

25 presets, detected automatically from the repository — each contributing layers, kinds, ecosystem ignore patterns and a recommended part budget.

Next.jsNuxtSvelteKitRemix
AstroAngularSolidVue + Vite
React + ViteNestJSExpress / Fastify / KoaNode library
MonorepoDjangoFastAPI / FlaskPython library
GoRustJava / Spring.NET
Laravel (PHP)Rails (Ruby)Terraform / Docker infraDocs-only
generic fallback

Non-TypeScript languages get import/export/class/function summaries rather than being treated as opaque text. Vue, Svelte and Astro script blocks go through the real TypeScript compiler. Every summary is labelled ast, structural or heuristic so you know how much to trust it — Python, for example, is a line-scan heuristic, while JSON and Markdown get structural shapes.

→ Preset table and detection rules

Commands

CommandDoes
generate (default)Write the snapshot.
validate / checkCompare the snapshot with the repository; exit 1 on drift.
reportSnapshot health, layer metrics, secret audit.
initInteractive (or --yes) setup that writes a self-documenting config.
explain <path>Why one path is included, which part it lands in, or why it was skipped.
diff <a> <b>Compare two snapshots.
describeThe machine-readable contract (--format json).
skillPrint or install the agent skill.

Exit codes: 0 success · 1 drift or refused generation · 2 usage error.

→ Full CLI reference

For AI agents

Everything an agent needs is available as data, and the tool can install its own skill:

# The contract: workflow, every option and default, exit codes, presets, safety rules
npx @ankurhalder/codebase-snapshot describe --format json

# Install the skill into the registries agent tools read: .claude/skills/, .cursor/rules/
# (it adds those files to .gitignore, and never touches your own AGENTS.md)
npx @ankurhalder/codebase-snapshot skill --install

An agent told only "use npx @ankurhalder/codebase-snapshot" can read the contract, follow its ordered workflow, and produce a validated snapshot unaided — that path is covered by a test.

→ Using this with an AI agent · AGENTS.md · llms.txt

Configuration

snapshot.config.ts (or .mjs) is written by init with every setting at its current value, commented and grouped, so it doubles as the reference. Deleting any line is safe: the defaults are real. The object is exported through a name — export default { … } is import/no-anonymous-default-export, on by default in eslint-config-next.

const config = {
  maxPartBytes: "120k",                                   // hard budget per part
  excludePatterns: ["vendor/**", "**/*.min.js"],
  artifacts: { monolith: false },                         // single-file output stays off
  budgets: { default: "120k", byLayer: { docs: 40_000 } },
  includeSensitiveFiles: false,                           // .env, *.pem … stay out
};

export default config;

→ Configuration reference

Programmatic API

import { generateSnapshot, resolveConfig, validateSnapshot, loadConfigFile } from "@ankurhalder/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("@ankurhalder/codebase-snapshot")), with type definitions for both. The CLI and the API share one implementation, so anything the CLI does is available here.

Documentation

InstallationEvery client, version pinning, agent skill install
CLI referenceCommands, options, exit codes, examples
ConfigurationEvery setting, all 25 presets, budgets, hooks, secrets
Snapshot outputDirectory layout and the full manifest schema
AI agentsThe contract, the skill, what an agent should avoid
TroubleshootingEvery message and what to do about it
ChangelogRelease history and breaking changes
WikiGuides, recipes, FAQ

Safety

  • Credential files are excluded by default — .env, *.pem, *.key, .npmrc, .netrc, .git-credentials, id_rsa, .kube/config, *.tfstate — and listed in manifest.skipped[] with the reason.
  • Secrets are redacted inside ordinary files: only the matched span is masked, never the whole line, and no excerpt reaches any artifact.
  • The output directory is owned by the tool. Each run is written to a scratch directory and swapped in atomically; the previous snapshot survives a failure.
  • It refuses to replace a directory it did not create, so --out-dir src cannot destroy source code.

Contributing

Issues and pull requests are welcome — see CONTRIBUTING.md and the code of conduct. Security reports: SECURITY.md.

License

MIT © Ankur Halder

版本与发布记录

@ankurhalder/codebase-snapshot 共发布 19 个版本,首次发布于 2026/11/03;过去 12 个月发布了 19 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
4.4.1latest2026/11/053 天前
4.4.02026/11/053 天前
4.3.02026/11/043 天前
4.1.12026/11/043 天前
4.1.02026/11/043 天前
4.0.72026/11/043 天前

关于 @ankurhalder/codebase-snapshot 的常见问题

@ankurhalder/codebase-snapshot 是什么?

Production-grade LLM codebase snapshot generator, auditor, and AST partitioner注意:该包已被作者标记为弃用——Renamed to codebase-snapshot, which is the supported package. Run: npx codebase-snapshot@latest setup

如何安装 @ankurhalder/codebase-snapshot?

在项目目录运行 npm install @ankurhalder/codebase-snapshot,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 snap、codebase-snapshot,可以用 npx snap 直接运行。

@ankurhalder/codebase-snapshot 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@ankurhalder/codebase-snapshot 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@ankurhalder/codebase-snapshot 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=18.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@ankurhalder/codebase-snapshot 可以商用吗?

@ankurhalder/codebase-snapshot 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@ankurhalder/codebase-snapshot 的下载量有多少?

根据 npm 官方下载统计,@ankurhalder/codebase-snapshot 在 2026/10/07 – 2026/11/05 这 30 天内被下载 3,666 次,日均约 122 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@ankurhalder/codebase-snapshot 还在维护吗?

最新版本 4.4.1 发布于 2026/11/05(3 天前);至今共发布 19 个版本,其中过去 12 个月发布了 19 个;首次发布于 2026/11/03。作者已将其标记为弃用,新项目建议寻找替代方案。