SnapshotJuly 2026a point-in-time write-up, left as written

Claude as a callable

Claude Code is not just a chat tool. It’s a CLI. That means you can call it from your own deterministic programs, treat it as a subroutine, and embed LLM judgment inside otherwise-traditional pipelines.

The CLI surface

At its simplest:

claude -p "summarize this log" < yesterday.log

Claude Code reads the prompt, optionally reads stdin, runs a one-shot session, and prints the result. No interactive REPL, no session state: just in, out.

Flags worth knowing (check the current docs for the full list):

Shell scripts

A shell script can invoke Claude anywhere you’d otherwise write a bespoke rule. Example: a nightly content audit.

#!/bin/bash
claude -p "Review content/ for broken links and stale references. Output a markdown summary." \
  --permission-mode auto \
  --allowed-tools Read,Grep,Glob,WebFetch \
  > audit-$(date +%F).md

Then cron or a systemd timer fires it on a schedule. Claude sees what you point it at, does the task, writes a file.

Structured output

For pipelines that consume Claude’s output programmatically, --output-format json returns structured results (exit status, token counts, final message content, tool-call sequences) instead of free-form prose.

Common patterns:

The prompt determines the schema. Claude follows it reliably if you’re explicit.

Exit codes, retries, and failure modes

A non-zero exit code from claude means the session didn’t complete successfully, usually a tool failure, auth issue, or timeout. Handle it like any other shell failure: retry, log, alert.

Common failure modes to plan for:

Treat Claude calls the way you’d treat any external service: not 100% reliable, worth retrying, always worth validating.

One-shot vs. full session

When to use a callable one-shot vs. an interactive session:

If you find yourself wanting to run a full session non-interactively, that’s usually a sign the task should be broken into smaller one-shots, or the prompt needs to be more complete upfront.

Common patterns

Real things people wire up with callable Claude:

The Claude Agent SDK

For deeper programmatic use, the Claude Agent SDK packages up the same harness that powers Claude Code and makes it available in Python and TypeScript. Anthropic also offers Managed Agents: server-hosted agents where Anthropic runs the loop and the sandbox. Use the SDK when you’re building a product that needs Claude-as-agent as a first-class component.

Resources