Skip to content

@makaio/ai-adapters-claude-code-cli

Claude Code CLI AI adapter for the Makaio framework. Integrates with Claude by spawning the claude CLI binary and consuming its JSONL stdout stream instead of using the Agent SDK.

import { createClaudeCliAdapter } from '@makaio/ai-adapters-claude-code-cli';
import { MakaioBus } from '@makaio/bus-core';
import { AdapterSubjects } from '@makaio/contracts';
const adapter = await createClaudeCliAdapter();
const result = await MakaioBus.request(AdapterSubjects.startAgent, {
adapterId: adapter.adapterId,
role: 'lead',
initialMessage: 'Inspect this repository',
model: 'claude-sonnet',
});

Three-layer design matching the framework adapter contract:

LayerClassResponsibility
DomainClaudeCodeCliAdapterHandles adapter.* bus subjects, lifecycle
AgentClaudeCodeCliAgentHandles agent.* subjects, routes connector events
ConnectorClaudeCliConnectorSpawns claude -p, reads JSONL stdout

The CLI emits event shapes identical to the Anthropic SDK. Shared agent logic from @makaio/ai-adapters-claude-shared handles all event routing without modification.

The connector namespace is adapter:claude-code-cli. It is scoped to connector and agent events for this adapter; cross-namespace requests such as MCP session registration go through the framework bus subjects owned by those services.

Tool approval requests flow through the singleton HTTP MCP bridge service rather than a direct bus bridge. The bridge routes approval requests to AgentSubjects.toolApprove on the global bus. Adapters register and unregister their per-session context through McpSubjects.session.register and McpSubjects.session.unregister.

import { McpSubjects } from '@makaio/contracts';
const { handled, data } = await MakaioBus.requestOptional(McpSubjects.session.register, {
adapterSessionId: 'adapter-session-1',
agentId: 'agent-1',
adapterId: 'adapter-1',
adapterName: 'claude-code-cli',
sessionId: 'makaio-session-1',
contextOverrides: {
cwd: '/repo',
sessionId: 'makaio-session-1',
agentId: 'agent-1',
},
});
if (handled) {
console.log(data.port);
}

The adapter declares runtime capabilities through the framework capability system and also exposes test-specific metadata for the conformance suite.

Runtime capabilities declared by the adapter:

CapabilityMeaning
toolsClaude Code tool use through the CLI/MCP bridge
chatInTurnMessagesMultiple user messages can be merged into the current turn
systemPrompt:overrideReplace/set the system prompt
systemPrompt:appendAppend to the adapter’s default system prompt

Conformance-test capabilities returned by createTestConfig():

FeatureSupported
supportsReplaceNo
supportsInterruptNo

startAgent.model should be supplied by the host after resolving the selected provider/model. The CLI receives that value as --model; if omitted, the claude binary falls back to its own configured default.

The adapter can use a host-resolved managed claude binary, an explicit providerConfig.binaryPath, or PATH lookup for claude. An explicit provider config path wins.

import { createTestConfig } from '@makaio/ai-adapters-claude-code-cli';
// Register bridge handlers when a test needs MCP approval routing
const config = await createTestConfig();
FilePurpose
src/adapter.tsClaudeCodeCliAdapter and createClaudeCliAdapter factory
src/agent.tsClaudeCodeCliAgent — event routing layer
src/connector.tsClaudeCliConnector — spawns CLI process, reads JSONL
src/session.tsClaudeCliSession — session state for a single agent run
src/turn.tsTurn state machine for one user/assistant exchange
src/config.tsClaudeCodeCliConfig — settings resolution
src/provider.tsProvider presets and model configuration
src/schemas.tsClaudeCodeCliProviderConfigSchema
src/types.tsInternal type definitions
src/constants.tsAdapter name and shared constants
src/definition.tsInternal adapter definition consumed by the package descriptor
src/package.tsMakaioExtension package descriptor with adapters[] contribution
src/server.tsServer entrypoint that re-exports the package descriptor as default
src/namespace/Bus namespace, subjects, and event schemas
src/utils/Utility functions (CLI args, stdio transport, etc.)