This repository is a source-recovery and refactoring workspace for
@anthropic-ai/claude-code@2.1.81.
The upstream distributable is the bundled CLI in cli.js. The goal here is to
move from that bundle-derived codebase toward a maintainable TypeScript project
with:
- first-party source in
src/claude-code - third-party packages isolated behind explicit imports
- a generated, loadable JS recovery tree in
recovered-js - direct source-level tests in addition to bundle-regression tests
There are three important representations in this repo:
-
cli.jsThe behavioral oracle. This is the original bundled CLI that the project is being recovered from. -
src/claude-codeThe transitional first-party source tree. This is where refactoring work happens. New extractions should land here as normal modules with direct imports, not as more bundle-era wrappers. -
recovered-jsA generated JS tree emitted fromsrc/claude-code. It exists to keep a clean executable/loadable recovery target while the TS tree is still being normalized.
-
src/claude-code/coreThe main recovery target. Most of the large merged files live here, alongside progressively extracted source modules. -
src/claude-code/vendorThe source-side third-party boundary. First-party code should import through these wrappers instead of importing npm packages directly. -
recovered-js/_externalsGenerated JS-side third-party wrappers used by the recovered tree. -
testsMixed validation:- bundle/harness regression tests
- direct source-level TS tests
- generated JS/loadability checks
-
scriptsAST-backed normalization and recovery scripts. Prefer these over regex-based transforms for structural work. -
src/_mirror_map.jsonGenerated crosswalk from this recovery tree to the preferred external reference tree at../../claude-code-source-reference/src(clone ofhangsman/claude-code-source), orCLAUDE_CODE_MIRROR_DIRif overridden. Falls back to../../anthropic-leaked-source-codeonly if the preferred reference tree is absent. -
src/_sourcemap_map.jsonGenerated crosswalk from this recovery tree to the preferred source map at../../claude-code-source-reference/cli.js.map, orCLAUDE_CODE_SOURCEMAP_FILEif overridden. Falls back to~/Downloads/cli.js.maponly if the preferred source map is absent.
- Treat
cli.jsas the behavioral reference until source parity is proven. - Treat
src/claude-codeas the place for maintainable code. - Treat
recovered-jsas generated output. Do not hand-edit it. - Prefer extracting semantic seams from large merged files instead of doing blind one-file-per-wrapper splits.
- Keep third-party code out of
src/claude-code; route it throughsrc/claude-code/vendor.
Install dependencies:
npm installRun the full validation path:
npm run ciRegenerate the generated artifacts after source edits:
npm run sync:generatedCheck generated artifacts without rewriting them:
npm run check:generatedRegenerate the optional mirror crosswalk:
npm run map:mirrorRegenerate the source-map crosswalk:
npm run map:sourcemapRegenerate both preferred reference crosswalks:
npm run map:referenceCheck the recovered JS tree is loadable:
npm run recover:js:loadcheckCheck the source CLI path directly:
npm run source:cli:checkBundle-oriented validation:
npm run build
npm run verifySource validation:
npm run typecheck
npm test- Extract a coherent seam from a large merged file in
src/claude-code/core. - Add direct tests for the new source module.
- Run
npm run typecheckand the relevant focused tests. - Run
npm run sync:generated. - Run
npm run ci.
The target is not "prettier generated output." The target is a normal TS module graph where:
srcis the source of truth- vendor packages are explicit imports
- tests run against source directly
- the recovered/generated compatibility layers can eventually be deleted