claude_agent_sdk

Orchestrate Claude Code subprocesses with budget limits and session management.

1|Updated Mar 11, 2026
One-click install
npx skills add https://github.com/antonyfmunoz/OS --skill claude-agent-sdk-antonyfmunoz
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: claude_agent_sdk
Source: https://github.com/antonyfmunoz/OS/tree/main/skills/tools/claude_agent_sdk
Command: npx skills add https://github.com/antonyfmunoz/OS --skill claude-agent-sdk-antonyfmunoz

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This skill helps you reliably run and debug programmatic Claude Code (CC) workflows, including tool access, budgeting, streaming, and multi-turn session management, without losing valid output on non-zero exits.

Core Features & Use Cases

  • Claude Code subprocess orchestration: Runs the claude CLI as a child process in Python (via claude-agent-sdk) or directly (claude -p) for automation.
  • Budget + permission governance: Enforces --max-budget-usd and tool access modes (e.g., --allowedTools) to prevent runaway spending and unsafe tool use.
  • Session persistence + routing integration: Supports session resume via agent_id and integrates as a prioritized provider in a model router with escalation logic.
  • Production-grade operational guardrails: Handles nested-session recursion (skips CC SDK if already inside CLAUDE_CODE_SESSION), cleans orphaned subprocesses on timeout, and preserves streamed output even when the CLI exits with warnings.

Quick Start

Use the claude_agent_sdk wrapper to analyze a business situation with a tight max budget so the model router can fall back safely if CC SDK fails.

Frequently Asked Questions about claude_agent_sdk

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I automate Claude Code subprocess runs with budget limits and tool whitelists?

Claude Code subprocess orchestration enforces max-budget-usd and allowedTools whitelists during automated CLI runs. You invoke the claude subprocess programmatically to constrain spending and restrict tool access for heavy maintenance tasks.

Why does my Claude Code subprocess lose valid output when it exits with a non-zero code?

Claude Code subprocess streaming preserves valid output even on non-zero exit codes. The orchestration wrapper captures streamed data before the process terminates, ensuring partial results survive warnings or timeout failures.

Can I resume a multi-turn Claude Code session after a timeout without starting over?

Session persistence and resume support in Claude Code orchestration tracks agent_id to continue multi-turn sessions. It cleans orphaned subprocesses on timeout and routes subsequent requests to the existing session context.

How do I run scheduled Claude Code tasks with cron-style automation safely?

Scheduled cron-style Claude Code automation uses the claude -p command with tool whitelists and max-budget enforcement. This prevents runaway spending during unattended tool-driven maintenance tasks.

What happens if I call the Claude Agent SDK from inside an existing Claude Code session?

Nested-session recursion prevention skips the Claude Agent SDK if the process detects an active CLAUDE_CODE_SESSION environment. This guardrail stops recursive subprocess spawning and falls back safely.

Does Claude Code orchestration support streaming-to-completion constraints for long-running analysis?

Claude Code subprocess orchestration satisfies streaming-to-completion constraints by routing the claude CLI as a provider. It streams analysis and code generation output continuously until completion, even during fallback scenarios.