Automation
Claude Agent SDK and Non-Interactive Automation
The Agent SDK is for teams that want Claude Code capabilities inside a controlled program, not just inside a terminal conversation.
Quick Answer
Use `claude -p` for simple one-off automation and the Agent SDK when you need programmatic control over tools, permissions, sessions, hooks, MCP, structured output, or custom orchestration.
For: Platform engineers and developers building repeatable Claude Code automation.
Key facts
What this page establishes
- Use `claude -p` for simple one-off automation and the Agent SDK when you need programmatic control over tools, permissions, sessions, hooks, MCP, structured output, or custom orchestration.
- Audience: Platform engineers and developers building repeatable Claude Code automation.
- Primary-source base: Claude Agent SDK overview, CLI reference, Extend Claude Code.
Pick the smallest automation surface
Not every automation needs an SDK. If you need a quick summary or a scriptable answer, the CLI non-interactive mode may be enough. If you need tool restrictions, session management, hooks, MCP, structured outputs, or custom orchestration, reach for the SDK.
The smaller surface is easier to secure and debug. Move up only when the workflow needs more control than the simpler interface can provide.
Primary-source anchor: the Agent SDK overview lists built-in tools, hooks, subagents, MCP, permissions, and sessions as SDK-accessible capabilities.
Use non-interactive CLI mode for simple jobs
The CLI can answer a prompt and exit, process piped input, continue a session, and return output formats useful in scripts. This is ideal for summaries, generated notes, triage drafts, or low-risk checks that do not need custom state.
Keep prompt inputs deterministic. For repeatable jobs, feed files or logs through stdin and ask for a constrained output format rather than relying on ambient terminal context.
claude -p "Summarize this repository in five bullets"
cat test-output.log | claude -p "Identify the failing test and likely source file"
claude -c -p "Continue the previous investigation and list unresolved risks" Primary-source anchor: the CLI reference documents interactive prompts, `-p` queries, piped input, resumes, auth, MCP, agents, and other automation commands.
Use the SDK when Claude is part of an application
The SDK is the right level when Claude is one actor in a larger system: a review bot, an internal maintenance agent, a migration assistant, or a controlled workflow runner.
Programmatic agents need the same discipline as other services. Define allowed tools, constrain filesystem access, set permission behavior, log outcomes, and make human review explicit where risk is high.
- Define the prompt contract and expected output schema.
- Restrict tools to the workflow need.
- Decide whether filesystem settings should load.
- Log tool calls and final outcomes where auditability matters.
- Design retry and failure behavior before production use.
Prefer structured outputs for downstream automation
If another program consumes Claude output, free-form prose is a liability. Ask for JSON or another validated structure and fail closed when the output does not match.
Structured output is especially useful for issue triage, code review findings, release-note drafts, test-failure classification, and routing decisions.
{
"summary": "One sentence",
"findings": [
{ "severity": "high", "file": "src/auth.ts", "line": 42, "issue": "Why it matters" }
],
"checksRun": ["npm test -- auth"],
"needsHumanReview": true
} Do not hide agentic behavior from users
When Claude Code capabilities become part of a product or internal tool, make the boundary visible. Users should know what the agent can read, what it can change, what checks it runs, and who approves the result.
A reliable automation is not one that never fails. It is one that fails with enough evidence for a human or another system to recover safely.
Primary Sources
These are the source pages used for factual claims on this article.
Anthropic
Claude Agent SDK overview
Programmatic access to tools, hooks, subagents, MCP, permissions, and sessions.Anthropic
CLI reference
Command shapes for interactive, non-interactive, auth, MCP, agents, and CI workflows.Anthropic
Extend Claude Code
Decision map for CLAUDE.md, skills, code intelligence, MCP, subagents, hooks, agent teams, and plugins.Anthropic
Claude Code GitHub Actions
GitHub Actions setup, @claude workflow, repository permissions, and CI considerations.Cite This Page
Claude Ships Code. "Claude Agent SDK and Non-Interactive Automation." Updated 2026-07-06. https://claudeshipscode-com.pages.dev/agent-sdk-automation
Claude Ships Code. "Claude Agent SDK and Non-Interactive Automation." Updated 2026-07-06. https://claudeshipscode-com.pages.dev/agent-sdk-automation FAQ
When should I use the Agent SDK instead of the CLI?
Use the SDK when you need programmatic control over tools, permissions, sessions, MCP, hooks, structured outputs, or custom orchestration.
Can I use Claude Code in CI without the SDK?
Yes. The official GitHub Action and non-interactive CLI patterns cover many CI cases before a custom SDK integration is needed.