Claude Code (@anthropic-ai/claude-code) is an interactive AI-powered coding assistant that runs as a CLI application in the terminal. It provides a REPL (Read-Eval-Print Loop) interface where users can have conversations with Claude to write, edit, debug, and understand code.
- TypeScript — The entire codebase is written in TypeScript with strict type checking
- Node.js — Runtime environment (ESM modules,
"type": "module"in package.json) - Bun — Used internally for feature flags (
bun:bundle) and dead code elimination; not the runtime for end users
- esbuild — Transpile-only (no bundling). The build script (
build.mjs) handles:- TypeScript/TSX → JavaScript transpilation
bun:bundleandbun:ffishim generation- Bare
src/import rewriting to relative paths .jsxextension fixing for React components.d.tsimport stripping- Empty stub generation for missing internal modules
- Runtime shims for internal packages
- Ink — React for the terminal. Claude Code uses Ink to render its terminal UI
- React — Components use React patterns (hooks, JSX, functional components)
- React Compiler — Some UI files use
react/compiler-runtimefor memoization
- Zod v4 — Used extensively for:
- Tool input/output schema definitions
- Hook response validation
- Configuration parsing
- Runtime type validation
@anthropic-ai/sdk— Anthropic's official SDK for API communicationlodash-es— Utility library (always cherry-picked imports, never full import)chalk— Terminal string stylingcommander— CLI argument parsingdiff— Diff generation for file editsglobby— File globbingmarked/marked-terminal— Markdown rendering in terminalstrip-ansi— ANSI escape code strippingzod/v4— Schema validation (note: imported fromzod/v4, notzod)
The codebase uses a feature flag system via bun:bundle:
import { feature } from 'bun:bundle'
// At build time, feature('FLAG') resolves to true/false
// enabling dead code elimination of entire code paths
if (feature('PROACTIVE')) {
// This entire block is removed from builds where PROACTIVE is false
}Common feature flags include:
PROACTIVE— Proactive/autonomous agent featuresREACTIVE_COMPACT— Reactive compaction strategyTRANSCRIPT_CLASSIFIER— Auto permission modeHARD_FAIL— Development crash-on-error modePROMPT_CACHE_BREAK_DETECTION— Cache break monitoring
- External users — Standard Node.js runtime, feature flags control available features
- Internal users (
ant) —process.env.USER_TYPE === 'ant'enables additional debugging, error logging to disk, and internal-only commands - Cloud providers — Bedrock (
CLAUDE_CODE_USE_BEDROCK), Vertex (CLAUDE_CODE_USE_VERTEX), and Foundry (CLAUDE_CODE_USE_FOUNDRY) have specific environment flags
Key scripts from package.json:
typecheck— TypeScript type checking without emitbuild— Run the esbuild build scriptlint— ESLint + Biome lintingtest— Vitest test runner
The application has multiple entry points in src/entrypoints/:
- CLI entry — Main interactive REPL
- SDK entry — Programmatic usage as a library
- Bridge entry — Remote connection support (IDE extensions, mobile)
- Subcommand entries —
claude config,claude mcp, etc.
User Input → CLI/Bridge → REPL Loop → Query Engine → Anthropic API
↓
Tool Execution
(Bash, Edit, Grep, etc.)
↓
Permission Check
↓
Result Rendering (Ink/React)
The core loop:
- User provides a prompt (via REPL or programmatic API)
- System/user context is assembled (git status, CLAUDE.md files, etc.)
- The prompt + context is sent to the Anthropic API
- The model responds with text and/or tool use requests
- Tool use requests go through permission checking
- Approved tools execute and return results
- Results are rendered via Ink React components
- The loop continues until the model stops requesting tools