DEV Community

Cover image for Inspecting Anthropic’s ‘Claude Code’ CLI: Architecture of a $40B AI Agent
Harsh Gautam
Harsh Gautam

Posted on

Inspecting Anthropic’s ‘Claude Code’ CLI: Architecture of a $40B AI Agent

When Anthropic released Claude Code—their flagship agentic command-line interface—it shipped to the public NPM registry as a rolled-up, minified JavaScript bundle (cli.js). The internal engine was deliberately obscured.

However, looking past the minified distribution, the raw Source Maps (cli.js.map) remain fully inspectable. By analyzing the uncompressed TypeScript architecture (archival map reference via AprilNEA), we get a rare, un-obfuscated look at the inner loop of a production-grade ReAct (Reasoning + Acting) AI agent.

Here are four fascinating engineering and systems design patterns sitting right beneath the surface inside QueryEngine.ts:


1. Bypassing V8 via Native "Sidecars" (/vendor/rg)

A common rookie mistake when building local CLI tools that interact with massive codebases is relying on pure JavaScript I/O (e.g., recursive fs.readdir or glob patterns). If Claude Code tried to parse a 20,000-file enterprise repository using the V8 event loop, the terminal would freeze.

Instead, Anthropic adopted the Native Sidecar Pattern:

Inside the package's /vendor directory sits a pre-compiled native Rust binary: Ripgrep (rg.exe / rg). The TypeScript engine acts strictly as the ReAct orchestrator, instantly spawning child processes to hand off the heavy file scanning to native Rust:


typescript
// Pure Sidecar execution inside the bundled tools
const ripgrepPath = path.join(__dirname, '../vendor/rg')
const { stdout } = await execFile(ripgrepPath, ['--json', pattern, targetDir])
Enter fullscreen mode Exit fullscreen mode

Top comments (0)