skip to content

Claude Code Overview

Install, configure, and use Claude Code โ€” Anthropic's agentic CLI. Covers interactive mode, headless scripting, CLAUDE.md memory files, and the project/user settings hierarchy.

5 min read 17 snippets yesterday intermediate

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#

LocationScopePurpose
~/.claude/CLAUDE.mdGlobal (all projects)Personal preferences, API keys reminder, global style rules
<project-root>/CLAUDE.mdProjectArchitecture notes, conventions, commands to run, files to avoid
<subdir>/CLAUDE.mdSubtreeComponent-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#

FlagEffect
--print / -pHeadless mode โ€” print response and exit
--output-formattext (default) or json
--allowedToolsComma-separated list of tools to permit
--disallowedToolsTools to always deny
--modelOverride model (e.g. claude-sonnet-4-6)
--no-auto-compactDisable automatic context compaction
--dangerously-skip-permissionsSkip all permission prompts (CI use only โ€” never interactive)
--verboseVerbose 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