How to Use Claude Code in Terminal: Complete Setup Guide

Claude Code runs in your terminal as claude chat after a five-minute install, connecting to Anthropic's API with your own key. You type natural-language instructions, the agent reads your codebase, edits files, and runs shell commands—all without leaving the command line. Most guides skip the part where you wire MCP servers to give Claude the context it actually needs: screenshots, UI element trees, and dev-tool output.
What is Claude Code and why use it in the terminal?
Claude Code is Anthropic's agentic coding assistant, available as a CLI (claude) and a VS Code extension. The terminal version shines when you already live in tmux, need scriptable workflows, or want to pipe agent output into other tools. Unlike Cursor or Windsurf, you control the loop—the agent doesn't auto-apply edits or spawn IDE windows.
The CLI reads your project directory, maintains conversation context across sessions, and executes bash/zsh/fish commands when you approve. It's bring-your-own-API-key (no subscription beyond Anthropic's usage), and the chat history lives in ~/.config/claude/chat/.
Claude Code's terminal mode is stateless between claude chat sessions unless you use --resume or name the chat with --id. Name critical chats so you can return to them.
How do I install Claude Code in the terminal?
- Install the CLI:
curl -fsSL https://cli.anthropic.com/install.sh | sh(macOS/Linux) orbrew install anthropic-ai/tap/claudeif you prefer Homebrew. Windows users run the PowerShell installer from cli.anthropic.com. - Add your API key:
export ANTHROPIC_API_KEY=sk-ant-...in your shell profile (~/.zshrcor~/.bashrc), or runclaude auth loginand paste the key when prompted. Get a key at console.anthropic.com/settings/keys. - Verify:
claude --versionshould print the release number (≥1.0.0 as of Aug 2026). - Start a chat:
claude chatdrops you into an interactive session. Type/helpto see slash commands (/quit,/clear,/save).
The install script places the binary in /usr/local/bin/claude (macOS) or ~/.local/bin/claude (Linux). Add that path to $PATH if it's not there.
How do I give Claude Code context about my UI or app?
Out of the box, Claude Code sees your filesystem and terminal output—it can't see your browser, native macOS apps, or the UI elements you're debugging. You need an MCP server that captures screenshots and resolves the accessibility tree.
PinVari installs an MCP connector at ~/.pinvari/mcp/pinvari-mcp that hands Claude the exact UI element you circled (role, title, frame, confidence score) plus a cropped screenshot. Connect it with:
claude mcp add --scope user pinvari -- "$HOME/.pinvari/mcp/pinvari-mcp"
Now when you press ⌥⌘A, circle a button in Figma or a table cell in Safari, and say "make this button 12px taller," PinVari captures the element's AX path (AXButton "Submit" in AXGroup "LoginForm"), transcribes your voice on-device, and passes both to Claude via pinvari_next_instruction. Claude reads the instruction, sees the screenshot cropped to the region you circled, and writes the code change.
Other useful MCP servers for terminal Claude:
@modelcontextprotocol/server-filesystem(read/write project files outside the current dir)@modelcontextprotocol/server-puppeteer(browser automation for end-to-end tests)- Custom servers that tail logs, query databases, or hit internal APIs
Full setup guide: Claude Code MCP. List installed servers with claude mcp list.
If claude mcp add pinvari errors, you forgot the -- "$HOME/.pinvari/mcp/pinvari-mcp" path. The bare command tries to install from npm and fails.
What does a typical Claude Code terminal workflow look like?
Here's how I fix a UI bug reported by a QA engineer:
- Capture the issue: Hold ⌥⌘A, circle the broken dropdown in the staging app, say "this dropdown doesn't close when I click outside." PinVari resolves
AXPopUpButton "Sort by" in AXGroup "Toolbar", transcribes the instruction, and files it to the Command Center. - Start a chat:
claude chat --id dropdown-fix(naming it lets me resume tomorrow). - Pull the instruction: I type
@pinvari get next instruction. Claude callspinvari_next_instruction, gets the element path + screenshot + spoken words, and says "I see the AXPopUpButton 'Sort by' in the toolbar. Let me check the click-outside handler." - Agent reads the code: Claude scans
src/components/Toolbar.tsx, finds theuseClickOutsidehook, notices it's not attached to the popup's ref. - Agent proposes a fix: It writes a diff adding the ref to the PopUpButton. I review, type
yes, Claude writes the file. - Verify: I refresh the staging app, test the dropdown, circle it again, say "works now," and type
@pinvari mark doneto close the loop.
Total time: under three minutes. No screenshot pasting, no "the button in the top-right," no token waste on a full-page image.
Compare this to Cursor's agent mode, where the AI auto-applies edits in the GUI. Terminal Claude makes you the gate—nothing ships without yes.
How does Claude Code in terminal compare to Cursor or Codex CLI?
| Feature | Claude Code CLI | Cursor | Codex CLI |
|---|---|---|---|
| Interface | Terminal (claude chat) | VS Code fork (GUI) | Terminal (codex) |
| Context window | 200K tokens (Claude 3.5 Sonnet) | 200K (Sonnet or GPT-4) | 128K (GPT-4 Turbo) |
| MCP support | Native (claude mcp add) | Via extension | Via codex mcp |
| Auto-apply edits | No (you approve) | Yes (agent mode) | Configurable |
| Price | Usage-only (~$3/M input tokens) | $20/mo + usage overage | Usage-only (~$10/M input tokens) |
| Best for | tmux users, scriptable pipelines | GUI developers, pair-programming feel | OpenAI API users, CI/CD hooks |
Claude Code vs Cursor goes deeper. If you live in the terminal and want deterministic, reviewable edits, Claude Code wins. If you want the agent to drive and you trust auto-apply, Cursor's faster for rapid iteration.
Codex CLI (OpenAI's terminal agent) is structurally similar to Claude Code but uses GPT-4 Turbo. The MCP story is lighter (fewer public servers), and the context window is smaller. Choose Codex if you're already on OpenAI credits; choose Claude Code if you want the 200K window and Anthropic's steerable prompting.
How do I connect multiple MCP servers to Claude Code?
Each claude mcp add call registers one server in ~/.config/claude/mcp.json. Add as many as you need:
claude mcp add --scope user pinvari -- "$HOME/.pinvari/mcp/pinvari-mcp"
claude mcp add --scope user filesystem -- npx -y @modelcontextprotocol/server-filesystem "$HOME/projects"
claude mcp add --scope user logs -- /usr/local/bin/tail-server --log-dir /var/log/myapp
Claude loads all servers when you start claude chat. Type @servername toolname to call a specific server's tool, or just describe what you need and Claude picks the right one.
MCP servers run as child processes—they don't persist between chat sessions unless you background them. PinVari's connector talks to the running PinVari.app (127.0.0.1:3402), so the app must be open.
Remove a server with claude mcp remove servername. List all with claude mcp list.
If a server crashes mid-chat, Claude reports "tool unavailable" but keeps running. Check ~/.config/claude/logs/ for stderr traces. Most crashes are missing dependencies (e.g., npx not in $PATH).
What are the must-know slash commands and flags?
Inside claude chat:
/help— list all commands/quitor/q— exit (or Ctrl+D)/clear— wipe the conversation (starts fresh)/save <filename>— export the chat to markdown/files— show which files Claude read this session/context— dump the current context (tokens used, attached files)
Flags when starting:
--id <name>— name the chat so you can resume it--resume— continue the last unnamed chat--model claude-3-5-sonnet-20240620— override the default model--max-tokens 4096— cap output length--temperature 0.7— adjust randomness (0.0–1.0)
Example: claude chat --id refactor-auth --model claude-3-opus-20240229 starts a named session with Opus (the deepest-reasoning model, slower and pricier than Sonnet).
Check token usage mid-chat with /context. If you're over budget, /clear and summarize the findings before continuing.
How do I integrate Claude Code terminal into a CI/CD pipeline?
Non-interactive mode: echo "refactor this function for clarity" | claude --file src/utils.ts --output diff.patch reads the file, generates a patch, and exits. You can:
- Lint the patch with
git apply --check diff.patch - Auto-apply if tests pass:
git apply diff.patch && npm test && git commit -am "AI refactor" - Post the diff to a PR comment via GitHub Actions
For UI-context workflows, wire PinVari's MCP into a headless Mac runner:
- PinVari runs in the background (
open -a PinVari) - A test script uses Puppeteer to click through the app, triggering ⌥⌘A captures at each step
- Claude polls
pinvari_next_instruction, processes each capture, commits fixes - The pipeline closes with
pinvari_mark_doneper issue
This is agent-driven QA: the AI becomes the tester and the fixer. Real agencies are shipping this on nightly builds.
What mistakes do people make when using Claude Code in terminal?
Forgetting to name critical chats: claude chat without --id creates an unnamed session. When you /quit, the context is gone unless you /save first. Name anything you'll resume: --id feature-auth, --id bug-1234.
Pasting full screenshots as base64: Claude accepts images, but a 2MB PNG costs ~6,000 tokens. Use an MCP server (PinVari, Puppeteer) that crops to the relevant region and includes metadata (element role, frame). A 200×200 cropped screenshot is ~30 tokens.
Not setting the ANTHROPIC_API_KEY persistently: Exporting it in one shell session means the next terminal tab has no key. Add export ANTHROPIC_API_KEY=sk-ant-... to ~/.zshrc or ~/.bashrc so it's always there.
Trusting auto-applied diffs blindly: Claude Code in terminal requires manual approval, which is a feature. If you pipe yes into the chat (e.g., yes | claude chat), you bypass review and risk broken commits. Always read the diff.
Ignoring MCP server logs: When pinvari_next_instruction returns empty or the wrong element, check ~/.config/claude/logs/. The connector logs why it failed (app not running, AX tree empty, confidence <0.8).
FAQ
Can I use Claude Code in terminal without an API key?
No. Claude Code CLI requires an Anthropic API key (get one at console.anthropic.com). There's no self-hosted or offline mode—the agent calls Anthropic's servers for every response. If you need local inference, run a local AI on Mac like Ollama with a Llama model, but you lose Claude's 200K context window and MCP tooling.
How much does Claude Code in terminal cost?
You pay only Anthropic's API usage: ~$3 per million input tokens, ~$15 per million output tokens (Claude 3.5 Sonnet, Aug 2026 pricing). A 10-minute chat reviewing 5,000 lines of code might use 50K tokens in (~$0.15) and 2K out (~$0.03), total ~$0.18. Heavy users spend $20–50/mo. No subscription for the CLI itself.
Does Claude Code in terminal work on Windows or Linux?
Yes. The install script supports Linux (x64, arm64) and Windows (PowerShell installer). All features (MCP, chat, file edits) work cross-platform. PinVari's MCP connector is macOS-only (it reads the AX tree via macOS Accessibility API), but you can connect other MCP servers (filesystem, Puppeteer, SQLite) on any OS.
How do I make Claude Code remember context between terminal sessions?
Name your chat with --id: claude chat --id project-refactor. The history lives in ~/.config/claude/chat/project-refactor.json. Next time, claude chat --id project-refactor resumes where you left off. Unnamed chats (claude chat) create a temp session that vanishes on /quit unless you /save it.
Can Claude Code in terminal edit files outside my current directory?
By default, Claude can read/write files in the directory where you ran claude chat. To access other paths, install the filesystem MCP server: claude mcp add --scope user filesystem -- npx -y @modelcontextprotocol/server-filesystem /path/to/other/project. Now Claude can read /path/to/other/project/** and write approved changes there.
What's the difference between Claude Code CLI and the VS Code extension?
The CLI (claude chat) is terminal-native, requires manual approval for edits, and works in any shell. The VS Code extension embeds Claude into the IDE sidebar, auto-applies edits in agent mode, and has GUI context (open tabs, highlighted code). Use the CLI for scriptable workflows and tmux setups; use the extension for GUI-driven pair programming. Both share the same API key and MCP config.
---
Claude Code in terminal is the leanest path from spoken feedback to shipped code when you're already in the shell. Install the CLI, wire one or two MCP servers for the context Claude can't see (screenshots, UI elements, logs), and let the agent edit while you gate every commit. The loop—capture, instruct, review, ship—runs in under a minute once you trust the tooling.
If you're tired of pasting screenshots and typing "the button on the left" into a chat box, try PinVari. Hold ⌥⌘A, circle the element, speak, and watch Claude get the exact named component plus a cropped screenshot. One-time $39 (launch pricing), works with Claude Code CLI, Cursor, or any MCP-compatible agent. No subscription, no uploads, no guessing which div you meant.
Hand your agent the exact element
PinVari resolves what you point at into a named, executable instruction — on-device, no keys, your own agent. One click inside PinVari connects Claude Code, Cursor, VS Code or Codex — or paste one CLI line from pinvari.com/connect.
PinVari → Connect → your agent (one click)Get PinVari — $39 →


