Claude Code CLI commands

The Claude Code CLI is useful because it can be interactive, scriptable, and composable with shell pipelines. Treat commands as workflow building blocks rather than one-off prompts.

Last verified
Applies to
Claude Code 2.1.x. CLI spellings were checked on local version 2.1.198; current official docs may describe newer 2.1.x behavior.
Verification method
Official documentation, CLI reference, and changelog reviewed on 2026-07-19. Top-level, auth, and MCP help output were checked locally. The example print request consumes account/API usage and was not executed for this audit.
Official sources
CLI referenceChangelog

Reproducible practice

Turn a one-off repository inventory into machine-checkable output

Use print mode for a bounded read-only question, cap tool access, preserve the response, and validate its transport format.

Prerequisites

  • A trusted repository and valid authentication.
  • jq or another JSON parser available locally.
  • An understanding that print mode can incur usage and skips the interactive workspace trust dialog.

Steps

  1. Confirm the flags on the installed version

    Help output is the local source of truth for spelling and accepted values.

    Step 1
    claude --version
    claude --help
  2. Run a read-only inventory

    The prompt asks for evidence, while tools and plan mode constrain the execution surface.

    Step 2
    claude -p "List build and test commands with the file that defines each one." \
      --permission-mode plan \
      --allowedTools "Read" "Grep" "Bash(git status --short)" \
      --output-format json > /tmp/claude-inventory.json
  3. Validate the envelope

    A parseable response proves the CLI transport, not the factual accuracy of every model statement.

    Step 3
    jq -e . /tmp/claude-inventory.json >/dev/null
  4. Verify cited commands in repository files

    Open the cited package, build, or CI files and compare command spellings before using the inventory.

Expected result

The command exits, writes valid JSON, and produces a source-linked inventory that can be checked against repository files.

Validation

  • Require a zero exit status and valid JSON.
  • Verify each reported command against its cited file.
  • Do not treat model prose as proof that a command succeeded.

Failure handling

Permission prompt or denial

Narrow or correct the allowed tool pattern; do not jump to bypassPermissions.

Invalid or empty JSON

Check exit status, stderr, authentication, and whether output-format is supported by the installed version.

Cleanup or rollback

  • Delete the temporary JSON after review.
  • If the command touched files unexpectedly, stop and inspect git status before any cleanup.

Boundaries and when not to use it

  • Print mode is suitable for bounded automation, not interactive clarification-heavy work.
  • Allowed tools auto-approve matching tools; use --tools when the goal is to remove other tools from availability.

Interactive and one-shot usage

Use `claude` to start an interactive session in the current project. Use an initial query when you already know the task. Use print mode when the result should be consumed by another command, script, or automation.

Continue and resume

Long-running work benefits from session continuity. Continuing the most recent session keeps context available; resuming by identifier helps when you maintain several threads for bug fixes, refactors, reviews, or research.

Authentication and status checks

Authentication commands help confirm whether the current environment can use Claude Code before a task begins. For teams, this is useful in onboarding docs and troubleshooting checklists.

Pipes and automation

Shell pipelines can feed logs, diffs, file lists, or command output into Claude Code. This pattern is useful for summarizing failures, triaging changed files, or creating a first-pass explanation before a human review.

Pipe logs into Claude Code
cat build.log | claude -p "Summarize the first actionable error and likely fix."
Continue a session from print mode
claude -c -p "Check for type errors in the files changed on this branch."

Common CLI commands

These commands cover daily development: starting sessions, resuming work, checking auth, updating the CLI, and running background agents.

CommandDescription
claudeStart an interactive session in the current directory.
claude "query"Start interactive mode with an initial prompt.
claude -p "query"Run a one-shot query and exit, useful for scripts.
claude -cContinue the most recent conversation in this directory.
claude -r "name" "query"Resume a named or ID-based session with a new prompt.
claude auth status --textCheck whether the current environment is authenticated.
claude updateUpdate Claude Code to the latest version.
claude --bg "task"Start a background session and free the terminal.

Useful flags for automation

Flags let you tune permissions, models, working directories, and output behavior without changing project files.

CommandDescription
--permission-mode planStart in plan mode before edits are allowed.
--add-dir ../appsGrant read/write access to an additional directory.
--allowedTools "Bash(git *)"Auto-approve matching tool calls for CI or scripts.
--model sonnetChoose the model for the current session.
--bare -pMinimal scripted mode without auto-loaded skills or MCP.

CLI vs slash commands

CLI flags start and script sessions; slash commands control a session that is already running. Most daily work uses both layers together.

CLI usage checklist

Related topics