ClaudeCodeBook
No description available
Ask AI about ClaudeCodeBook
Powered by Claude ยท Grounded in docs
I know everything about ClaudeCodeBook. Ask me about installation, configuration, usage, or troubleshooting.
0/500
Reviews
Documentation
Claude Code Book
We have automatically generated the Claude Code Book: ClaudeCodeBook-ไธญๆ.pdf | ClaudeCodeBook-English.pdf

Overview
Claude Code: An AI-powered CLI agent for software development, built by Anthropic.
Claude Code is a command-line interface tool that brings Claude's reasoning capabilities directly into the development workflow. It provides an interactive REPL with AI assistance, a comprehensive tool system for file operations and command execution, Vim-style modal editing, and deep integration with development workflows (Git, shell commands, editors).
The project is written in TypeScript with Bun as the runtime and build tool. It targets multiple platforms (macOS, Linux, Windows) and supports multiple authentication methods including OAuth, API keys, and cloud provider integrations (AWS Bedrock, Google Vertex AI).
Repository Structure
claude-code/
โโโ src/ # Main application source code
โ โโโ index.ts # Application entry point
โ โโโ commands.ts # Slash command registry and loading
โ โโโ context.ts # AI context preparation (system/user prompts)
โ โโโ cost-tracker.ts # API usage tracking and cost reporting
โ โโโ tools.ts # Tool registry and MCP integration
โ โ
โ โโโ commands/ # Slash command implementations (~40 commands)
โ โ โโโ add.ts # Add/edit code with AI
โ โ โโโ autofixPr.ts # Auto-fix pull requests
โ โ โโโ bash.ts # Shell command execution
โ โ โโโ config.ts # Configuration management
โ โ โโโ diff.ts # Git diff viewer
โ โ โโโ git.ts # Git operations
โ โ โโโ ...
โ โ
โ โโโ tools/ # Tool implementations for AI agent
โ โ โโโ BashTool.ts
โ โ โโโ FileReadTool.ts
โ โ โโโ WebSearchTool.ts
โ โ โโโ AgentTool.ts
โ โ โโโ ...
โ โ
โ โโโ utils/ # Shared utilities (~40 subdirectories)
โ โ โโโ bash/ # Shell parsing, security, execution
โ โ โ โโโ exec.ts # Command execution engine
โ โ โ โโโ parser.ts # Shell parser utilities
โ โ โ โโโ security.ts # Command security validation
โ โ โ โโโ shellSnapshot.ts # Shell state capture
โ โ โโโ git/ # Git operations
โ โ โโโ settings/ # Configuration persistence
โ โ โโโ analytics/ # Session analytics and BigQuery export
โ โ โโโ telemetry/ # OpenTelemetry tracing and metrics
โ โ โโโ teleport/ # Remote session API client
โ โ โโโ vim/ # Vim emulation layer
โ โ โโโ todo/ # Todo data types
โ โ โโโ ultraplan/ # Ultra-plan workflow
โ โ โโโ ...
โ โ
โ โโโ bootstrap/ # Application initialization
โ โ โโโ state.ts # Global STATE singleton
โ โ
โ โโโ bridge/ # Remote control infrastructure
โ โ โโโ bridgeApi.ts # Environments REST API client
โ โ โโโ bridgeConfig.ts # Configuration with OAuth/keychain
โ โ โโโ bridgeDebug.ts # Fault injection for testing
โ โ โโโ workSecret.ts # Work secret decoding and session routing
โ โ
โ โโโ buddy/ # Companion mascot system
โ โ โโโ companion.js # Creature generation (seeded PRNG)
โ โ โโโ sprites.ts # ASCII art rendering
โ โ โโโ CompanionSprite.tsx # React sprite component
โ โ
โ โโโ assistant/ # Teleport Agent SDK
โ โ โโโ entrypoints/ # SDK entry points and types
โ โ โโโ utils/ # API client with OAuth support
โ โ
โ โโโ voice/ # Voice mode feature gating
โ โ โโโ voice-mode.ts # GrowthBook + OAuth auth checks
โ โ
โ โโโ vim/ # Vim emulation
โ โโโ transitions.ts # State machine (NORMAL/INSERT modes)
โ โโโ motions.ts # Cursor movement functions
โ โโโ operators.ts # Edit operations (delete, yank, etc.)
โ โโโ textObjects.ts # Text object boundaries
โ โโโ types.ts # TypeScript interfaces and constants
โ
โโโ src/commands.ts # Command registry entry
โโโ src/tools.ts # Tool registry entry
โโโ src/context.ts # Context preparation entry
โโโ src/cost-tracker.ts # Cost tracking entry
โโโ src/index.ts # Main entry point
โ
โโโ package.json # Node.js dependencies
โโโ bunfig.toml # Bun build configuration
โโโ tsconfig.json # TypeScript configuration
โโโ ...
Getting Started
Prerequisites
- Bun โฅ 1.0 (install via bun.sh)
- Node.js โฅ 18 (for fallback)
- macOS / Linux / Windows (WSL supported)
Installation
# Clone the repository
git clone https://github.com/anthropics/claude-code.git
cd claude-code
# Install dependencies with Bun
bun install
# Build the project
bun run build
# Link for development
bun link
Development Setup
# Run in development mode with hot reload
bun run dev
# Run tests
bun test
# Run with debug output
DEBUG=* bun run start
Environment Variables
| Variable | Description | Default |
|---|---|---|
ANTHROPIC_API_KEY | Anthropic API key | Required for API key auth |
DEBUG | Enable debug logging | - |
BUN_ENV | Environment (development, production) | production |
OTEL_LOG_USER_PROMPTS | Include user prompts in telemetry | false |
BETA_SESSION_TRACING | Enable beta tracing attributes | false |
Usage
Basic Commands
# Start an interactive session
claude
# Start with a specific task
claude "Explain this codebase"
# Start with auto-approve mode (for automation)
claude --approve-all "Review and fix bugs"
# Resume a previous session
claude --resume <session-id>
Slash Commands
Available in the interactive REPL:
| Command | Description |
|---|---|
/add [description] | Add or edit code based on description |
/bash <command> | Execute a shell command |
/diff [file] | Show uncommitted changes |
/git <subcommand> | Run a git command |
/config [key] [value] | View or modify configuration |
/clear | Clear the conversation |
/help | Show help information |
/model <name> | Switch the active model |
/compact | Compact context window |
/session | Show current session info |
Configuration
# View current config
claude config list
# Set a config value
claude config set model claude-opus-4-5
# Set an environment variable
claude config set --env API_KEY your_key
Key Modules & Scripts
Core Entry Points
| File | Purpose |
|---|---|
src/index.ts | Main entry point; orchestrates initialization, session management, and the REPL loop |
src/commands.ts | Central registry for all slash commands with feature-gated loading |
src/tools.ts | Tool registry assembling built-in tools, MCP tools, and permission-filtered tools |
src/context.ts | Prepares system and user context for AI conversations |
src/cost-tracker.ts | Tracks API usage, costs, and generates usage reports |
State Management
| Module | Purpose |
|---|---|
src/bootstrap/state.ts | Global STATE singleton with typed accessors for all runtime state |
src/utils/settings/settings.ts | Project-level configuration persistence |
Security & Bash Execution
| Module | Purpose |
|---|---|
src/utils/bash/security.ts | Fail-closed security model; rejects unverifiable shell constructs |
src/utils/bash/exec.ts | Command execution with streaming, timeout, and cancellation |
src/utils/bash/shellSnapshot.ts | Captures shell state for context injection |
Telemetry & Analytics
| Module | Purpose |
|---|---|
src/utils/telemetry/index.ts | Public API for OpenTelemetry tracing and metrics |
src/utils/telemetry/sessionTracing.ts | Span management for interactions, LLM calls, and tools |
src/utils/telemetry/bigqueryExporter.ts | Exports metrics to BigQuery |
src/utils/analytics/sessionAnalytics.ts | Session-level analytics with BigQuery export |
Vim Emulation
| Module | Purpose |
|---|---|
src/vim/transitions.ts | State machine coordinating NORMAL/INSERT modes |
src/vim/motions.ts | Pure functions for cursor movement |
src/vim/operators.ts | Pure functions for edit operations |
src/vim/textObjects.ts | Functions for text object boundaries |
src/vim/types.ts | TypeScript interfaces and state type definitions |
Remote & Cloud Features
| Module | Purpose |
|---|---|
src/bridge/bridgeApi.ts | Environments REST API client for remote control |
src/bridge/bridgeConfig.ts | Configuration with OAuth and keychain integration |
src/assistant/ | Teleport Agent SDK for session management |
src/utils/teleport/api.ts | Sessions API client for remote environments |
Architecture
System Architecture
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ CLI Interface โ
โ User Input โ Slash Commands โ REPL โ Vim Mode โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Command Registry (commands.ts) โ
โ Resolves slash commands, checks feature flags, validates perms โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Tool Registry (tools.ts) โ
โ Built-in tools + MCP tools + permission-filtered tools โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Tool Implementations โ
โ BashTool, FileReadTool, WebSearchTool, AgentTool, ... โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ AI Model (Claude API) โ
โ Context prepared by context.ts โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Cost Tracking (cost-tracker.ts) โ
โ Telemetry (telemetry/) โ
โ Analytics (analytics/) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Authentication Model
Claude Code supports multiple authentication methods:
- OAuth โ User login via
claude auth login(stored in macOS Keychain) - API Key โ Set via
ANTHROPIC_API_KEYenvironment variable - Cloud Providers โ AWS Bedrock, Google Vertex AI, AWS IAM
- Trusted Device โ Device tokens for remote control (CCR v2)
Feature Gating
Features are gated via:
- GrowthBook (
growthbook.js) โ Remote feature flags for A/B testing - Bundle constants (
bun:bundle) โ Dead-code elimination for disabled features - Platform checks โ macOS-only features (Keychain, speech synthesis)
Data Pipeline
Context Preparation Flow
1. User input received
โ
2. context.ts โ getUserContext()
โ โโโ Reads .claude/CLAUDE.md
โ โโโ Reads .claude/instructions.md
โ โโโ Memoized per session
โ
3. context.ts โ getSystemContext()
โ โโโ Git status (branch, recent commits)
โ โโโ Current directory info
โ โโโ Cache breaker injection
โ
4. Combined into system prompt injection
Telemetry Flow
Tool execution / LLM call
โ
Span created by sessionTracing.ts
โ
Events logged by events.ts (logOTelEvent)
โ
Metrics accumulated by OpenTelemetry SDK
โ
bigqueryExporter.ts โ POST to BigQuery API
โ
(Optionally) Perfetto trace file written
Session Analytics Flow
Session starts
โ
Analytics initialized with session ID
โ
Per-tool/per-command metrics accumulated
โ
Session ends
โ
bigqueryExporter.ts โ POST to BigQuery
โ
STATE.sessionAnalytics cleared
Dependencies
Runtime Dependencies
| Package | Purpose |
|---|---|
typescript | TypeScript language support |
@anthropic-ai/sdk | Anthropic API client |
@modelcontextprotocol/sdk | MCP protocol implementation |
@anthropic-ai/growthbook | Feature flag client |
@google-cloud/bigquery | BigQuery analytics export |
@aspect-build/rules_ts | TypeScript build rules |
@aspect/registry | Aspect registry |
@opentelemetry/* | OpenTelemetry SDK |
@vueuse/core | Vue composition utilities |
tree-sitter-bash | Shell parsing |
zod | Schema validation |
uuid | UUID generation |
semver | Semantic version parsing |
jose | JWT handling |
ora | Terminal spinners |
chalk | Terminal colors |
glob | File globbing |
diff | Text diffing |
yaml | YAML parsing |
zx | Shell script utilities |
Development Dependencies
| Package | Purpose |
|---|---|
bun | Runtime and build tool |
vitest | Unit testing framework |
@types/node | Node.js type definitions |
ts-node | TypeScript execution |
eslint | Linting |
prettier | Code formatting |
License
Proprietary โ Claude Code is developed and maintained by Anthropic PBC. Usage is subject to Anthropic's Acceptable Use Policy and Terms of Service. For commercial licensing or enterprise deployments, contact Anthropic at anthropic.com. This repo does not contain any original Claude Code source code.
