Claude CLI
Claude Code is Anthropic's official CLI — a terminal-native AI coding agent that runs in your development environment. Unlike chat interfaces, Claude Code reads your actual files, runs commands, edits code, and iterates in a feedback loop directly in your terminal. It's the primary CLI interface to Claude for software engineering tasks.
This page is a practical CLI reference. For conceptual background, see the fullClaude Code section.
Install
# Install globally via npm
npm install -g @anthropic-ai/claude-code
# Verify installation
claude --version
# Authenticate (opens browser for OAuth)
claude auth loginRequires Node.js 18+. Uses your Anthropic account (Pro/Max subscription) for authentication. Alternatively, set ANTHROPIC_API_KEY to use an API key directly.
Starting a Session
# Start interactive session in current directory
claude
# Start with an initial prompt
claude "Explain the architecture of this codebase"
# Start in a specific directory
claude --cwd /path/to/project
# Start with a specific model
claude --model claude-opus-4-6
# Non-interactive: pipe input and get output
echo "What does package.json do?" | claude --printKey Slash Commands
| Command | What it does |
|---|---|
| /help | Show all available commands |
| /clear | Clear the current conversation context |
| /compact | Summarise current context to save tokens, then continue |
| /memory | View and manage project memory files |
| /status | Show current model, context usage, session info |
| /review | Code review the current branch or staged changes |
| /commit | Generate a commit message and commit staged changes |
| /voice | Toggle voice mode (speak prompts, hear responses) |
| /loop <interval> <task> | Schedule a recurring task for this session (e.g. /loop 30m run tests) |
| /mcp | Manage MCP server connections |
Key CLI Flags
claude --print # Non-interactive: print response then exit
claude --output-format json # Return structured JSON response
claude --model <id> # Override the model (e.g. claude-opus-4-6)
claude --cwd <dir> # Set working directory
claude --no-stream # Disable streaming output
claude --max-turns <n> # Limit agentic turns (default: unlimited)
claude --allowedTools "Read,Write,Bash" # Restrict which tools Claude can use
claude --permission-mode auto # Skip all permission prompts (dangerous in scripts)CLAUDE.md — Project Context
Place a CLAUDE.md file in your project root to give Claude persistent context about the project: architecture, conventions, commands to run, things to avoid. Claude reads this file automatically at the start of every session in that directory.
# CLAUDE.md
## Build commands
npm run build # Compile TypeScript
npm run test # Run Jest tests
npm run dev # Dev server at :3000
## Conventions
- Use React functional components only (no class components)
- All API calls go through src/lib/api.ts
- Never commit .env files
## Architecture
Next.js 16 App Router. API routes in src/app/api/. Static export.Permission Modes
Claude Code asks for permission before running potentially destructive tools. Three modes:
- default — prompts for each tool call the first time in a session
- auto — skips all prompts (use in scripts, CI, non-interactive contexts)
- manual — prompts for every tool call without exception
Checklist: Do You Understand This?
- How do you install and authenticate Claude Code?
- What does
/compactdo and when would you use it? - What is CLAUDE.md and where does it go?
- What flag do you use to run Claude Code non-interactively in a script?