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
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 --helpRun 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.jsonValidate 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/nullVerify 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.
cat build.log | claude -p "Summarize the first actionable error and likely fix."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.
| Command | Description |
|---|---|
claude | Start 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 -c | Continue 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 --text | Check whether the current environment is authenticated. |
claude update | Update 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.
| Command | Description |
|---|---|
--permission-mode plan | Start in plan mode before edits are allowed. |
--add-dir ../apps | Grant read/write access to an additional directory. |
--allowedTools "Bash(git *)" | Auto-approve matching tool calls for CI or scripts. |
--model sonnet | Choose the model for the current session. |
--bare -p | Minimal 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.
Start with CLI
Use claude, -c, -r, and -p for entry, resume, and automation.
Read guideControl in-session
Use /plan, /memory, /code-review, and /doctor during active work.
Read guidePermissions flags
Pass --permission-mode and --allowedTools for CI and scripts.
Read guideBackground work
Detach long tasks with --bg and monitor via /tasks.
Read guideCLI usage checklist
Run from the right directory
Start Claude Code inside the repository or pass the intended working directory explicitly.
Read guideKeep command output visible
When using print mode or pipes, preserve the source output so later review can trace the result.
Read guideSeparate scripts from sessions
Use interactive sessions for exploratory coding and print mode for repeatable automation.
Read guideCheck auth before CI setup
Use auth status and setup-token flows before wiring Claude Code into scripts or GitHub Actions.
Read guide