OCDevel Claude Code Podcast

Headless Claude Code: drive claude -p and the Agent SDK from your scripts

The Act II pivot from driving one Claude Code session by hand to calling it from a script: same agent, same loop, but you pre-decide what's allowed in code before the run ever starts. **The tutorial.** Print mode (`claude -p`) as a Unix citizen — piping stdin (and the 10MB cap), the `--bare` flag for deterministic CI runs, and structured output via `--output-format json` (the `result`, `session_id`, `total_cost_usd`, and `subtype` fields), `stream-json` with the `init` and `api_retry` events, and `--json-schema` for typed data instead of prose. The run-bounding flags — `--max-turns`, `--max-budget-usd`, `--model`/`--fallback-model`, `--allowedTools`/`--permission-mode` — and chaining turns with `--resume`/`--session-id`/`--fork-session`. Why a model refusal can't be caught from the exit code. Copyable patterns: a commit-message generator (and the space-before-`*` permission footgun), a stdin-fed typo linter that needs no Bash permission, and a locked-down CI run. Then the [Claude Agent SDK](https://claude.com/blog/building-agents-with-the-claude-agent-sdk) (renamed from the Claude Code SDK in September 2025): `query()` and the options that mirror the CLI flags, custom in-process tools, the Python `ClaudeSDKClient`, hooks and subagents in code, and the `can_use_tool` permission callback. Full reference in [the headless docs](https://code.claude.com/docs/en/headless) and the [migration guide](https://platform.claude.com/docs/en/agent-sdk/migration-guide). **The pitfalls.** `--dangerously-skip-permissions` in an unattended run — how to recognize the silent-success failure, and the least-privilege allowlist that replaces it — and the [June 15, 2026 billing change](https://support.claude.com/en/articles/15036540) that moves Agent SDK and `claude -p` usage to a separate metered credit pool, plus how to watch `total_cost_usd` and bound it. **News.** Claude Code 2.1.166 (June 6): a `fallbackModel` setting (up to three), thinking-off controls, a `"*"` deny-all glob, and a cross-session permission-escalation fix; latest is 2.1.167 ([changelog](https://code.claude.com/docs/en/changelog)). 2.1.163 added `additionalContext` from Stop hooks, `/plugin list`, and version-pinning settings. And Claude Opus 4.1 is deprecated, retiring on the API August 5, 2026 ([release notes](https://platform.claude.com/docs/en/release-notes/overview)). Earlier episodes referenced: CLAUDE.md and `--resume`, permissions and plan mode, custom slash commands and hooks, skills, subagents and the orchestrator pattern, MCP servers, cost and rate-limit engineering and evals, ultraplan/ultrareview, and parallel sessions with git worktrees.