Claw Code is a clean-room open-source reimplementation of the Claude Code agent harness, built in Python and Rust. This claw code getting started guide walks you through every step — from cloning the repo to running advanced CLI subcommands and building the Rust runtime.

安裝

Clone the repository from GitHub to get started with claw code:

git clone https://github.com/instructkr/claw-code.git cd claw-code

The repository is organized into four top-level directories: src/ for the Python layer, rust/ for the six Rust crates, tests/ for the test suite, and assets/ for static resources.

Python 快速入門

The Python layer provides the primary CLI interface. All commands use the python3 -m src.main entrypoint with a subcommand argument:

# Render the porting summary python3 -m src.main summary # Print the workspace manifest python3 -m src.main manifest # List modules (limit output) python3 -m src.main subsystems --limit 16 # Run the test suite python3 -m unittest discover -s tests -v # Audit against the original archive python3 -m src.main parity-audit # List commands and tools python3 -m src.main commands --limit 10 python3 -m src.main tools --limit 10

全部 27 個 CLI 子命令

Claw Code exposes 27 subcommands through the Python CLI. Each subcommand maps to a specific agent operation, from workspace inspection to full runtime mode selection:

Subcommand 用途
summaryRender the porting progress summary
manifestPrint the workspace manifest
parity-auditAudit against the original TypeScript archive
setup-reportShow workspace setup report with prefetches and deferred init
command-graphDisplay the command dependency graph
tool-poolShow the tool registry pool
bootstrap-graphVisualize the 7-stage bootstrap sequence
subsystemsList all modules/subsystems
commandsList available slash commands
toolsList registered tools
routeShow mode routing table
bootstrapRun the full bootstrap sequence
turn-loopExecute the conversation turn loop
flush-transcriptFlush the current transcript to disk
load-sessionLoad a saved session
remote-modeStart in remote mode
ssh-modeStart in SSH tunnel mode
teleport-modeStart in teleport (workspace migration) mode
direct-connect-modeStart in direct-connect mode
deep-link-modeStart in deep-link mode
show-commandInspect a specific command
show-toolInspect a specific tool
exec-commandExecute a specific command
exec-toolExecute a specific tool

Rust 建構與 CLI

The Rust layer compiles to the rusty-claude-cli binary. Build and test with standard Cargo commands:

# Build the release binary cargo build --release -p rusty-claude-cli # Run the full test suite (excluding compat harness) cargo test --workspace --exclude compat-harness

The Rust CLI supports the following commands and flags:

Command / Flag 說明
promptSubmit a prompt to the agent
--resumeResume a previous session
dump-manifestsDump workspace manifests
bootstrap-planDisplay the bootstrap execution plan
system-promptPrint the system prompt
--helpDisplay help information
--versionPrint version
--output-format text|jsonControl output format
--allowedToolsRestrict which tools the agent may use

環境變數

Claw Code reads the following environment variables to configure authentication, model selection, runtime behavior, and remote connectivity:

Variable 用途
ANTHROPIC_API_KEYPrimary API key for Anthropic authentication
ANTHROPIC_AUTH_TOKENBearer token for proxy/OAuth authentication
ANTHROPIC_BASE_URLOverride the default API base URL
ANTHROPIC_MODELOverride the default model selection
RUSTY_CLAUDE_PERMISSION_MODESet the permission enforcement mode
CLAUDE_CONFIG_HOMEOverride the config directory (default: ~/.claude)
CLAUDE_CODE_REMOTEEnable remote mode
CLAUDE_CODE_REMOTE_SESSION_IDSession ID for remote connections
CLAUDE_CODE_UPSTREAMUpstream server URL for remote mode
CLAWD_WEB_SEARCH_BASE_URLBase URL for web search integration

工作空間設定系統

The WorkspaceSetup system automatically discovers your environment when claw code starts. It detects python_version, implementation (CPython, PyPy, etc.), platform_name, and the test_command (defaulting to python3 -m unittest discover -s tests -v).

The SetupReport includes two phases: prefetches (data gathered eagerly during setup) and deferred_init (initialization deferred until after the trust gate clears). This two-phase approach ensures fast startup while deferring expensive operations until they are actually needed.

啟動流程:7 個階段

Claw Code follows a strict 7-stage bootstrap sequence every time it starts. Each stage depends on the successful completion of the previous one:

Stage Name 說明
1PrefetchEagerly gather workspace metadata, environment variables, and configuration files
2Warning HandlerInstall warning and error handlers for graceful failure reporting
3CLI Parser + Trust GateParse command-line arguments and verify trust/permission requirements
4Setup + Parallel LoadRun workspace setup while loading commands and agents in parallel
5Deferred InitExecute deferred initialization steps after trust gate clears
6Mode RoutingRoute to one of 6 runtime modes: standard, remote, SSH, teleport, direct-connect, or deep-link
7Query Engine Submit LoopEnter the main conversation loop, submitting queries to the LLM and processing tool calls
# Visualize the bootstrap graph python3 -m src.main bootstrap-graph

儲存庫配置

The claw code repository is organized into four top-level directories, each with a clear responsibility boundary:

Directory 語言 Contents
src/PythonAgent orchestration, LLM integration, session management, CLI entrypoint, query engine, tool definitions, command handlers
rust/Rust6 crates: rusty-claude-cli, runtime, api, commands, tools, compat-harness
tests/PythonUnit and integration tests for the Python layer
assets/StaticStatic resources, configuration templates, and reference data