Skip to main content

Overview

The Claude Code bridge wraps Anthropic’s claude CLI, providing access to Claude’s code-generation and reasoning capabilities through Agent-Ctrl’s unified API. Claude Code is a strong default choice for general coding workflows, tool-heavy tasks, and scenarios where you want fine-grained control over the agent’s system prompt and permission behavior. The bridge is implemented by ClaudeCodeBridge and configured through ClaudeCodeBridgeBuilder. Access the builder through the AgentCtrl facade:

Basic Usage

The simplest Claude Code interaction requires just a prompt:
With model selection:

System Prompts

Claude Code supports two complementary approaches to system prompt configuration, giving you precise control over the agent’s behavior.

Replacing the System Prompt

Use withSystemPrompt() to completely replace the default system prompt with your own. The agent will follow only your instructions, without the built-in Claude Code behavior:

Appending to the System Prompt

Use appendSystemPrompt() to add instructions on top of the default system prompt. This preserves Claude Code’s built-in capabilities (file reading, code editing, command execution) while layering in your project-specific context:

Combining Both Methods

You can use both methods together. withSystemPrompt() sets the base prompt and appendSystemPrompt() adds to it:

Permission Modes

When running Claude Code headlessly (as Agent-Ctrl does), you need to configure how the agent handles tool permission requests. The PermissionMode enum provides four levels of autonomy:
The default is BypassPermissions because Agent-Ctrl runs the CLI in a non-interactive, headless mode. If you use DefaultMode or Plan without an interactive terminal, the agent will hang waiting for permission responses that never come, eventually timing out.

Turn Limits

Each “turn” represents one cycle where the agent reads context, reasons, and takes an action (such as reading a file, editing code, or running a command). Limiting turns helps control execution time, cost, and scope:

Guidelines for Turn Limits

Without a turn limit, Claude Code continues working until it decides the task is complete or the timeout is reached. For predictable behavior, combine withMaxTurns() with withTimeout().

Additional Directories

By default, the agent operates within the working directory set by inDirectory(). Use withAdditionalDirs() to grant access to additional directories, such as shared libraries, configuration repositories, or reference codebases:
Each path in the array must be an absolute path to an existing directory.

Verbose Mode

The verbose() method controls whether Claude Code emits detailed output. Verbose mode is enabled by default and is required for proper JSON stream parsing. In most cases, you should leave this at its default value:
Disabling verbose mode may prevent Agent-Ctrl from correctly parsing the agent’s output.

Streaming with Claude Code

Claude Code streams output as JSON Lines containing message events, system events, error events, and result events. The bridge parses these in real time and delivers them through the standard streaming callbacks:

Event Normalization

During streaming, Claude Code emits several types of events that are normalized into the callback API:
  • Text content from MessageEvent messages (type text) is delivered through onText() with the text string.
  • Tool use from MessageEvent messages (type tool_use) is delivered through onToolUse() with the tool name, input parameters, and call ID.
  • Tool results from MessageEvent messages (type tool_result) are delivered through onToolUse() with tool set to 'tool_result', the tool use ID in the input array, and the result content as output.
  • Error events are delivered through onError() with the error message.

Session Management

Claude Code session IDs are extracted from the session_id field in the stream JSON output. Use them to maintain conversational context across multiple executions:

Data Availability

Not all data points are available from every agent. Claude Code’s current JSON output format has the following coverage: If you need token usage and cost tracking, consider using OpenCode with an Anthropic model, which provides both.

Complete Example