Guides building hosted, long-running agents with Anthropic's Managed Agents API: creating versioned agents, environments, and event-driven sessions over SSE. Covers object model, tool policies, budgets, and when to choose over the Agent SDK.
Ships in agent-sdk. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Managed Agents is a hosted agent harness: you define an agent (model, system prompt, tools) once, start sessions against it in an environment, and exchange events. Anthropic runs the loop and the sandbox where tools execute.
| Object | Holds | Created |
|---|---|---|
| Agent | Model, system prompt, tools, MCP servers, skills; versioned | Once, then updated |
| Environment | Where sessions run (cloud sandbox or self-hosted) | Once per configuration |
| Session | One running agent instance and its history | Every run |
| Events | User messages, tool results, status updates | Continuously |
Model, system prompt, and tools live on the agent, never on the session. The session takes a pointer to an agent (and optionally a pinned version). All endpoints are beta and need the managed-agents-2026-04-01 header, which the official SDKs set automatically on client.beta.* calls.
import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic();
const MODEL = process.env.ANTHROPIC_MODEL!; // a current model ID
const environment = await client.beta.environments.create({
name: "dev-env",
config: { type: "cloud", networking: { type: "limited", allow_package_managers: true, allow_mcp_servers: true } },
});
const agent = await client.beta.agents.create({
name: "Code Reviewer",
model: MODEL,
system: "You are a senior code reviewer.",
tools: [{
type: "agent_toolset_20260401",
default_config: { enabled: true, permission_policy: { type: "auto" } },
configs: [{ name: "web_fetch", enabled: false }, { name: "web_search", enabled: false }],
}],
});
// Persist environment.id, agent.id and agent.version; do not create these per request.
To change behavior later, update the agent (client.beta.agents.update); each update creates a new version, and running sessions keep the version they started with. The Anthropic docs also describe keeping agents as version-controlled files synced with the ant CLI.
Open the stream before (or concurrently with) sending the first message; the stream only delivers events that occur after it opens.
const session = await client.beta.sessions.create({
agent: { type: "agent", id: AGENT_ID, version: AGENT_VERSION },
environment_id: ENVIRONMENT_ID,
title: "Review auth module",
});
const stream = await client.beta.sessions.events.stream(session.id);
await client.beta.sessions.events.send(session.id, {
events: [{ type: "user.message", content: [{ type: "text", text: "Review the auth module" }] }],
});
for await (const event of stream) {
if (event.type === "agent.message") {
for (const block of event.content) if (block.type === "text") process.stdout.write(block.text);
} else if (event.type === "session.status_idle") {
if (event.stop_reason.type !== "requires_action") break; // otherwise it is waiting on you
} else if (event.type === "session.status_terminated") {
break;
}
}
Session statuses are idle, running, rescheduling, and terminated. terminated means the session is over, either completed or failed; retrieve the session to tell which. Errors arrive as session.error events, not as a status.
ask pause the session. Reply with a user.tool_confirmation event (result: "allow" or "deny"). When nobody is watching, deny rather than allowing everythingtype: "custom") arrive as agent.custom_tool_use; reply with user.custom_tool_resultFor conversational sessions send user.message. For deliverables (a report, a PR, a fixed set of changes), the docs describe user.define_outcome with a rubric: a grader evaluates each iteration and the agent revises until it passes or hits max_iterations. Send one or the other as the kickoff, not both.
Sessions accept an optional budget at creation: { type: "limit", max_list_cost: { amount: "2500", currency: "USD" } }, where the amount is an integer string in cents. At the cap the session goes idle with stop_reason budget_reached; changing or removing the budget resumes it. A budget cannot be added after creation. List cost is priced at public list rates, which may differ from your contracted price; check the pricing page for what counts.
Available operations include sessions.retrieve, list, update (title, metadata, session-local tool overrides while idle, budget), archive, and delete. There is no session fork in Managed Agents. Delete sessions and uploaded files you no longer need, since transcripts persist until deleted.
| Managed Agents | Agent SDK | |
|---|---|---|
| Who runs the loop | Anthropic | Your process |
| Where tools execute | Per-session sandbox (cloud or self-hosted) | Your machine or container |
| Configuration | Versioned agent objects via API | Options per query() call |
| State | Server-side sessions and events | Local session transcripts |
requires_action pauses explicitly and deny by default when unattendedWhat SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
Other plugins' skills for the same job
/agent-sdk:managed-agents-apifrom agent-sdk
npx claudepluginhub latestaiagents/agent-skills --plugin agent-sdk5 skills in this plugin
/agent-sdk-quickstartBuild a first agent with the Claude Agent SDK (TypeScript or Python): install, run query(), read result messages, restrict tools and permissions, add custom tools through an in-process MCP server, and guard tool calls with hooks. Also explains when to pick the Agent SDK, the Client SDK, or Managed Agents.
Use this skill when starting a new agent project, migrating from a hand-written messages.create tool loop, or choosing between the Agent SDK, the Client SDK, and Managed Agents.
Activate when: Claude Agent SDK, @anthropic-ai/claude-agent-sdk, claude-agent-sdk, query(), ClaudeAgentOptions, createSdkMcpServer, build agent, agent SDK quickstart.
/agent-sdk-streamingStream Claude Agent SDK output to a UI: the default message flow, enabling partial messages with includePartialMessages / include_partial_messages, handling stream_event deltas for text and tool input, attributing subagent output, and handling cut-off streams.
Use this skill when building a chat or progress UI on top of the Agent SDK, showing tool activity live, or debugging missing or out-of-order streamed output.
Activate when: agent SDK streaming, includePartialMessages, include_partial_messages, stream_event, StreamEvent, SDKPartialAssistantMessage, text_delta, input_json_delta, real-time agent output.
/session-lifecycleManage agent sessions correctly in both the Claude Agent SDK (local transcripts with continue, resume, and forkSession) and Claude Managed Agents (server-side sessions with idle, running, rescheduling, and terminated states). Covers capturing session IDs, resuming across processes and hosts, forking to explore alternatives, when to start fresh, and retention.
Use this skill when building multi-turn agents, debugging "my agent forgot the earlier context", choosing between continue, resume, fork, or a new session, or designing session retention.
Activate when: agent session, session resume, continue conversation, forkSession, fork_session, session ID, ClaudeSDKClient, Managed Agents session status, session retention.
/sub-agent-delegationDelegate work to subagents in the Claude Agent SDK: define them with the agents option (AgentDefinition), restrict their tools, pass the right context in the Agent tool prompt, detect subagent messages, resume subagents, and cap depth, concurrency, and spend.
Use this skill when parallelizing research or review across subagents, keeping the main context small, giving a subtask specialized instructions or read-only tools, or debugging why Claude does not delegate.
Activate when: subagent, sub-agent, agents option, AgentDefinition, Agent tool, Task tool, parallel agents, delegate to agent, parent_tool_use_id, CLAUDE_CODE_MAX_CONCURRENT_SUBAGENTS.
2 plugins in one repository ship this exact skill · first indexed Nov 5, 2026