| Mode | Description |
|---|---|
| Interactive REPL | Default mode. Full terminal UI with message history, status bar, and keyboard shortcuts. |
| SDK / headless | Non-interactive mode. No UI. Accepts a prompt, runs the agent loop, and writes structured output to stdout. |
SDK entrypoint
The SDK surface lives inentrypoints/sdk/ and consists of three files:
| File | Purpose |
|---|---|
coreTypes.ts | Core TypeScript types for SDK input and output |
coreSchemas.ts | Zod schemas for validating SDK messages |
controlSchemas.ts | Schemas for control messages (abort, status updates) |
QueryEngine class (QueryEngine.ts) is the headless query engine that drives the agent loop without any UI rendering. It accepts messages, runs tool calls, and emits structured output events.
CLI flags for non-interactive use
-p / --print
Runs Claude Code in print mode. Claude processes the prompt, executes any needed tools, and exits. No interactive input is read from stdin.
--output-format
Controls the format of Claude’s output.
- json
- stream-json
Emits a single JSON object after the agent loop completes. Contains the final assistant message, token usage, cost, and session metadata.Example output:
--input-format stream-json
Accepts streaming JSON input on stdin instead of a single prompt string. Each line must be a valid JSON message. This lets you pipe structured input into Claude Code from another process.
Running Claude Code in a CI/CD pipeline
The-p flag combined with --output-format json makes Claude Code straightforward to embed in automated pipelines:
MCP server mode
Claude Code can act as a Model Context Protocol (MCP) server, exposing its tools and agent capabilities to any MCP-compatible client:entrypoints/mcp.ts. In this mode Claude Code listens for MCP requests on stdin/stdout and responds with MCP-formatted messages. No interactive UI is started.