Claude Code API: call Claude Code from your own code Anthropic's documentation now describes three ways to start Claude Code from a developer's own code: the claude -p (or --print) non-interactive CLI flag, the Agent SDK for Python and TypeScript, and an HTTP API trigger for cloud scheduled tasks, formerly called routines. The claude -p route exits with code 0 on success and a non-zero code on failure, and with --output-format json returns a total_cost_usd client-side cost estimate that Anthropic warns can differ from the actual bill; the docs recommend --bare for CI and scripts, which skips auto-discovery of hooks, skills, plugins, MCP servers and CLAUDE.md and requires an ANTHROPIC_API_KEY instead of a subscription login. The /fire endpoint at api.anthropic.com/v1/claude_code/routines//fire is available to claude.ai users only, ships under the experimental-cc-routine-2026-04-01 beta header while scheduled tasks are in research preview, and draws down subscription usage the same way interactive sessions do. Claude Code API: call Claude Code from your own code November 20, 2026 · 4 min read Anthropic’s docs describe three ways to start Claude Code from your own code: the claude -p command, the Agent SDK for Python and TypeScript, and the API trigger of a cloud scheduled task, formerly a routine. To call Claude models directly instead, the same docs point to the Client SDK for the Claude API. When you call Claude Code for the same job every day, there is a fourth option: have it write the job once as a Whenever workflow that runs on a webhook or a schedule, with no AI model call on a run unless you add an AI step. Run Claude Code from a script with claude -p Anthropic’s docs call this running Claude Code in non-interactive mode: add the -p or --print flag to any claude command, with your prompt and the CLI options you need. claude -p "What does the auth module do?" Claude Code exits with code 0 on success and a non-zero code when the run fails, so a script can branch on the exit status. With --output-format json, the response includes total cost usd, a client-side cost estimate that can differ from your actual bill. claude -p "Summarize this project" --output-format json | jq -r '.result' For CI and scripts, the docs recommend --bare: it skips auto-discovery of hooks, skills, plugins, MCP servers and CLAUDE.md, and it does not use your subscription login, so set ANTHROPIC API KEY with a key created in the Claude Console. Embed it with the Agent SDK The Agent SDK gives you the same tools, agent loop and context management that power Claude Code, as a Python or TypeScript library in a process you operate. From any other language, the docs say to run the CLI as a subprocess with the -p flag and --output-format json. A product you offer to other people authenticates with an API key: unless previously approved, Anthropic does not allow third-party developers to offer claude.ai login or rate limits for their products, including agents built on the Agent SDK. Start a cloud routine from an HTTP request A cloud scheduled task, formerly a routine, can have an API trigger: a dedicated endpoint you POST to with the task’s bearer token, which starts a new session and returns its URL. An optional text field passes run-specific context, such as an alert body, alongside the saved prompt. curl -X POST https://api.anthropic.com/v1/claude code/routines/