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.