Skip to main content

Claude Code CLI

Claude Code is Anthropic's official CLI coding agent. It runs in your terminal, reads your files, edits code, runs commands, and can complete multi-step tasks autonomously.

Installation

npm install -g @anthropic-ai/claude-code

You need an ANTHROPIC_API_KEY in your environment. Set it in your shell profile:

export ANTHROPIC_API_KEY=your_api_key_here

Start a Session

claude

This opens an interactive session in your current directory. Claude can read, edit, and create files from here.

Run a One-Off Task

claude "Fix the failing tests in src/"

Pass a prompt directly to run a single task without entering the interactive mode.

Continue the Last Session

claude --continue

Resumes the most recent conversation with its full context.

Resume a Specific Session

claude --resume

Shows a list of recent sessions so you can pick one to continue.

Useful Flags

FlagWhat it does
--continueResume the last conversation
--resumePick a past conversation to resume
--model <id>Choose a specific Claude model
--add-dir <path>Add an extra directory to the context
--allowedTools <tools>Restrict which tools Claude can use
--output-format jsonPrint the final response as JSON (useful for scripts)
--verboseShow detailed logs of what Claude is doing

Useful In-Session Commands

CommandWhat it does
/helpShow all available commands
/clearClear the conversation history
/compactSummarize the conversation to save context space
/modelSwitch to a different model
/add-dir <path>Add a directory to the current session
/allowed-toolsShow or change which tools are enabled
/memoryEdit Claude's persistent memory
/statusShow account and session information
/costShow token usage and estimated cost for the session
/exitExit Claude Code

Example: Fix a Bug

claude "The login endpoint returns 500 when the password is wrong. Fix it."

Claude reads the relevant files, applies the fix, and shows a diff.

Example: Add a Feature

cd my-project
claude "Add pagination to the /posts endpoint. Use limit and offset query params."

Claude explores the codebase, edits the right files, and can run tests to verify the change.

Example: Ask Without Editing

claude "Explain how the auth middleware works"

Claude reads the code and answers without making any changes.

MCP Servers

Claude Code supports Model Context Protocol (MCP) servers. They extend Claude with extra tools like database access, browser control, or external APIs.

To add an MCP server:

claude mcp add

To list configured servers:

claude mcp list