
Security News
The Next Open Source Security Race: Triage at Machine Speed
Claude Opus 4.6 has uncovered more than 500 open source vulnerabilities, raising new considerations for disclosure, triage, and patching at scale.
@ag-kit/examples-claude-agent-human-in-the-loop
Advanced tools
This example demonstrates how to implement human-in-the-loop (HITL) workflows with Claude Agent SDK.
When a user asks Claude to perform a task, the agent:
plan_execution_steps tool to generate 10 imperative stepsUser: "Help me bake a cake"
↓
Claude: Calls plan_execution_steps
↓
Tool: Returns { __interrupt__: true, steps: [...] }
↓
Agent: Detects __interrupt__, emits RUN_FINISHED (interrupt)
↓
Frontend: Shows steps UI (enable/disable checkboxes)
↓
User: Disables "Add frosting", clicks Continue
↓
Frontend: Sends resume({ steps: [...modified...] })
↓
Agent: Uses session ID to resume
↓
Claude: Generates creative response based on enabled steps
__interrupt__ marker__interrupt__: trueANTHROPIC_API_KEY=your-api-key
CLAUDE_MODEL=claude-3-5-sonnet-20241022 # optional
# Install dependencies
pnpm install
# Build
pnpm run build
# Run the server (from examples/agents/server)
cd ../server
pnpm run dev
http://localhost:5173/?agent=ts-claude-agent-human-in-the-loopconst planExecutionStepsTool = tool(
"plan_execution_steps",
"Generate 10 imperative steps for a task",
{ steps: z.array(z.object({ description: z.string(), status: z.literal("enabled") })) },
async (args) => {
// Return __interrupt__ marker
return {
content: [{
type: "text",
text: JSON.stringify({
__interrupt__: true,
reason: "Task planning requires user confirmation",
steps: args.steps,
})
}],
isError: false,
};
}
);
const agent = new ClaudeAgent({
name: "claude-hitl-agent",
mcpServers: { hitl: createSdkMcpServer({ tools: [planExecutionStepsTool] }) },
systemPrompt: "When user asks to perform a task, MUST call plan_execution_steps...",
includePartialMessages: true,
});
private detectInterrupt(sdkMessage: SDKMessage) {
if (sdkMessage.type === "assistant") {
for (const content of message.content) {
if (content.type === "text") {
const parsed = JSON.parse(content.text);
if (parsed.__interrupt__) {
return { id, reason, payload: parsed };
}
}
}
}
return null;
}
private async _resume(subscriber, input) {
const sessionId = this.sessionStore.get(threadId);
const resumePrompt = this.buildResumePrompt(payload);
const agentQuery = query({
prompt: resumePrompt,
options: { resume: sessionId } // SDK auto-loads history
});
// Continue processing...
}
To add a new HITL scenario (e.g., payment approval):
const approvePaymentTool = tool(
"approve_payment",
"Request approval for a payment",
{ amount: z.number(), recipient: z.string() },
async (args) => {
return {
content: [{
type: "text",
text: JSON.stringify({
__interrupt__: true,
type: "approve_payment",
amount: args.amount,
recipient: args.recipient,
})
}],
isError: false,
};
}
);
No changes needed to ClaudeAgent! It automatically detects any __interrupt__ marker.
FAQs
Claude Agent SDK human-in-the-loop example
We found that @ag-kit/examples-claude-agent-human-in-the-loop demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Claude Opus 4.6 has uncovered more than 500 open source vulnerabilities, raising new considerations for disclosure, triage, and patching at scale.

Research
/Security News
Malicious dYdX client packages were published to npm and PyPI after a maintainer compromise, enabling wallet credential theft and remote code execution.

Security News
gem.coop is testing registry-level dependency cooldowns to limit exposure during the brief window when malicious gems are most likely to spread.