Getting started

Run claude to start a REPL session:

# Start interactive mode
claude

# Start with an initial query
claude "explain this project"

CLI commands

CommandDescriptionExample
claudeStart interactive REPLclaude
claude "query"Start REPL with initial promptclaude "explain this project"
claude -p "query"Query via SDK, then exitclaude -p "explain this function"
cat file | claude -p "query"Process piped contentcat logs.txt | claude -p "explain"
claude -cContinue most recent conversationclaude -c
claude -c -p "query"Continue via SDKclaude -c -p "Check for type errors"
claude -r "<session-id>" "query"Resume session by IDclaude -r "abc123" "Finish this PR"
claude updateUpdate to latest versionclaude update
claude mcpConfigure Model Context Protocol serversSee MCP section in tutorials

CLI flags

Customize Claude Code’s behavior with these command-line flags:

FlagDescriptionExample
--add-dirAdd additional working directories for Claude to access (validates each path exists as a directory)claude --add-dir ../apps ../lib
--allowedToolsA list of tools that should be allowed without prompting the user for permission, in addition to settings.json files"Bash(git log:*)" "Bash(git diff:*)" "Write"
--disallowedToolsA list of tools that should be disallowed without prompting the user for permission, in addition to settings.json files"Bash(git log:*)" "Bash(git diff:*)" "Write"
--print, -pPrint response without interactive mode (see SDK documentation for programmatic usage details)claude -p "query"
--output-formatSpecify output format for print mode (options: text, json, stream-json)claude -p "query" --output-format json
--verboseEnable verbose logging, shows full turn-by-turn output (helpful for debugging in both print and interactive modes)claude --verbose
--max-turnsLimit the number of agentic turns in non-interactive modeclaude -p --max-turns 3 "query"
--modelSets the model for the current session with an alias for the latest model (sonnet or opus) or a model’s full nameclaude --model claude-sonnet-4-20250514
--permission-prompt-toolSpecify an MCP tool to handle permission prompts in non-interactive modeclaude -p --permission-prompt-tool mcp_auth_tool "query"
--resumeResume a specific session by ID, or by choosing in interactive modeclaude --resume abc123 "query"
--continueLoad the most recent conversation in the current directoryclaude --continue
--dangerously-skip-permissionsSkip permission prompts (use with caution)claude --dangerously-skip-permissions

The --output-format json flag is particularly useful for scripting and automation, allowing you to parse Claude’s responses programmatically.

For detailed information about print mode (-p) including output formats, streaming, verbose logging, and programmatic usage, see the SDK documentation.

Slash commands

Control Claude’s behavior during an interactive session:

CommandPurpose
/bugReport bugs (sends conversation to Anthropic)
/clearClear conversation history
/compact [instructions]Compact conversation with optional focus instructions
/configView/modify configuration
/costShow token usage statistics
/doctorChecks the health of your Claude Code installation
/helpGet usage help
/initInitialize project with CLAUDE.md guide
/loginSwitch Anthropic accounts
/logoutSign out from your Anthropic account
/memoryEdit CLAUDE.md memory files
/modelSelect or change the AI model
/permissionsView or update permissions
/pr_commentsView pull request comments
/reviewRequest code review
/statusView account and system statuses
/terminal-setupInstall Shift+Enter key binding for newlines (iTerm2 and VSCode only)
/vimEnter vim mode for alternating insert and command modes

Special shortcuts

Quick memory with #

Add memories instantly by starting your input with #:

# Always use descriptive variable names

You’ll be prompted to select which memory file to store this in.

Line breaks in terminal

Enter multiline commands using:

  • Quick escape: Type \ followed by Enter
  • Keyboard shortcut: Option+Enter (or Shift+Enter if configured)

To set up Option+Enter in your terminal:

For Mac Terminal.app:

  1. Open Settings → Profiles → Keyboard
  2. Check “Use Option as Meta Key”

For iTerm2 and VSCode terminal:

  1. Open Settings → Profiles → Keys
  2. Under General, set Left/Right Option key to “Esc+”

Tip for iTerm2 and VSCode users: Run /terminal-setup within Claude Code to automatically configure Shift+Enter as a more intuitive alternative.

See terminal setup in settings for configuration details.

Vim Mode

Claude Code supports a subset of Vim keybindings that can be enabled with /vim or configured via /config.

The supported subset includes:

  • Mode switching: Esc (to NORMAL), i/I, a/A, o/O (to INSERT)
  • Navigation: h/j/k/l, w/e/b, 0/$/^, gg/G
  • Editing: x, dw/de/db/dd/D, cw/ce/cb/cc/C, . (repeat)