claude-code·Published 2026.06.01·Views 1
claude -p: The Core of Automation, Answers Without a Chat (print)
claude -p isn't for human chatting; it's for scripts that call Claude like a component. The print option that outputs only the answer and exits, explained
If you've used Claude Code like a chat so far, this command is a slightly different world. It's not a person conversing directly—it's a way for another program or script to call Claude like a "component." It's the starting point when you want to automate repetitive analysis tasks.
Definition (What It Is)
claude -p "question" is a command that gets only the answer and exits, without opening a chat window (-p = print). Instead of a chat window opening so you can keep chatting as usual, it prints the answer to your task to the screen once and ends right away. It's not for a person to converse with, but for a script (a small program that runs multiple commands automatically) to call Claude and take just the result.
How to Use It (By Difficulty)
Before you start: Since -p spits out the answer as text once and ends, it especially shines "when you want to take the result and use it elsewhere." The commands below also answer based on the files in your work folder if you run them after moving (cd folder-path) into it.
Basic — Get a one-line answer
claude -p "이 함수 하는 일 한 문장으로"
It prints the answer to your question once and ends right away. Since no chat window opens waiting for input, it's clean for when you "just want to quickly ask this one thing."
Applied — Pipe in a file to analyze
cat error.log | claude -p "에러 원인 설명"
This uses cat (a command that prints a file's contents to the screen) to pull out the log file's contents, then pipes it (|, the symbol connecting the preceding command's output to the next one) to Claude to analyze. The whole thing is handed over without copy-pasting the file.
Advanced — Get the result as JSON for automation
git diff | claude -p "커밋 메시지 써줘" --output-format json
This pipes in git diff (viewing uncommitted changes) to make a commit message, but with --output-format json it receives the result in JSON format (a structured data form that's good for programs to exchange). Received this way, another tool can read the result directly and pass it on to the next task.
Common Pitfalls
Since -p is for automation, it's usually used alongside permission options or output-format options (such as --output-format). Also, since no chat window opens, don't panic thinking "why can't I type in the chat?" That's the normal behavior. If you want to converse directly as a person, just use claude without -p.
Real-World Example
There's a case where someone put a script on a schedule (cron, a tool that runs commands automatically at set times) that pipes the server log via cat to claude -p to summarize it every night, then automatically emails that summary. Without anyone lifting a finger, a tidy log summary arrives in the inbox every day.
More Ways to Use It
- Since you can get the answer as text, you can fully automate repetitive analysis tasks.
- Received as JSON, another program can read and process the result directly, which is great for chaining tools together.
- If you want to continue the past conversation's context and get just the answer, use it together with
-c, likeclaude -c -p "...".
Wrap-Up
claude -p isn't a "mode for a person to chat" but a "mode for a program to call Claude and take just the answer." Since you can get the answer as text or JSON, weaving it together with pipes and scheduled execution lets you fully automate repetitive work. It's the most important option for getting started with automation.
Reference: Claude Code v2.1.154 (2026.05)
Comments
Comments 0
Checking sign-in status…
Loading comments…