Claude Code In Action
← All lessons
Lesson 106Claude Code In Action

Routines and headless

Summary audio

No audio recap for this lesson.

Study notes

Routines (Managed Infrastructure)

  • Saved prompt + repositories + connectors that run on Anthropix managed infrastructure
  • Triggered by: cron schedule, HTTP POST to API endpoint, or GitHub events (e. g. , new pull requests)
  • No need to maintain machines or workflow files
  • Created via web interface or /schedule command in Cloud Code
  • Limitations: Research preview with evolving behavior; recurring schedules run at most hourly; fresh clone from default branch each run; can only push to cloud/ prefix branches by default

Headless Mode (Full Control)

  • Run Cloud Code from your own scripts and applications
  • Use -P flag for one-shot command execution with no interactive UI
  • Reads from stdin, writes to stdout—pipes like standard shell tools
  • Skips auto-discovery of hooks, skills, plugins, MCP servers, and cloud MD file
  • Faster startup; only loads explicitly allowed tools
  • Useful when job needs your environment or custom logic

Structured Output

  • Pair JSON schema with output format JSON to constrain output structure
  • Schema-matched object lands in structured output field of JSON response
  • Extract with jq command and pipe to database or another script

Multi-Step Automation

  • Capture session ID from JSON output to resume later
  • One script kicks off work; another resumes with full context

Agent SDK

  • Library that embeds Cloud Code in TypeScript or Python applications
  • Exposes query function and same primitives as schema
  • Pass prompt + options (allow tools, system prompt, permission mode)
  • Iterate over streamed messages from Cloud

When to Use Each

  • Routines: Repeat work on managed infrastructure
  • Headless (-P): Pipe data through scripts
  • Headless (--bear): CI needs consistent results per run
  • Agent SDK: Embed work inside your own product

Takeaways

  • Routines run on managed infrastructure triggered by schedules, webhooks, or GitHub events—no machine maintenance needed, but limited to hourly recurrence and cloud/ prefix branches
  • Headless mode (-P flag) lets you pipe Cloud Code through scripts like standard shell tools, skipping auto-discovery for faster startup and custom environment control
  • Structured output uses JSON schemas to constrain responses into a structured output field that you can extract with jq and pipe to databases or other tools
  • Multi-step automation captures session IDs to resume work later, enabling one script to kick off a job and another to continue with full context
  • Agent SDK embeds Cloud Code in TypeScript or Python applications via a query function, giving you programmatic control over prompts, tools, and permissions
Flashcards 10 cards
Question
click to reveal · ←/→
Answer
click to flip back
Export to Anki (.tsv) ↓
Knowledge check 6 questions