Use claude -p for One-Shot Tasks Without Entering an Interactive Session
Sometimes you don't need a full interactive session — you just want a quick answer or a single operation. The -p flag (short for --print) runs Claude Code in non-interactive mode: it processes your prompt, prints the result, and exits.
# Ask a quick question without entering interactive mode
claude -p "what does the --frozen flag do in composer install?"
# Generate a one-liner and pipe it elsewhere
claude -p "write a bash one-liner that finds all TODO comments in .php files" | pbcopy
# Summarize a file without opening a session
claude -p "summarize what this file does" < src/Services/PaymentGateway.php
The real power is how -p composes with standard Unix tools. You can pipe input into Claude, pipe output out of Claude, or both — making it a building block in shell pipelines.
# Pipe git diff into Claude for a quick explanation
git diff HEAD~1 | claude -p "explain what changed in this diff"
# Generate a commit message from staged changes
git diff --cached | claude -p "write a concise commit message for these changes"
# Process a file and save the result
claude -p "convert this CSV to a markdown table" < data.csv > table.md
You can combine -p with other flags like --model to pick a specific model, or --output-format json to get structured output for scripts that need to parse Claude's response programmatically.
# Use a faster model for simple questions
claude -p --model haiku "what's the default port for PostgreSQL?"
Think of claude -p as the curl of AI — a single command that fits anywhere in your existing shell workflows.
via Claude Code
Log in to leave a comment.
When typing feels slow — describing a complex bug, explaining architecture, or thinking through a problem out loud — press Option+V to switch to voice input. Speak naturally and Claude Code transcribes your words into a prompt, so you can describe what you need at the speed of thought.
When Claude is heading down the wrong path — editing the wrong file, writing code you don't want, or giving a long explanation you don't need — press Escape to stop it immediately. You keep everything it did up to that point and can redirect with a new prompt.
Closed a session and realized you weren't done? Pass --continue (or -c) when launching Claude Code to pick up exactly where you left off — same context, same files, same conversation history — without re-explaining what you were working on.