Video: Routines and Headless
1. Video: Routines and Headless
Once you trust Claude to do a task, the next move is to stop doing it by hand. The most direct way needs no script or a server. A routine. Which is a saved prompt plus repositories and connectors that runs on Anthrobic's managed infrastructure whenever it's triggered. When you need full control instead, headless mode and the Agent SDK run Claude Code from your own scripts and applications. Start with a path where you build nothing. A routine bundles a prompt, the repository it works on and any connectors it needs, then runs that bundle in the cloud on a trigger. A cron schedule, an HTTP post to its API endpoint, or a GitHub event like a new pull request. The infrastructure is Anthrobic, so there's no machine of yours staying on overnight and no workflow file to maintain. You create one from the web at claude.ai, slash code, slash routines, or from inside You can run. Slash schedule, daily dependency audit at 9am. A morning dependency audit or a PR triager that fires when a new pull request lands. Anything that's the same prompt on a recurring trigger fits. Three things to know before you rely on it though. Routines are a research preview, so behavior and limits will just keep on moving. A recurring schedule runs at most hourly, and each run starts from a fresh clone of your default branch and can only push to Claude slash prefix branches unless you loosen that which is the guardrail that keeps an autonomous run from rewriting main. When the job needs your environment or logic around that run, drop to headless mode. The -p flag, alias print, runs Claude Code as a one-shot command with no interactive tui. It reads standard in and writes standard out, so it pipes like any other shell tool. Bayer skips auto discovery of hooks, skills, plugins, mcp servers, and the CLAUDE.md file. You get Claude, plus the tools that you allow explicitly, and nothing the local environment happens to load. Startup is much faster this way. Now you can pair the JSON schema with output format JSON and Claude constrains the structure output to match your schema. The schema matching object lands in the structured output field of the JSON response. So you can pull it with a jq command and pipe it into a database or another script. For multi-step automation, capture the session's id from a JSON output and resume. One script kicks off the work, another resumes it later with full context. The agent SDK gets you a library that embeds Claude Code inside of your own TypeScript or Python applications. Both expose a query function and the same primitives as the CLI. You pass a prompt, plus options like allow tools, a system prompt, and a permission mode, and iterate the messages that Claude streams back. Routines are the default for repeat work. It runs on Anthropic's infrastructure and nothing for you to host. Drop to headless when the job needs your pipeline. Dash p to pipe data through a script. Bare when CI needs the same results every single run and the agent SDK when the work belongs inside of your own product.2. Let's practice!
Create Your Free Account
or
By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.