1.2 Tech Stack and Runtime Environment

Chapter goal: Understand Claude Code's technology choices and the reasoning behind each decision.


Runtime: Why Bun?

Claude Code runs on Bun ≥ 1.3.5 (and is also compatible with Node.js ≥ 24).

bun install    # install dependencies
bun run dev    # start

Why choose Bun over Node.js:

FeatureAdvantage
Native TypeScript executionRun .ts files directly without a compile step
bun:bundle capabilityfeature() compile-time switches are integrated directly into the bundler
Faster startupLower startup latency for CLI tools
Built-in test runnerUnified toolchain

Most importantly, import { feature } from 'bun:bundle'—this API enables dead code elimination (DCE) at build time, so feature switches for different builds are fully isolated at the binary level.


UI Layer: React + Ink

This is the most "counter-intuitive" choice in the whole stack: using React to render UI in the terminal.

// src/components/some-component.tsx

function StatusBar({ model, cost }: Props) {
  return (
    <Box borderStyle="round">
      <Text color="green">{model}</Text>
      <Text> ${cost.toFixed(4)}</Text>
    </Box>
  )
}

Ink is a library that renders React in the terminal. Claude Code uses it to implement:

The source has 148 terminal UI components (src/components/) and 87 custom Hooks (src/hooks/), comparable in scale to a medium-sized web frontend project.


AI Communication Layer: Multi-Cloud Support

// Three AI backends, one unified interface
// or
process.env.CLAUDE_CODE_USE_BEDROCK     // AWS Bedrock
// or
process.env.CLAUDE_CODE_USE_VERTEX      // Google Cloud Vertex AI

This design allows enterprise users to deploy in their own cloud environments without routing traffic through Anthropic servers.


Full Dependency Stack

Core AI

LibraryUsage
@anthropic-ai/sdkAnthropic API client
@anthropic-ai/claude-agent-sdkAgent SDK (headless mode)
@modelcontextprotocol/sdkMCP protocol support

Network Communication

LibraryUsage
axiosHTTP requests
undiciHigh-performance HTTP (built into Node.js)
wsWebSocket (Bridge remote control)
Server-Sent EventsStreaming response reception

UI & Interaction

LibraryUsage
inkTerminal React renderer
reactUI component framework
fuse.jsFuzzy search (command autocomplete)

Filesystem & Processes

LibraryUsage
chokidarFile watching (hot reload)
execaProcess execution (replacement for child_process)
tree-killProcess tree termination

Data Parsing

LibraryUsage
yamlYAML config parsing
jsonc-parserJSON-with-comments parsing
zodRuntime type validation

Observability

LibraryUsage
@opentelemetry/*Full OpenTelemetry instrumentation

Language: TypeScript + ESM

All source code uses TypeScript + ES Modules (ESM):

// Typical file header

Important conventions:


Native Modules

shims/            # JS fallback implementations for native modules
vendor/           # native binding source (C++/Rust)
image-processor.node  # precompiled image-processing module

Claude Code includes a small number of native Node.js modules (.node files) for performance-sensitive scenarios such as image processing. The shims/ directory provides cross-platform JavaScript fallback implementations.


Next