Claude Code: CLI Reference Manual

Last updated: 2026-08-31

This is Claude Code's command quick-reference — every command, parameter, and slash command for daily use.

💡 Tip: No need to memorize everything. Daily use only requires claude, claude "instruction", and a few common slash commands; the rest can be looked up.

📋 Prerequisites: Chapter 18 - Hooks System

1. What You'll Learn


2. CLI Launch Parameters

(1) Basic Usage

BASH
claude                           # Interactive mode
claude "your instruction"        # With instruction
echo "instruction" | claude      # Pipeline mode
claude -p "quick query"          # Print mode

(2) Complete Parameter List

Parameter Description Example
-p, --print Non-interactive mode claude -p "query"
--model Specify model --model claude-opus-4-20250514
--resume Resume last session claude --resume
--headless No UI mode claude --headless "task"
--output Output format --output json
--style Output style --style concise
--allowed-tools Limit tools --allowed-tools Read,Write
--allow-full-auto Full auto mode --allow-full-auto
--mcp-config MCP config file --mcp-config ./mcp.json
--no-hooks Disable hooks --no-hooks
--sandbox Sandbox mode --sandbox
--version Show version claude --version
--help Show help claude --help

3. Slash Commands

(1) Session Control

Command Description
/help Show help
/clear Clear conversation history
/compact Compress conversation history
/cost View Token usage and cost
/exit Exit Claude Code

(2) File and Project

Command Description
/init Initialize project, generate CLAUDE.md
/files View loaded files
/diff View current session file changes
/search <pattern> Search pattern in project

(3) Configuration and Tools

Command Description
/model <name> Switch model
/style <name> Switch output style
/mcp View MCP server status
/hooks View hook configuration
/skills List available Skills
/skill <name> Execute specified Skill
/config View current configuration

(4) Git Integration

Command Description
/commit Commit current changes
/undo Undo last operation

▶ Example 1: Slash Command Usage

TEXT 📖 Display only
> /cost
Token usage: 45,230 / 200,000 (22.6%)
Session cost: $0.91

> /files
Loaded: src/index.ts, src/routes/user.ts, src/services/user.service.ts

> /model claude-opus-4-20250514
Model switched to claude-opus-4-20250514

> /diff
Modified: src/routes/user.ts (+12 -3), src/services/user.service.ts (+28 -0)

4. Control and Modes

(1) Interactive Controls

Operation Key Description
Send instruction Enter Send current input
New line Shift+Enter Multi-line input
Interrupt Ctrl+C Stop current operation
Exit Ctrl+D Exit Claude Code
History ↑/↓ Browse history

(2) Permission Confirmation Options

Option Description
y Yes (this time)
n No
a Always (this session)
e Edit before applying

5. Configuration File Locations

File Location Purpose
~/.claude/CLAUDE.md Global Personal preferences
~/.claude/settings.json Global Global settings
~/.claude/hooks.json Global Global hooks
~/.claude/mcp_settings.json Global MCP config
project/CLAUDE.md Project Project conventions
project/.claude/hooks.json Project Project hooks
project/.claudeignore Project Exclude files

Environment Variables

Variable Description Example
ANTHROPIC_API_KEY API key sk-ant-api03-xxx
ANTHROPIC_BASE_URL API URL https://api.deepseek.com
CLAUDE_MODEL Default model claude-sonnet-4-20250514
CLAUDE_STYLE Default style concise

6. Quick Reference: Common Commands

BASH
# Daily development
claude                                    # Interactive mode
claude "Fix login bug"                    # With instruction
claude --resume                            # Resume session

# Automation
claude -p "Review code" --output json     # Pipeline + JSON
claude --headless "Run tests, fix bugs"   # CI mode

# Control
claude --allowed-tools Read,Write         # Limit tools
claude --style concise                    # Concise output
claude --model claude-opus-4-20250514     # Switch model

# In-session
/cost    # View cost
/clear   # Clear history
/diff    # View changes
/commit  # Commit code

❓ FAQ

Q How to check Claude Code version?
A claude --version.
Q Difference between -p and pipeline mode?
A -p is print mode shorthand, outputs directly without interaction. Pipeline mode passes input via stdin, also non-interactive.
Q How to reset all configuration?
A Delete ~/.claude/ directory, restart Claude Code. Restores defaults.
Q /compact vs /clear?
A /compact preserves context but reduces Tokens; /clear starts completely fresh.
Q How to list all historical sessions?
A claude --list-sessions.

📖 Summary


📝 Exercises

  1. Basic (⭐): Use claude --help to view all parameters, try 3 new ones.
  2. Intermediate (⭐⭐): Use 5 different slash commands in a session, record effects.
  3. Advanced (⭐⭐⭐): Write a Shell script using claude -p --output json for automated code review pipeline.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏