CLI Flags
claude from your terminal| Flag | Description | Example |
|---|---|---|
| --print / -p | Non-interactive mode — print response and exit | claude -p "explain this file" |
| --output-format | Output format in print mode: text, json, or stream-json | claude -p "…" --output-format json |
| --model / -m | Override the model (e.g. claude-opus-4-7) | claude -m claude-opus-4-7 |
| --resume | Resume a specific prior conversation by session ID | claude --resume <session-id> |
| --continue / -c | Continue the most recent conversation | claude -c |
| --no-tools | Disable all tool use (pure conversation mode) | claude --no-tools "what is X?" |
| --dangerously-skip-permissions | Skip all permission prompts (CI/script use only) | claude --dangerously-skip-permissions -p "…" |
| --allowedTools | Whitelist specific tools (comma-separated) | claude --allowedTools Bash,Edit |
| --disallowedTools | Blacklist specific tools | claude --disallowedTools Bash |
| --system-prompt | Prepend a system prompt (print mode only) | claude -p "…" --system-prompt "You are…" |
| --append-system-prompt | Append text to existing system prompt | claude -p "…" --append-system-prompt "…" |
| --max-turns | Limit agentic loop iterations | claude -p "…" --max-turns 5 |
| --add-dir | Add extra directory to Claude's file access | claude --add-dir /path/to/extra |
| --verbose | Show detailed tool call output | claude --verbose |
| --version | Print current Claude Code version | claude --version |
Combine --print with shell pipes: cat myfile.ts | claude -p "find bugs" --output-format json | jq .content
Keyboard Shortcuts
claude REPL| Action | Shortcut |
|---|---|
| Submit message | Enter |
| Insert newline | Shift+Enter |
| Accept auto-complete | Tab |
| Interrupt / cancel response | Ctrl+C |
| Exit Claude Code | Ctrl+C twice, or Ctrl+D |
| Clear screen | Ctrl+L |
| Action | Shortcut |
|---|---|
| Previous message (history) | ↑ |
| Next message (history) | ↓ |
| Move cursor word-left | Ctrl+← |
| Move cursor word-right | Ctrl+→ |
| Jump to line start | Ctrl+A |
| Jump to line end | Ctrl+E |
Add custom shortcuts in ~/.claude/keybindings.json. Use chord sequences like "ctrl+k ctrl+r" to avoid conflicts with terminal shortcuts.
Slash Commands
Slash commands appear in the autocomplete menu. Built-ins always available; user skills live in ~/.claude/commands/ or .claude/commands/ (project scope).
| Command | What it does |
|---|---|
| /help | Show all available commands and shortcuts |
| /clear | Clear the current conversation context |
| /compact | Compact conversation — keeps key context, reclaims token budget |
| /config | Open the Claude Code settings editor |
| /cost | Show cost and token usage for the current session |
| /model | Switch model mid-session (e.g. swap Opus ↔ Sonnet ↔ Haiku) |
| /status | Show context usage, model, and active tools |
| /memory | Edit your CLAUDE.md memory files |
| /doctor | Run a self-diagnostic and check for config issues |
| /reset | Reset all settings to defaults |
| /pr-comments | Fetch and display comments from the current PR |
| /review Skill | Full code review of the current branch's changes |
| /commit Skill | Stage, diff, draft, and create a git commit |
| /pr Skill | Create a pull request for the current branch |
| /scaffold Skill | Generate a project skeleton (Next.js, FastAPI, etc.) |
| /mock Skill | Generate mock data, fixtures, or test stubs |
| /docker Skill | Create Dockerfile + compose config for the project |
| /migrate Skill | Produce a schema migration (SQL or ORM) |
| /fast | Toggle Fast Mode (Opus with faster output) |
Drop a .md file in ~/.claude/commands/my-command.md. Claude runs it when you type /my-command. Project-scoped commands go in .claude/commands/. See full slash commands guide →
Built-in Skills by Category
Search and preview all skills at the Claude Skills Browser →
Git & Version Control
Testing & Quality
Scaffolding & Generation
Automation & Config
Docs & Explanation
Hooks Quick Reference
| Hook Event | When it fires |
|---|---|
PreToolUse | Before Claude calls any tool |
PostToolUse | After a tool call completes |
Stop | When Claude finishes responding |
UserPromptSubmit | When you submit any message |
| Exit Code | Meaning |
|---|---|
0 | Success — continue |
2 | Block the tool call (PreToolUse only) |
| other | Error — logged, but execution continues |
# ~/.claude/settings.json — minimal hook example { "hooks": { "PostToolUse": [ { "matcher": "Edit|Write", "hooks": [ { "type": "command", "command": "npm run lint --silent 2>&1 | head -20" } ] } ] } }
Permission Modes
| Mode | Set via | Behaviour |
|---|---|---|
| Default | No flag | Prompts for each new tool before executing |
| Allow-list | --allowedTools or settings.json |
Only the listed tools run without asking; all others still prompt |
| Deny-list | --disallowedTools |
Listed tools are always blocked; everything else prompts normally |
| Full auto | --dangerously-skip-permissions |
All tools execute silently — intended for CI scripts only |
Use "permissions": { "allow": ["Bash(git *)", "Edit", "Read"] } to allow only safe git commands inside Bash, while still blocking arbitrary shell execution.
Key Environment Variables
| Variable | Purpose |
|---|---|
ANTHROPIC_API_KEY | Your Anthropic API key (required for API usage; not needed for the Claude.ai plan) |
CLAUDE_MODEL | Default model to use (e.g. claude-opus-4-7) |
CLAUDE_MAX_TOKENS | Override default max output token budget |
CLAUDE_SKIP_PERMISSIONS | Set to 1 to skip prompts (same as --dangerously-skip-permissions) |
ANTHROPIC_BASE_URL | Override the API endpoint (for proxies or local models) |
NO_COLOR | Disable colour output (CI-friendly) |
CLAUDE_CONFIG_DIR | Override the default config directory (~/.claude) |
Power Tips
Put architecture rules, coding conventions, and DO NOTs in CLAUDE.md at the project root. Claude reads it on every session. Run /init to generate one from your existing code. See also tips & tricks →
-p + pipes
Chain claude -p into shell pipelines: git diff HEAD~1 | claude -p "write release notes" --output-format text > RELEASE_NOTES.md. Combine with --max-turns 1 for deterministic one-shot tasks.
Run dangerous refactors in a git worktree add ../my-branch-wt my-branch, then claude --add-dir ../my-branch-wt. Mistakes stay isolated; main working tree is never touched.
Claude Code can spawn subagents with the Agent tool. Use the Explore subagent for read-only research so the main context isn't flooded, and general-purpose for write tasks.
Run /compact before starting a large feature. It summarises prior context into a tight header, freeing the token budget for the actual work rather than old conversation history.
Wire a PostToolUse hook on Edit|Write to run your linter and test suite on every file save. You get instant feedback without leaving the Claude Code session. See hooks guide →
Commit a .claude/settings.json to the repo. It sets default allowed tools, custom hooks, and permissions for the entire team — everyone gets the same safe defaults automatically.
Run claude --continue to pick up exactly where you left off. Or claude --resume <id> to jump to a specific past session. /cost shows session cost at any point.