Skip to the workspace
Pebellslearn by building
Claude Workflow  ›  Capstone Project

Starting Claude from the Shell

claude 15 minPlain claude opens a conversation, claude with a quoted query opens one with a first message, claude -p prints a single answer for scripts, and --add-dir widens the workspace.

claude code / Starting Claude from the Shell

Explore each scene at your own pace.

01 · The rule

The rule

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 claude to talk, add a query to start, -p to 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 folder
  • claude opens 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 -p is 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-dir adds 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.

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.