Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Architecture

Claude Code Rust is a terminal application with two local components: a Rust process owns the interface and application state; a TypeScript bridge translates between the app and Anthropic’s Agent SDK. Read Development to run a checkout and Testing to validate a change.

Runtime Shape

Keyboard / terminal events
           |
           v
Rust app state and event loop <----> Rust terminal rendering
           |
     NDJSON commands / events
           |
           v
TypeScript bridge <----> Claude Agent SDK <----> Claude services and tools

Rust starts a Tokio runtime and runs the app inside a LocalSet, which supports the non-Send parts of terminal and child-process handling. The bridge is a child process running under Bun. Newline-delimited JSON (NDJSON) carries one command or event envelope per line over its standard input and output.

Support commands such as doctor, CLI help, completions and manual generation take a separate path before an interactive session starts. Detailed launch resolution belongs in Startup and launch settings.

Follow one prompt

  1. Startup resolves the working directory and launch arguments. The app handles trust, authentication and session selection before admitting an initial prompt.
  2. The composer submits a prompt through the application’s existing input and command path. The bridge client sends a command envelope over stdin.
  3. The TypeScript bridge maps the command to the active SDK session. The SDK supplies model output, tool activity and interaction requests.
  4. The bridge converts those results into typed events. Rust applies them to the relevant session state; permission and question requests become interactive UI.
  5. Rendering projects the canonical transcript into terminal rows. Finished output enters terminal scrollback; the live reply, composer and footer remain in the active area.
  6. A permission answer or other interaction travels back through the command path. Completion, cancellation and failure are handled by their lifecycle owners, rather than inferred from displayed text.

The invariant reference explains the identity checks, saved-history behavior and failure paths behind this flow. In particular, saved history must not cause another desktop notification, and a transport acknowledgement does not by itself prove that an operation completed.

Rust Terminal App

AreaResponsibility
src/main.rsProcess entrypoint, runtime, logging and exit behavior.
src/lib.rsCLI arguments, subcommands and diagnostics presets.
src/agent/Bridge resolution, process client, wire types and bridge errors.
src/app/Application state, lifecycle, sessions, input, permissions, settings and trust.
src/ui/Ratatui and Crossterm rendering of chat, tools, dialogs and fullscreen views.

The normal conversation renders inline. Fullscreen views temporarily use the alternate screen and return to chat when closed. Transcript layout, insertion into terminal scrollback, and resize replay have separate responsibilities; see Transcript rendering and Resize replay before changing that path.

Agent SDK Bridge

agent-sdk/src/bridge.ts and the modules under agent-sdk/src/bridge/ adapt SDK commands, callbacks and history into the application’s protocol. The runtime executes the compiled agent-sdk/dist/bridge.js; editing TypeScript requires rebuilding it.

The paired wire definitions are src/agent/wire.rs and agent-sdk/src/types.ts. Update both in one change when the transport contract changes. These definitions describe the internal Rust/bridge boundary, not a supported third-party SDK.

The SDK owns subprocess option serialization. The bridge forwards its argument array without reconstructing it. Assistant text and Markdown links are preserved across streaming, completed replies and saved history; structured citation objects are not transported to Rust as source references.

Where a change belongs

ChangeStart hereRelevant coverage
Launch flag or startup behaviorsrc/lib.rs, launch resolution, bridge session lifecycletests/cli_startup.rs, tests/docs_cli_contract.rs
Saved setting or structured editorBridge settings catalog/service; Rust config state and UIBridge settings tests, tests/config_flow.rs
Slash command or composer interactionApp command and input handling, bridge dispatch where neededtests/slash_input_flow.rs, bridge command tests
Transcript layout, resizing or shutdownUI layout and application terminal lifecycletests/terminal_resize.rs and rendering unit tests
SDK event or wire changeBridge event projection and Rust conversion/consumerBridge contract tests plus the affected Rust workflow
Installer or package contentsscripts/, npm launcher and platform mappingThe npm-package-layout CI job; Packaging

The testing guide maps these areas to executable checks. For a cross-boundary change, follow the actual input through its consumer and observable outcome before choosing tests.

Subsystems

Each link below owns the detailed rules for that concern.

Boundaries

Claude Code Rust owns the terminal UI, local settings surface, bridge process management and event rendering. Anthropic owns the SDK, authentication and service behavior, billing, models and upstream Claude Code semantics.

The application uses its local TypeScript bridge as the SDK integration point. SDK package subpath exports such as /browser, /bridge and /assistant are not the application’s runtime entry point.