Skip to content
AstroPaper
Go back

Analyzing the Claude Code Source: Architecture, Toolchain, and Code Stats

Edit page

Overview

Claude Code is Anthropic’s CLI tool for interacting with Claude. Its source distribution weighs in at ~163M across 3 folders and 7 files, with 1,902 source files totaling over 512K lines of code. This post breaks down the structure, toolchain, and technology choices behind it.

Project Structure

At the top level, the distribution is minimal:

claude-code-source/
├── cli.js          # 13M  — bundled application entry point
├── cli.js.map      # 57M  — source map for debugging
├── sdk-tools.d.ts  # 116K — TypeScript type definitions
├── package.json    # 4K   — npm package manifest
├── bun.lock        # 4K   — Bun package manager lockfile
├── LICENSE.md      # 4K
├── README.md       # 4K
├── node_modules/   # 29M  — npm dependencies
├── src/            # 35M  — original TypeScript source
└── vendor/         # 29M  — vendored third-party code

Size Distribution

pie title Space Distribution (~163M total)
    "cli.js.map (source map)" : 57
    "src/ (source code)" : 35
    "node_modules/ (deps)" : 29
    "vendor/ (vendored deps)" : 29
    "cli.js (bundle)" : 13
    "Other files" : 0.12

The Source Code: src/

The src/ directory contains 1,902 files organized into logical modules:

ModuleDirectoryPurpose
CoreTool.ts, Task.ts, QueryEngine.ts, context.tsCore abstractions and engine
UIcomponents/, screens/, ink/Terminal UI with Ink
CLIcli/, commands/, entrypoints/, main.tsxCommand-line interface
Featuresskills/, hooks/, keybindings/, voice/, vim/User-facing features
Infrastructureservices/, server/, remote/, state/, migrations/Backend services
Agent/AIassistant/, coordinator/, query/, bridge/, buddy/AI agent orchestration
Memorymemdir/Persistent memory system

Lines of Code by File Type

ExtensionFilesLines%Purpose
.ts1,332379,99774.1%TypeScript — logic, services, utilities
.tsx552132,66725.9%TypeScript + JSX — Ink UI components
.js1821~0%JavaScript — shims/config
Total1,902512,685100%

The codebase is essentially 100% TypeScript. The 18 .js files with only 21 lines are negligible.

The Build: From 1,902 Files to One

The entire src/ directory (35M, 512K lines) gets compiled and bundled into a single cli.js file (13M). This is the standard Node.js distribution pattern:

flowchart LR
    A["src/\n1,902 files\n512K lines\n35M"] --> B["Bundler\n(tree-shaking,\nminification)"]
    B --> C["cli.js\n1 file\n13M"]
    B --> D["cli.js.map\n57M"]
  1. Write source in TypeScript across many files
  2. Bundle into a single JS file using a tool like esbuild, webpack, or rollup — resolving imports, tree-shaking unused code
  3. Publish the bundle to npm

The source (35M) is larger than the bundle (13M), indicating significant tree-shaking and dead code elimination during the build.

The Toolchain

🏗️ Bun — The Package Manager

The presence of bun.lock reveals that Claude Code uses Bun for package management. Bun is a fast JavaScript/TypeScript runtime and toolkit that combines:

Bun is written in Zig, a low-level systems programming language created by Andrew Kelley in 2015. Zig targets the same space as C/C++ but with better safety, no hidden control flow, and excellent cross-compilation support. Bun chose Zig for its near-C performance and seamless C interop (needed to wrap JavaScriptCore, Safari’s JS engine).

🖥️ Ink — The Terminal UI

The 552 .tsx files use Ink, a React renderer for the terminal. Instead of rendering to a browser DOM, Ink renders React components as terminal output:

import { Box, Text } from "ink";

const StatusBar = ({ message }: { message: string }) => (
  <Box borderStyle="round" padding={1}>
    <Text color="green">{message}</Text>
  </Box>
);

This powers all of Claude Code’s interactive UI — spinners, status bars, colored text, input prompts, and scrollable output. Ink uses Yoga (Facebook’s flexbox engine) for terminal layout, so components can use familiar flexbox concepts.

📦 Source Maps — cli.js.map

The largest file in the distribution (57M) is the source map — a JSON file that maps positions in the bundled cli.js back to the original TypeScript source files. It’s 4.4× the bundle size, which is typical. Source maps enable:

It’s purely a development artifact — not needed at runtime. Without it, the distribution drops from ~163M to ~106M.

Key Takeaways


Edit page
Share this post on:

Previous Post
VS Code Workspace: Setup, Configuration, and Remote SSH
Next Post
Anatomy of Claude Code: File and Folder Sizes