The Claude Code harness is the layer around the Claude model that provides the tools and manages the context the model sees; Anthropic’s docs say “this surrounding layer is what the term agentic harness refers to” (How Claude Code works). The same harness is available as a library through the Claude Agent SDK (Agent SDK overview).
Applies to: Claude Code documentation (How Claude Code works, Agent SDK overview, Quickstart and agent loop pages) and Anthropic’s June 2, 2026 dynamic workflows post. Last checked: October 27, 2026.
On this page
What the harness does
Anthropic describes the agentic loop as three blended phases: gather context, take action and verify results. The loop “is powered by two components”: models that reason and tools that act, and Claude Code is the layer that provides the tools and manages context (How Claude Code works).
The built-in tools fall into five categories in the docs (How Claude Code works):
| Category | What Claude can do |
|---|---|
| File operations | Read files, edit code, create new files, rename and reorganize |
| Search | Find files by pattern, search content with regex, explore codebases |
| Execution | Run shell commands, start servers, run tests, use git |
| Web | Search the web, fetch documentation, look up error messages |
| Code intelligence | See type errors and warnings after edits, jump to definitions, find references (requires code intelligence plugins) |
Skills, MCP servers, hooks and subagents “form a layer on top of the core agentic loop” (How Claude Code works). See Claude Code skills, Claude Code MCP, Claude Code hooks and Claude Code subagents for each one.
Context and safety are part of the harness
The harness also decides what goes into the context window: conversation history, file contents, command output, CLAUDE.md, auto memory, loaded skills and system instructions. It compacts the conversation automatically as the window fills, and /context shows what is using space (How Claude Code works). For details, see Claude Code compact and context.
Two safety mechanisms sit in the same layer: checkpoints, which snapshot a file before Claude edits it, and permission modes (Auto, Manual, Accept edits and Plan), which set what Claude can do without asking. Shift+Tab cycles through the modes (How Claude Code works).
The docs say the agentic loop, tools and capabilities “are the same everywhere you use Claude Code”: the terminal, the desktop app, IDE extensions, claude.ai/code, Remote Control, Slack and CI/CD pipelines. Only where code runs and how you interact change (How Claude Code works).
Use the harness in your own code: the Agent SDK
The Agent SDK “gives you the same tools, agent loop, and context management that power Claude Code, programmable in Python and TypeScript”. It is a library that runs the Claude Code binary, with built-in tools, hooks, subagents, MCP, permissions, sessions, skills, commands, memory and plugins (Agent SDK overview). Anthropic’s announcement of the rename called it “the agent harness that powers Claude Code (the Claude Code SDK)” (Building agents with the Claude Agent SDK).
Install commands from the Agent SDK quickstart, which lists Node.js 18+ or Python 3.10+ as prerequisites:
TypeScript (existing project):
npm install @anthropic-ai/claude-agent-sdk
npm install --save-dev tsx
Python with uv:
uv init
uv add claude-agent-sdk
Python with pip on macOS or Linux:
python3 -m venv .venv
source .venv/bin/activate
pip install claude-agent-sdk
Both SDKs bundle a native Claude Code binary, so most installs need no separate Claude Code install (Agent SDK quickstart). The SDK reads ANTHROPIC_API_KEY from the environment and does not load .env files automatically:
export ANTHROPIC_API_KEY=your-api-key
Anthropic’s note on login: “Unless previously approved, Anthropic does not allow third party developers to offer claude.ai login or rate limits for their products, including agents built on the Claude Agent SDK” (Agent SDK overview).
The quickstart’s Python agent, which reviews utils.py and fixes crash bugs (Agent SDK quickstart):
import asyncio
from claude_agent_sdk import query, ClaudeAgentOptions, AssistantMessage, ResultMessage
async def main():
# Agentic loop: streams messages as Claude works
async for message in query(
prompt="Review utils.py for bugs that would cause crashes. Fix any issues you find.",
options=ClaudeAgentOptions(
allowed_tools=["Read", "Edit", "Glob"], # Auto-approve these tools
permission_mode="acceptEdits", # Auto-approve file edits
),
):
# Print human-readable output
if isinstance(message, AssistantMessage):
for block in message.content:
if hasattr(block, "text"):
print(block.text) # Claude's reasoning
elif hasattr(block, "name"):
print(f"Tool: {block.name}") # Tool being called
elif isinstance(message, ResultMessage):
print(f"Done: {message.subtype}") # Final result
asyncio.run(main())
permission_mode="acceptEdits" auto-approves file edits, and allowed_tools pre-approves only Read, Edit and Glob; the quickstart adds Bash or WebSearch to that list when the agent needs them (Agent SDK quickstart).
How the SDK loop runs
When an agent starts, the SDK runs “the same execution loop that powers Claude Code”: receive the prompt, evaluate and respond, execute tools, repeat, then return a result. Each full cycle is one turn, and the loop ends when Claude produces a response with no tool calls (How the agent loop works).
You can cap the loop with max_turns / maxTurns, which counts tool-use turns only, or with max_budget_usd / maxBudgetUsd for a spend threshold. The docs call a budget “a good default for production agents” (How the agent loop works).
From a language other than Python or TypeScript, the overview says to run the CLI as a subprocess with -p and --output-format json (Agent SDK overview). The example from Run Claude Code programmatically:
claude -p "Summarize this project" --output-format json
Other harnesses: Managed Agents and dynamic workflows
Anthropic’s comparison table lists two more options. Managed Agents is “a hosted agent harness that runs the agent loop”, with sessions in an Anthropic-managed cloud sandbox or a self-hosted sandbox; the Client SDK gives direct API access where you write the tool loop yourself (Agent SDK overview).
Inside Claude Code, dynamic workflows let Claude “write its own harness on the fly”. Anthropic’s post says the default harness “is built for coding” and that workflows run a JavaScript file that spawns and coordinates subagents with their own context windows. You can ask Claude to make one or use the trigger word ultracode. The post warns that dynamic workflows “often use more tokens and are best suited for complex, high value tasks” (A harness for every task).





