Claude Code Harness Guide
Audience: Users — Operators configuring or troubleshooting the Claude Code harness adapter.
The Claude Code adapter enables hpilot to use Claude as a pipeline agent via the claude-agent-sdk Python package. hpilot runs the SDK in-process and explicitly directs it to the standalone claude executable through the SDK's public CLI-path option.
An effort resolved from global model_effort or stage_overrides.<stage>.effort is passed to the SDK after normalization. hpilot does not impose an effort vocabulary; the SDK and selected model decide validity. A synchronous SDK option rejection ends the stage on its first attempt. Later SDK iteration and transport failures remain retryable and surface their SDK diagnosis separately from the preserved transcript. Omitting effort preserves the SDK default.
Configuration and Setup
Prerequisites
- The
claude-agent-sdkPython package (>=0.2.87) is included as a standard hpilot dependency. The minimum version provides theThinkingConfigAdaptiveandThinkingDisplayoptions needed for summarized thinking. - A standalone Claude Code CLI must be on
PATH; verify it withclaude --version. - Authentication is handled by Claude Code through the SDK. hpilot passes SDK
setting_sourcesfor user, project, and local settings, so Claude Code loads~/.claude/settings.json, project.claude/settings.json,.claude/settings.local.json, normal environment variables, and existing Claude Code login credentials. hpilot doctorverifies that the SDK is importable and the standalone CLI is onPATH; Claude authentication failures are surfaced by the SDK when a Claude stage starts.
Headless and Autonomous Operation
- The Claude adapter uses the SDK's
bypassPermissionspermission mode for fully autonomous operation. - Disallowed tools (including
EnterPlanMode,ExitPlanMode, andAskUserQuestion) are passed through SDK options to prevent interactive prompts that would block automation. - Claude stages request adaptive thinking with summarized display by default so supported models can emit SDK-provided thinking summaries. Visible assistant text still renders as
reply:events; only true thinking blocks render asthinking:. - Run hpilot as the account that normally uses Claude Code. Claude Code may refuse autonomous permissions for a root account.
Settings and evaluation
The Claude adapter does not patch .claude/settings.json or install Claude Code callbacks:
- Contract enforcement and verifier decisions remain hpilot-owned. hpilot evaluates each completed SDK turn while the session is alive and sends a focused continuation prompt when the result is blocked.
- Read-only path enforcement uses the shared Git-backed guard to detect protected Git-visible changes without restoring them.
- The final reply and contract result are returned after the SDK session exits; blocking decisions are evaluated between turns while the session remains alive.
Permission Enforcement
- Disallowed Tools: Tools that could block automation (e.g.,
AskUserQuestion,EnterPlanMode) are denied through SDKdisallowed_toolsoptions. - Read-Only Paths: Protected file writes are detected and reported without restoring them. The stage captures one Git-backed status baseline before its attempts begin, then fails if a protected path changes during any attempt.
- Logging: Evaluation events are logged to
.hpilot/logs/evaluation-events.jsonl.
Troubleshooting
Claude stage reports missing authentication
hpilot does not duplicate Claude Code's authentication resolution during preflight. Set credentials in the normal Claude Code locations, then rerun the stage. Supported locations include shell environment variables, env entries in Claude settings files, and existing claude login credentials.
Stage fails with read-only path violation
If a stage modifies a file matching its read_only_paths configuration, the protected modification remains in place and the stage fails. Adjust the stage's read_only_paths or prompt to avoid writing to protected paths.
Stream Output and Cancellation
Log event classification
- Visible assistant text (Claude
TextBlock) renders asreply:events. Multiline replies appear with a blank line before the indented body; each content line keeps its original leading whitespace from the agent output, so code blocks, nested lists, and other indented structures keep their shape. Single-line replies use the inline formatreply: text. - True model thinking (Claude
ThinkingBlock) renders asthinking:events with the same blank-line-and-indent format and per-line leading-whitespace preservation. Visible text is never labeledthinking:. hpilot requests summarized thinking from the SDK by default; simple prompts may still omit thinking entirely. - See Runtime and Daemon (User Guide) for the full log format reference.
Daemon cancellation
The Claude adapter runs in-process via a background thread. When you run hpilot cancel, the daemon requests cancellation of the running SDK task and then joins the thread. The worker also checks the cancellation event at short intervals in case the cross-thread event-loop wakeup is delayed. Cancellation interrupts the in-flight SDK call so the async iteration unwinds cleanly, the SDK generators close without error, and the stage stops promptly with exit code 130 — the SDK thread does not continue after cancellation.
Continuation and sessions
- A contract or verifier block can trigger another turn in the same Claude session instead of restarting the stage.
- Each completed turn, including an in-session continuation, consumes one stage
max_retriesslot. The session stops when that budget is exhausted. - If a stage retry is needed later, Claude can reuse the captured session when retry continuation is supported. The session identifier is also recorded in
.hpilot/logs/evaluation-events.jsonlwhen evaluation runs.
Native session discovery
Claude SDK transcripts remain in Claude's normal project store and hpilot does not add entries to Claude's history index. The same standalone claude executable used by the SDK provides native inspection. Start with claude --resume in the exact stage workspace and use Ctrl+A to show all projects. In the verified Claude Code 2.1.220 environment, a live hpilot SDK session was omitted from both picker views even though the SDK session API found the transcript; claude --resume <session-id> opened that same session successfully. Treat direct resume using .hpilot/latest-session.json as the verified boundary when the picker omits an SDK session; other Claude Code versions may differ. Project and worktree scoping can also hide native sessions, so picker absence alone does not mean the transcript was deleted.