Starting Claude from the Shell
How you launch Claude Code decides what kind of session you get: a conversation, a conversation with a head start, or a single answer that a script can use. A few small variations on one command cover all three.
The rule
Plain
claudeto talk, add a query to start,-pto print and exit.
claude # interactive session in this folder
claude "why does test_weekly_plan fail?" # interactive, first prompt already sent
claude -p "summarise what orders.py does" # print one answer, then exit
git diff --staged | claude -p "write a one-line commit message for this diff"
claude --add-dir ../tiffin-shared # also work in a second folderclaudeopens the familiar interactive session.claude "query"does the same but sends your first message straight away, which is handy when you already know the question.claude -pis print mode, often called headless mode. One prompt in, one answer out, then it exits. Because it writes to standard output and can read from a pipe, it fits into shell scripts, git hooks and scheduled jobs. Nobody is there to answer a permission prompt, so any tool that needs approval must be allowed in advance, or the call is refused.--add-diradds another folder to the session's workspace, such as a shared library that sits beside the project. Add only what the task needs.
claude --help lists the other options, such as choosing a model or a permission mode at launch. Print mode can also return structured output, such as JSON, for a program to parse.
One shell detail trips people up: put the query in double quotes so the shell passes it as a single argument. An unquoted apostrophe, as in don't, starts a quoted string of its own, and the shell will sit waiting for you to close it.
The shortcut
Ask "Will I reply?" If there will be back-and-forth, use claude, with a quoted query if you already know your opening question. If the answer goes into a file, a pipe or a script, use -p.
Morning investigation
claude "last night's job logged three failed payments; find out why". You will want to follow up, so it is interactive, with a head start.
The trap is a scripted -p run with broad permissions. Nobody is watching to approve or stop it, so give unattended runs the narrowest permissions that still do the job.
Drills
Answer fast — trust the rule.
Which command opens an interactive session with your first question already sent?
Which command prints a single answer and exits, ready to use in a pipe?
You pipe the staged diff into claude -p "write a commit message". What does Claude receive?
The date helpers live in ../tiffin-shared. How do you let the session work there too?
Remember
claudeto talk,claude "query"to start with a question,claude -pto print and exit.- Shortcut: will I reply? If not, use
-p. - Trap: unattended
-pruns with more permissions than they need.
