Claude Code Overview#
Claude Code is Anthropicโs official agentic CLI. It runs Claude directly in your terminal, reads and edits files, runs commands, manages git, and integrates with your development workflow.
Install#
npm install -g @anthropic-ai/claude-code
Output:
added 1 package, and audited 1 package in 3s
found 0 vulnerabilities
[!NOTE] Requires Node.js 18+. Claude Code is also available as a VS Code extension, JetBrains plugin, and via claude.ai/code.
Set your API key#
export ANTHROPIC_API_KEY="sk-ant-..."
Or run claude and it will prompt you to authenticate on first launch.
Launch interactive mode#
claude
Output:
โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ โป Welcome to Claude Code research preview! โ
โ โ
โ /help for help, /exit to quit โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
? What would you like to do?
Type your request in natural language. Claude reads the current directory as context.
> refactor the auth module to use JWT instead of session tokens
Claude will plan the changes, show you a diff, and ask for confirmation before writing files.
Key interactive concepts#
Permission model#
Claude Code asks before taking potentially destructive actions (file edits, shell commands, git operations). You can:
- Allow once โ approve this specific action
- Allow always (for this session) โ auto-approve this tool type
- Deny โ block the action and let Claude adjust
Context window management#
Use /compact when the conversation grows long. Claude summarizes prior context and continues with a clean window.
/clear vs /compact#
/clearโ discard all conversation history; start fresh/compactโ summarize history and continue; context is preserved as a condensed form
Headless (non-interactive) mode#
Run Claude as a scripted command without the interactive UI. Useful for CI, automation, and piping output.
# Single prompt, non-interactive
claude --print "List all TODO comments in this repo"
# Short form
claude -p "What does this project do?"
Output:
This project is an Astro-based static site for developer cheat sheets and code snippets...
Pipe input to Claude#
cat error.log | claude -p "What is causing this error?"
Output:
The error is a NullPointerException at UserService.java:142. The `currentUser` field
is null when `getPreferences()` is called โ likely because `authenticate()` was not
called before accessing the user object.
Output format flags#
# Plain text (default for pipes)
claude -p "Summarize this file" < README.md
# JSON output (useful for scripting)
claude --output-format json -p "List the exports in this file" < src/utils.ts
Output (JSON):
{"type":"result","result":"The file exports: formatDate, parseISO, addDays, diffDays","session_id":"sess_01...","cost_usd":0.0012}
Allowed tools flag#
Restrict which tools Claude can use in a session:
# Read-only โ no edits or commands
claude --allowedTools "Read,Bash(git log:git diff:git status)" -p "Summarize recent changes"
# Allow specific bash subcommands only
claude --allowedTools "Bash(npm test)" -p "Run the tests and tell me what failed"
CLAUDE.md โ persistent instructions#
CLAUDE.md files give Claude persistent context and standing instructions. Claude reads them automatically at the start of every session.
Hierarchy#
| Location | Scope | Purpose |
|---|---|---|
~/.claude/CLAUDE.md | Global (all projects) | Personal preferences, API keys reminder, global style rules |
<project-root>/CLAUDE.md | Project | Architecture notes, conventions, commands to run, files to avoid |
<subdir>/CLAUDE.md | Subtree | Component-specific guidance when entering that directory |
Claude merges all applicable CLAUDE.md files (global โ project โ subdir) before starting. More specific files take priority on conflicts.
Example project CLAUDE.md#
# Project: Acme API
## Stack
- FastAPI + SQLAlchemy 2.0
- Postgres 16, Alembic for migrations
- pytest + pytest-asyncio for tests
## Commands
- Run tests: `pytest tests/ -x`
- Start dev server: `uvicorn app.main:app --reload`
- Lint: `ruff check . && ruff format --check .`
## Conventions
- Use `async def` for all route handlers
- No `print()` statements โ use `structlog`
- All new endpoints need a test in `tests/api/`
- Never edit `alembic/versions/` directly
## Files to avoid
- `config/secrets.yaml` โ not in git; local only
Example global CLAUDE.md (~/.claude/CLAUDE.md)#
# Global preferences
- I prefer concise explanations โ skip restating what I already know
- Default to Python 3.12+ syntax
- Use `ruff` for formatting, not `black`
- Never add emoji to code comments
[!TIP] Keep CLAUDE.md files short and machine-parseable. Long prose slows Claudeโs context load. Use bullet points and code blocks. Think of it as a compact README for Claude.
IDE integration#
VS Code#
Install the Claude Code extension from the VS Code Marketplace. Adds:
- Inline diff review pane
- Chat panel docked to the sidebar
- Keyboard shortcut
Cmd+Esc(Mac) /Ctrl+Esc(Windows/Linux) to open Claude
JetBrains#
Install from the JetBrains Marketplace. Same features; accessible via Tools โ Claude Code.
Session management#
# List recent sessions
claude sessions list
# Resume a previous session
claude sessions resume <session-id>
# Clear all local session history
claude sessions clear
Useful startup flags#
| Flag | Effect |
|---|---|
--print / -p | Headless mode โ print response and exit |
--output-format | text (default) or json |
--allowedTools | Comma-separated list of tools to permit |
--disallowedTools | Tools to always deny |
--model | Override model (e.g. claude-sonnet-4-6) |
--no-auto-compact | Disable automatic context compaction |
--dangerously-skip-permissions | Skip all permission prompts (CI use only โ never interactive) |
--verbose | Verbose logging including tool calls |
First-run checklist#
โ Node 18+ installed (node --version)
โ npm install -g @anthropic-ai/claude-code
โ ANTHROPIC_API_KEY set in shell profile
โ Run `claude` in a project directory
โ Create a CLAUDE.md at project root with key conventions
โ Add CLAUDE.md to .gitignore if it contains personal notes, or commit it for team use