HomeClaude Code › CLI reference
OverviewInstallCLI referencePricing & limitsAgent SDKSkills & pluginsGitHubWeb, desktop & IDEModelsErrorsOpen source?TutorialFor studentsQA automation中文指南
Last updated: September 22, 2026

Claude Code CLI documentation: commands and flags

Claude Code has two surfaces: the interactive session you get from claude, and a non-interactive print mode for scripts and CI. This is the working reference for both.

TLDR

  • claude starts an interactive session in the current directory; claude -p "..." runs one prompt and exits.
  • Slash commands manage the session: /init, /compact, /clear, /model, /cost, /status, /permissions, /mcp, /agents.
  • --output-format json and --allowedTools make it scriptable; -c / -r resume sessions.

Launch

claude                          # interactive session
claude "fix the failing test"   # start with a prompt
claude -p "summarise this repo"  # print mode: answer, then exit
claude -c                       # continue the most recent session
claude -r                       # pick a session to resume
claude --model claude-opus-5    # choose the model for this session

Flags worth knowing

Slash commands inside a session

claude setup-token: long-lived auth for CI on a subscription

claude setup-token signs in once in a browser and prints a long-lived OAuth token for a Claude Pro/Max subscription, meant for headless environments where /login is impossible. Export it as CLAUDE_CODE_OAUTH_TOKEN in CI and print mode runs against the subscription's allowance. It is subscription-only; with an API key (Anthropic or gateway) the step is unnecessary — set ANTHROPIC_API_KEY instead.

Print mode for scripts and CI

cat error.log | claude -p "explain the root cause in three lines"

claude -p "write a changelog entry for the staged diff" \
  --allowedTools "Read,Bash(git diff *)" \
  --output-format json

Print mode is how the GitHub Action, editor integrations and the Agent SDK use Claude Code. With ANTHROPIC_BASE_URL set to the gateway, these runs bill against your gateway balance or unlimited plan rather than an Anthropic account.

Where configuration lives

Frequently asked questions

How do I run Claude Code without the interactive prompt?

Use print mode: claude -p "your prompt". Combine it with --allowedTools and --output-format json for scripts, and pipe files in on stdin.

What does /compact do?

It asks the model to summarise the conversation so far and replaces the history with that summary. Context shrinks, cost per turn drops, and the session can continue. Run it whenever a task changes direction.

Can I use Claude Code with a different API base URL?

Yes — set ANTHROPIC_BASE_URL. /status confirms which endpoint the session is using.

Run Claude Code on the gateway

Same models, two environment variables, credits at 7.69× face value — or a flat-rate unlimited plan.

Get an API key See unlimited plans

AI Prime Tech is an independent API gateway and is not affiliated with, endorsed by, or sponsored by Anthropic. “Claude” and “Claude Code” are trademarks of Anthropic. Claude Code features described here follow Anthropic’s public documentation at the time of writing and change frequently; prices and model lists on this page are read from this gateway’s live settings.

More Claude Code guides

Claude Code: the complete guideHow to install Claude CodeClaude Code pricing and limits, explainedThe Claude Code SDK, now the Claude Agent SDKClaude Code skills and pluginsClaude Code in GitHub: the App, the Action and @claudeDoes Claude Code have a web interface? Web, desktop and IDE explainedWhich model Claude Code uses, and how to change itClaude Code errors and how to fix themIs Claude Code open source?Claude Code tutorial: your first real sessionClaude Code for studentsHow to use Claude Code for QA automationClaude Code 怎么用:从安装到日常使用