﻿# Use Claude Code print mode for a bounded automation job

Use Claude Code print mode as a non-interactive workflow interface, accounting for output contracts, startup discovery and the lifecycle of background work.

Author: Retrivium editorial team
Updated: 2026-11-03
Canonical URL: https://retrivium.ai/journal/learn-claude-print-mode/
Language: en

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

- [Run Claude Code programmatically](https://code.claude.com/docs/en/headless).

- [How Claude Code works](https://code.claude.com/docs/en/how-claude-code-works).

- [Extend Claude Code](https://code.claude.com/docs/en/features-overview).

Related engineering guides: [Reproducible inference stacks: preserving a GPU pilot’s result](/journal/software-stack-reproducibility/); [Choose a local AI stack: desktop chat, shared UI or coding agent](/journal/local-ai-app-stack-selection/).
