Skip to content
2 min read · 469 words

@nhtio/adk/batteries/llm/claude_code_cli/exceptions ​

Battery-scoped exception constructors for the Claude Code CLI adapter.

Remarks ​

Battery-scoped exception classes minted via createException from @nhtio/adk/factories. Malformed NDJSON frames (either the wrapper's own inbound-command reader, or its translation of Claude's stream-json) are explicitly NOT a distinct exception — they are swallowed and surfaced via helpers.log.trace, matching the Ollama battery's malformed-line policy.

Variables ​

VariableDescription
E_CLAUDE_CODE_CLI_BINARY_NOT_FOUNDThrown when the claude binary cannot be located/spawned.
E_CLAUDE_CODE_CLI_CONTEXT_OVERFLOWThrown when the assembled request exceeds the configured contextWindow during the pre-flight context-window guard. Only raised when tokenEncoding is non-null. Carries { total, contextWindow, tokenEncoding, perBucket } in the message so middleware can target shedding.
E_CLAUDE_CODE_CLI_MCP_BRIDGE_STARTUP_FAILEDThrown when the wrapper's own MCP bridge server fails to start, OR Claude's system/init reports an mcp_server_errors entry naming the bridge, OR the @modelcontextprotocol/sdk optional peer is missing at wrapper startup.
E_CLAUDE_CODE_CLI_PROCESS_EXITED_NONZEROThrown when the wrapper process exits with no terminal result/error event observed.
E_CLAUDE_CODE_CLI_STARTUP_TIMEOUTThrown when the wrapper does not signal ready and Claude's system/init within startupTimeoutMs.
E_CLAUDE_CODE_CLI_STREAM_ERRORThrown on a transport-level stream failure between the adapter and the wrapper.
E_CLAUDE_CODE_CLI_STREAM_STALLEDThrown when the wrapper's stdout goes idle for longer than streamIdleTimeoutMs.
E_CLAUDE_CODE_CLI_TURN_FAILEDThrown when Claude's terminal result reports isError: true for a terminal error subtype other than error_max_turns, notably CLI-native budget exhaustion from --max-budget-usd. The error_max_turns subtype is the normal successful completion signal for this adapter's fixed single-turn dispatch contract.
E_CLAUDE_CODE_CLI_UNSUPPORTED_MEDIA_MODALITYThrown when a @nhtio/adk!Media whose modality cannot be represented reaches either direction of this battery under the corresponding unsupportedMediaPolicy/ unsupportedResultMediaPolicy: 'throw' — bidirectional: inbound prompt media (a -p string has no native image channel) and outbound tool-result media (only text/image MCP content blocks are supported).
E_CLAUDE_CODE_CLI_WRAPPER_CRASHEDThrown when the wrapper process crashes or exits abnormally mid-dispatch.
E_CLAUDE_CODE_CLI_WRAPPER_NOT_FOUNDThrown when no wrapper asset could be located on disk — neither the path resolved relative to the adapter module's own compiled location, nor the fallback resolved via this package's own bare-specifier self-reference, pointed at an existing file. The most common cause is a consumer bundling this adapter (e.g. Vite/Electron Forge bundling an Electron main process): the adapter module no longer lives inside @nhtio/adk's own directory tree, and @nhtio/adk is not reachable as an ordinary dependency from the bundled code's new location either. Set the wrapperPath option to the built wrapper asset's absolute path to fix this.
E_CLAUDE_CODE_CLI_WRAPPER_SPAWN_ERRORThrown when the wrapper process itself fails to spawn.
E_INVALID_CLAUDE_CODE_CLI_OPTIONSThrown when the resolved adapter options (constructor, executor overrides, or per-dispatch stash.claudeCodeCli) fail validation — including extraArgs security-flag rejection, the apiKey/authToken XOR violation, and the POSIX-only platform guard.