Summary
Once a Claude Code workflow is proven interactively, the logical next step is removing the human from the loop. This official Anthropic tutorial covers three distinct paths for doing that: Routines, headless mode via the `-p` flag, and the Agent SDK.
Routines are a new managed offering — currently in research preview — that bundle a prompt, repository, and connectors into a cloud-hosted unit triggered by cron schedule, HTTP POST, or GitHub events like new pull requests. No server required, but runs are capped at once per hour, start from a fresh clone of the default branch, and can only push to `claude/`-prefixed branches unless repo-level guardrails are loosened. Headless mode via `-p` turns Claude Code into a one-shot stdin/stdout tool that pipes like any shell command. Pairing it with `–output-format json` and a JSON schema constrains output to a predictable structure pipeable into databases or downstream scripts. The `–bare` flag strips autodiscovery of hooks, MCP servers, and CLAUDE.md for fully deterministic CI runs. The Agent SDK exposes the same primitives through a `query` function in TypeScript or Python, accepting options for allowed tools, system prompts, and permission modes, then streaming back the message sequence Claude produces.
A practical multi-step pattern covered: capture a session ID from one headless run and pass it to a second script to resume with full context, enabling pipelines that hand off work across invocations without losing state.
📺 Source: Claude · Published September 03, 2026
🏷️ Format: Tutorial Demo







