Anthropic — Claude Code
Drive Anthropic's Claude Code from inside agent loops — the optional override for AgentField's default AForge harness — with budget caps, schema-bound output, and the official claude_agent_sdk.
Claude Code is an optional override. AgentField's harness runs AForge, its own native worker, by default — set provider="claude-code" when you specifically want Claude driving the loop.
Spawn Anthropic's Claude Code from inside agent loops. The Python harness uses the official claude_agent_sdk package directly, so plan-mode reasoning and multi-turn refactors run with no CLI sitting in your container.
Reach for Claude Code when the work needs careful reasoning — code reviews, surgical refactors, multi-step planning, or anything that benefits from the agent thinking before it edits.
Quickstart
Only needed for this provider — the default AForge path installs nothing. Add the official Claude SDK alongside AgentField: Python takes the harness-claude extra and TypeScript takes the @anthropic-ai/claude-agent-sdk npm package as a project dependency, both loaded in-process. Only the Go harness drives the claude CLI as a subprocess, so that tab installs the CLI instead.
pip install 'agentfield[harness-claude]'
export ANTHROPIC_API_KEY=sk-ant-...Call the harness
Attach a HarnessConfig to the agent so every .harness(...) call inherits sensible defaults — provider, model, budget, permission mode — without re-specifying them. Override per call when a specific task needs something different.
from pydantic import BaseModel
from agentfield import Agent, HarnessConfig
class ReviewResult(BaseModel):
findings: list[str]
severity: str # "low" | "medium" | "high"
# Defaults live on the agent — one place, every harness call inherits them.
app = Agent(
node_id="reviewer",
harness_config=HarnessConfig(
provider="claude-code",
model="sonnet",
permission_mode="plan", # plan first, then execute
max_turns=12,
max_budget_usd=0.50,
tools=["Read", "Grep", "Glob"],
),
)
@app.reasoner()
async def review_diff(diff: str) -> dict:
result = await app.harness(
f"Review this diff. Find real issues — be precise, no fluff.\n\n{diff}",
schema=ReviewResult,
)
if result.is_error:
# Caller can route to a fallback provider or surface a structured failure.
return {"ok": False, "error": result.error_message}
return {
"ok": True,
"review": result.parsed.model_dump(),
"cost_usd": result.cost_usd,
"num_turns": result.num_turns,
"session_id": result.session_id,
}Composition pattern — plan-then-implement
Claude Code is a strong planner. Pair it with a faster implementer like Codex for the actual edits — same harness loop, one field flipped.
# Claude plans the change set, Codex executes it.
plan = await app.harness(
f"Read the codebase and produce a minimal-diff plan to {goal}.",
provider="claude-code",
permission_mode="plan",
schema=ChangePlan,
)
if plan.is_error:
raise RuntimeError(plan.error_message)
edits = await app.harness(
f"Apply this plan exactly:\n\n{plan.parsed.model_dump_json()}",
provider="codex", # swap provider, reuse the loop
permission_mode="auto",
schema=EditReport,
)Options
| Option | Type | Default | What it does |
|---|---|---|---|
provider | string | "aforge" | Set to "claude-code" to select this provider. Unset means the AForge default. |
model | string | empty | Empty resolves to sonnet, the provider's own default (unchanged from before). Set any alias the claude_agent_sdk accepts ("sonnet", "opus", "haiku"). |
permission_mode | string | null | "plan" (plan-first, then execute) or "auto" (bypass permissions). Maps to bypassPermissions on the SDK. |
tools | string[] | ["Read","Write","Edit","Bash","Glob","Grep"] | Allowed tool names — gates what Claude Code is allowed to invoke. |
max_turns | int | 30 | Hard cap on agent iterations. |
max_budget_usd | float | null | Cost ceiling. The SDK aborts when total spend would exceed this. |
system_prompt | string | null | Custom system prompt prepended to the loop. |
env | dict | {} | Extra environment variables forwarded to the subprocess. |
cwd | string | working dir | Working directory the agent treats as the repository root. |
schema | model | null | Pydantic class / Zod schema / Go struct. Forces JSON output validated against the schema. |
Authentication
- Set
ANTHROPIC_API_KEYin the harness's environment. The SDK picks it up automatically; you do not need to pass it throughapp.harness. - Check what the provider can see before you depend on it:
af harness doctor --provider claude-code. - For Anthropic Vertex or Bedrock routing, follow the official
claude_agent_sdkconfiguration.
When to choose Claude Code
- Code review and audits — plan mode lets the agent enumerate findings before changing any files.
- Multi-turn refactors where intermediate reasoning matters more than throughput.
- Surgical edits in a known codebase — Claude excels at minimal, targeted diffs.
- Reasoning-heavy tasks where stepping through the problem beats brute iteration.
Pairs well with
- Codex — Claude reviews, Codex implements. Run them in sequence.
- Gemini CLI — let Gemini ingest the whole repo first, then hand findings to Claude for surgical edits.
- OpenCode — adversarial pattern: Claude proposes, an open-weight OpenCode loop verifies.
See also
AForge — the default harness
AForge is AgentField's native coding harness. It ships with af, needs no CLI install, and runs every app.harness(...) call that does not name a provider.
OpenAI — Codex
Drive OpenAI Codex from inside agent loops — the optional override for AgentField's default AForge harness — with budget caps, schema-bound output, and subprocess control.