Intermediate

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 login

Requires 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 --print

Key Slash Commands

CommandWhat it does
/helpShow all available commands
/clearClear the current conversation context
/compactSummarise current context to save tokens, then continue
/memoryView and manage project memory files
/statusShow current model, context usage, session info
/reviewCode review the current branch or staged changes
/commitGenerate a commit message and commit staged changes
/voiceToggle voice mode (speak prompts, hear responses)
/loop <interval> <task>Schedule a recurring task for this session (e.g. /loop 30m run tests)
/mcpManage 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 /compact do 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?

Page built: 01 Jun 2026