Non-interactive mode is a bounded step
Non-interactive mode is useful for a single invocation from a shell script, local automation, or CI. Instead of a long exploratory session, define an explicit input, one narrow goal, and an output that can be saved and checked.
This mode fits a summary, log classification, release-note draft, or short diff analysis. It does not make Claude an unconditional approver: merge, release, and production deployment remain human and policy decisions.
claude --help
# Example: pass a narrow diff and save the result
claude -p "Write a short code-review summary" \
--allowed-tools "Bash(git diff:*)" \
> tmp/summary.mdInput and output contract
Structured output helps downstream processing, but valid JSON does not make a conclusion correct automatically. Compare it with the original diff or log.
| Part | Practice |
|---|---|
| Input | Pass a diff, log file, changelog, or another explicitly bounded data set |
| Goal | Describe one operation: summary, classification, or risk list |
| Output | Require Markdown or JSON with fixed fields |
| Check | Confirm that the result is non-empty and matches the expected shape |
| Evidence | Save the source, command, limits, and produced file |
Narrow delegation instead of full access
- Do not pass the whole repository when a diff or log is enough.
- Do not grant broad editing to a scripted run without a specific need.
- Do not put secrets in prompts, stdin, or saved artifacts.
- Do not permit commits, pushes, or destructive commands in the first version.
- Name the exact file or command that is the input.
- Describe what Claude must return and what it must not do.
- Grant only the minimum tools and permissions.
- Save the result in a temporary or dedicated evidence file.
- Perform human review before any external action.
Example: analyze a build log
Name the format and forbid editing in the prompt. If a pipeline needs machine parsing, add JSON-schema validation and treat invalid output as a failure rather than an empty success.
cat build.log | claude -p \
"Return JSON: category, cause, evidence, check, next_action" \
> tmp/failure.json
# A script or person checks the file next,
# not an automatic merge step.When to use an interactive session
| Scenario | Better mode |
|---|---|
| Short repeated summary or classification | Non-interactive |
| Analysis of one build log | Non-interactive |
| Exploration of an unfamiliar codebase | Interactive session |
| Root-cause investigation across components | Interactive session |
| Unclear requirements and clarification | Interactive session |
Canonical lesson source · JavaRush
Open JavaRush material