AgentHarness.Providers.Claude.Adapter.Exec (AgentHarness v0.3.0)

Copy Markdown View Source

ClaudeCode.Adapter that runs the Claude Code CLI through an AgentHarness.Exec implementation instead of a local port.

This keeps the whole claude_code protocol stack — stream-json framing, the control-protocol handshake, hook and MCP routing, questions and approvals — on the orchestrator, while the CLI process itself runs wherever the configured exec module puts it: locally through AgentHarness.Exec.Local, or in a remote sandbox through an exec implementation provided by the application.

Select it per session with auth: :inherit (the fail-closed :subscription mode pins the local port adapter by design):

provider_options: %{
  auth: :inherit,
  adapter: {AgentHarness.Providers.Claude.Adapter.Exec,
            exec: {MyApp.SandboxExec, sandbox: sandbox}}
}

Adapter options

  • :exec{module, opts} implementing AgentHarness.Exec. Defaults to {AgentHarness.Exec.Local, []}.
  • :cli_path — executable name or path, resolved in the execution environment. Defaults to "claude".

All other options are the ordinary claude_code session options (:model, :cwd, :env, :api_key, :can_use_tool, :resume, ...).

Differences from ClaudeCode.Adapter.Port

  • The spawn spec is remote-safe: cwd and the executable resolve in the execution environment, and only explicit entries are forwarded: the SDK vars, the :env option, and :api_key. The Port adapter forwards the orchestrator's whole System.get_env/0; this adapter never does. The execution environment's own environment remains the base, so under Exec.Local the command still inherits this VM's environment because the command runs here.
  • cwd has no orchestrator-side default. The Port adapter falls back to File.cwd!(); here a missing :cwd means the execution environment's default working directory, and the can_use_tool callback context omits :cwd until one is configured.
  • No reconnect-on-query. When the exec reports exit, the adapter stays disconnected — AgentHarness treats provider transport loss as session-fatal, and a dead sandbox process usually means a dead sandbox.
  • execute/4 applies on the orchestrator node. SDK features that expect filesystem access next to the CLI (History, Plugin/skills materialization) do not reach the execution environment.

This module intentionally mirrors ClaudeCode.Adapter.Port and reuses the SDK's protocol helpers. It is coupled to the pinned claude_code version; treat SDK upgrades as a review point for this file.

Summary

Functions

Returns a specification to start this module under a supervisor.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.