In this article
Print mode changes the interaction contract, while startup configuration, tools and completion behavior still require deliberate choices for unattended execution.
A shell script needs an operation that can finish without a person typing into a chat interface. Claude Code provides print mode for non-interactive calls. The headless documentation explains how this mode combines with output formats, continuation and configuration, revealing that replacing a human prompt with a command is only part of the automation design.
Choose a bounded scripted task
For a hypothetical repository-summary job, identify the input files and desired result before invoking claude -p. A bounded request is easier to consume than a general instruction to improve the project. The script should know whether it expects prose, a structured object or an artifact path. That contract determines the output format and how the application distinguishes success from a useful but incomplete explanation.
Understand normal startup discovery
The documentation states that ordinary print-mode calls discover configured skills, hooks, plugins and MCP setup rather than inherently starting with an empty environment. A developer’s machine and a clean runner can therefore differ. Inspect what the automation loads and which parts are necessary for the summary task. Do not assume that non-interactive means repository configuration cannot influence the run.
Use bare mode with its documented tradeoffs
Bare mode skips broad automatic discovery and is documented for reproducible scripted use. It also changes available behavior and authentication expectations, so it is not merely a faster spelling of the same command. Pass the required context and configuration explicitly. For the summary job, check that omitting project instructions does not remove a convention the output must follow before choosing this mode as the default wrapper.
Parse completion through the supported contract
The CLI documents exit status and JSON result fields for scripted consumers. Check both execution outcome and the artifact or structured field the task requires. Background work can affect when an ordinary print-mode process exits; bare mode has its own limits. A wrapper should not infer completion merely from the last line of visible prose or use a fixed delay instead of observing the actual process result.
Keep the script’s outcome honest
A completed summary, missing input and failed execution should produce distinguishable application outcomes. Keep the session reference when continuation is part of the workflow. If the source repository changed between calls, refresh the relevant observations. Print mode then provides a clear automation boundary: an application submits a specific task and consumes a verified result without treating every generated sentence as a successful side effect.
Documentation and further study
Related engineering guides: Reproducible inference stacks: preserving a GPU pilot’s result; Choose a local AI stack: desktop chat, shared UI or coding agent.
Earn rental income from GPUs
Have idle GPUs or looking to fund AI infrastructure? Retrivium finds a rental platform, sets up the server and helps you assess income and costs with a pilot.