Book implements the Agent Client Protocol (ACP) as an ACP server. IDE clients (such as Xcode) connect to Book over stdio, open sessions, send prompts, and receive streaming responses โ€” all via the ACP JSON-RPC wire protocol.

This page covers running and configuring the ACP server. For registering Book inside Xcode, see Xcode Integration. For the server architecture internals (AcpServer lifecycle, per-session isolation, capability-driven environment), see Embedding Book as an ACP Agent (Phase 4).

Starting the ACP Server

There are two entry points:

# Recommended: explicit flag form
bk --mode acp

# Deprecated sub-command form
bk serve   # DEPRECATED: Use 'bk --mode acp' instead

Both delegate execution to AcpModeRunner.run(…​) which handles background extension job synchronization, stdout stdio protection, and calls AcpServer.start(…​).

Transport Flags

Flag Values Default Notes

--acp-transport

stdio / http

stdio

Use stdio for all current integrations.

--acp-host

any hostname

localhost

Bind address for --acp-transport http.

--acp-port

any port number

8080

TCP port for --acp-transport http.

Note: --acp-transport http throws NotImplementedError in the current release โ€” the ACP SDK (v0.25.0) does not yet ship an HTTP transport. This flag is reserved for a future release.

--mode Flag Interaction

--mode is a repeatable enum option (tui, acp, mcp). When multiple values are passed:

  • --mode acp and --mode tui together: a warning is emitted and ACP wins.

  • --mode acp and --mode mcp together: --mode mcp is silently ignored at startup โ€” MCP server config arrives per-session via session/new.

Per-Session _meta Configuration

Clients that support the ACP _meta field can pass per-session configuration knobs in the session/new or prompt request body. AcpMetaParser parses the following book.* keys:

Key Type Description

book.maxTurns

Int

Maximum number of agent turns before stopping.

book.maxUnproductiveTurns

Int

Maximum consecutive unproductive turns.

book.cacheMaxTurnAge

Int

Maximum turn age for PureToolResultCache entries.

book.disablePruning

Boolean

Disable message-history pruning pipeline for this session.

book.compactionThresholdFraction

Double

Compaction trigger threshold (0.0โ€“1.0).

Example _meta payload:

{
  "book.maxTurns": 10,
  "book.maxUnproductiveTurns": 3,
  "book.cacheMaxTurnAge": 2,
  "book.disablePruning": false,
  "book.compactionThresholdFraction": 0.75
}

All keys are optional. Absent or unrecognised keys are silently ignored. Returns null when _meta is absent, not a JsonObject, or contains no book.* keys โ€” the hasAnyOverride() guard prevents callers from receiving a semantically-empty config instance.

Session Configuration Options

Book advertises native session configuration options to ACP clients, allowing IDE pickers (such as IntelliJ IDEA, Xcode, Junie, or Zed) to directly select the model and reasoning effort.

  • Model option (model): Lists the models returned by the provider’s listModels() call โ€” the provider is the source of truth. The local ModelMetadataRegistry is used only as a cross-reference (context window, pricing) and as a fallback seed if the provider fetch has not completed yet.

  • Reasoning effort option (thought_level): Offers reasoning effort levels (off, minimal, low, medium, high, xhigh, max) corresponding to EffortLevel values.

  • Usage Update Suppression: SessionUpdate.UsageUpdate events are only emitted when the model’s context window size is known (size > 0); models with unknown or zero context windows suppress usage updates to prevent misinformation.

Background Model Refresh & Sync

  • Hybrid Seed-Then-Refresh: Sessions start with a synchronous local model list seed to ensure instant client responsiveness. Immediately after session initialization (postInitialize()), a background refresh calls agentLoop.listModels() to fetch live model metadata. On success with non-empty results, the picker list is updated and a SessionUpdate.ConfigOptionUpdate is pushed to the client. On failure or empty results, the local seed is retained silently with a warning log (silent degradation).

  • Slash-Command Synchronization: Executing /model or /effort slash commands in ACP mode updates the session configuration and automatically notifies client pickers via a shared guarded emission helper.

  • Emission Safety: All option-update emissions route through a single guarded helper (emitConfigOptionUpdate) using trySend with error logging; post-session/delete emissions become logged no-ops.

When a client sends session/set_config_option:

  • Model switches (model): Validated against the provider’s advertised model list (a model not offered by the provider is rejected) and rejected if a prompt turn is active (IllegalStateException). On success, updates agentLoop.setModel(modelId), emits a SessionUpdate.ConfigOptionUpdate with refreshed options, and emits an immediate SessionUpdate.UsageUpdate to rescale the client context usage meter.

  • Reasoning effort switches (thought_level): Case-insensitively mapped to EffortLevel, sets sessionEffort and agentLoop.setThinkingLevel(…​), re-emits SessionUpdate.ConfigOptionUpdate, and returns updated options.

  • No session/set_config_option operation writes to persistent storage (configManager / sessionOrchestrator).

ACP Heartbeat Interval

While a tool process runs under ACP, a concurrent heartbeat emits Stdout(".") every 10 s. The period can be overridden at process startup via an environment variable:

Env var Type Default Constraint

BOOK_ACP_HEARTBEAT_INTERVAL

integer (seconds)

10

Must be > 0; non-numeric or โ‰ค 0 values fall back to the default.

Example โ€” set a 30-second heartbeat interval:

BOOK_ACP_HEARTBEAT_INTERVAL=30 bk --mode acp

Streaming limitation: full terminal output is only available after the command exits โ€” real-time stdout streaming is not supported by the ACP terminal RPC surface.

Slash Commands in ACP Mode

In ACP mode, slash commands are routed through the domain SlashCommandRegistry (not the TUI’s SlashCommandRouter) and rendered back to the client as ACP events. Commands with rendering == TUI_ONLY are excluded from the ACP-visible command list โ€” they are not meaningful outside the terminal UI. See the command list in Xcode Integration.

Troubleshooting

  • Agent fails to initialize โ€” check ~/.bk/agent/logs/; a missing OPENAI_API_KEY is the most common cause.

  • Non-JSON line before the first response โ€” kotlin-logging: initializing…​ is cosmetic; ACP-compliant clients must ignore non-JSON stdout lines.

  • Tool calls not visible โ€” requires Xcode 26.6+.

  • Sessions not listed โ€” sessions are stored relative to the cwd the client passes in session/new; run bk sessions list --all.