Tag: Claude AI

  • Connect Claude Code to Postgres via MCP: The Right Way (2026)

    Connect Claude Code to Postgres via MCP: The Right Way (2026)

    The most useful thing you can wire into Claude Code isn’t a new model or a clever prompt — it’s your actual database. When Claude Code can read your schema, it stops guessing at table names, column types, and relationships. It starts writing queries that work the first time.

    This is the practical walkthrough for connecting Claude Code to a Postgres database via MCP: the command, the credential setup, the safety pattern, and what the workflow actually looks like once it’s running.

    What the Postgres MCP server does

    The official @modelcontextprotocol/server-postgres package (maintained in the MCP reference implementations repo) gives Claude Code four tools: schema inspection, query execution inside a read-only transaction, table detail lookup, and relationship traversal. The server cannot write data — it’s read-only by design in the reference implementation, though third-party variants like postgres-mcp-pro add configurable write access if you need it.

    For the majority of development workflows — debugging, writing migrations, generating queries — read-only is exactly what you want. Claude Code can see the shape of your data without being able to touch it.

    The fastest path: single command setup

    If you just want it running against a local database:

    claude mcp add postgres -- npx -y @modelcontextprotocol/server-postgres "postgresql://USER:PASSWORD@localhost:5432/mydb"

    The -y flag on npx auto-accepts the package install so the command doesn’t hang on first run. Verify with:

    claude mcp list

    You should see postgres with a connected status. That’s it — Claude Code now has schema access in the current project.

    Don’t do this for a production database. The connection string above is hardcoded. It goes into ~/.claude.json as plaintext. Use a dedicated local or staging database during development, and use env vars for anything that matters.

    The right way: env vars and a read-only user

    Two things to do before connecting to any real database:

    1. Create a read-only Postgres user:

    CREATE USER claude_readonly WITH PASSWORD 'your-password-here';
    GRANT CONNECT ON DATABASE your_db TO claude_readonly;
    GRANT USAGE ON SCHEMA public TO claude_readonly;
    GRANT SELECT ON ALL TABLES IN SCHEMA public TO claude_readonly;
    ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO claude_readonly;

    This user can see everything in public and do nothing else. If something goes wrong — a rogue tool call, a compromised session — blast radius is zero.

    2. Reference the connection string via env var in .mcp.json:

    {
      "mcpServers": {
        "db": {
          "type": "stdio",
          "command": "npx",
          "args": ["-y", "@modelcontextprotocol/server-postgres"],
          "env": {
            "POSTGRES_CONNECTION_STRING": "${DATABASE_URL}"
          }
        }
      }
    }

    Set DATABASE_URL in your shell environment or in a .env file (not committed). Add .mcp.json to the repo — everyone on the team gets the same server config — but the actual connection string lives in each developer’s local environment. This is the same pattern you already use for application config. It’s the right pattern here too.

    Add the server at project scope so it’s committed:

    claude mcp add --scope project --transport stdio db -- npx -y @modelcontextprotocol/server-postgres

    Then edit .mcp.json to replace the hardcoded connection string with the ${DATABASE_URL} env var reference shown above.

    What Claude Code can actually do with schema access

    Once the server is connected, the workflow changes significantly. A few real examples:

    Schema exploration: Ask Claude Code “what tables are in this database and how are they related?” and it traverses foreign keys, describes join paths, and builds a mental model of your data layer. No more copy-pasting \dt output.

    Query generation: “Write a query that finds users who signed up in the last 30 days but haven’t completed onboarding” produces accurate SQL because Claude Code knows your actual column names. With a generic prompt and no schema access, you’d get plausible-looking SQL that fails because user_status is actually onboarding_state.

    Migration drafting: “I need to add a last_login_at column to users — show me the migration and check for existing timestamp patterns in the schema.” Claude Code inspects the schema first, matches your existing column naming conventions, and produces a migration that fits your codebase.

    Debugging: “This query is returning the wrong count — here’s the query, check it against the schema.” Claude Code can spot that you’re joining on a nullable column, missing a filter on a soft-delete flag, or aggregating before filtering.

    Neon and cloud Postgres

    If you’re on Neon, there’s a first-party MCP server with additional capabilities: branch management, database creation, and schema migrations via Neon’s branching model. Set it up with:

    npx neonctl mcp add

    This runs OAuth through your browser and configures Claude Code automatically. The Neon MCP server is intended for local development and IDE workflows — not production automation — same caution applies.

    Debugging when it doesn’t connect

    Three commands for when the server shows as disconnected:

    claude mcp list          # check registered servers and status
    claude mcp test db       # test a specific server
    claude --debug           # tail logs including MCP stderr output

    Most connection failures are either a wrong connection string, a missing env var, or Node version issues with npx. The debug log shows the exact error from the server process — read it before assuming the problem is Claude Code.

    The practical baseline

    Five minutes to set up. The productivity delta on any codebase larger than a few tables is immediate — Claude Code stops making column-name mistakes and starts being genuinely useful for data-layer work. Wire up the read-only user, commit the .mcp.json, and add DATABASE_URL to your team’s .env.example. Done.

    The model doing the work in a typical Claude Code session is claude-sonnet-4-6 (workhorse) — it handles schema-aware query generation well without burning through Opus 4.8 credits on every lookup.

    Related Reading

    Frequently Asked Questions

    How do I connect Claude Code to a Postgres database via MCP?

    Run: claude mcp add postgres — npx -y @modelcontextprotocol/server-postgres “postgresql://USER:PASSWORD@localhost:5432/mydb”. The -y flag auto-accepts the package install so the command doesn’t hang. Then run claude mcp list and confirm postgres shows a connected status. Use a local or staging database for this quick path, not production.

    Is the Postgres MCP server read-only?

    Yes. The official @modelcontextprotocol/server-postgres package is read-only by design — it exposes schema inspection, query execution inside a read-only transaction, table detail lookup, and relationship traversal. It cannot write data. Third-party variants like postgres-mcp-pro add configurable write access if you need it.

    What’s the safe way to connect Claude Code to a production database?

    Create a dedicated read-only Postgres user (GRANT SELECT only), and reference the connection string through an environment variable in .mcp.json using ${DATABASE_URL} rather than hardcoding it. Commit .mcp.json so the team shares the server config, but keep the actual connection string in each developer’s local .env. If a session is ever compromised, the blast radius is zero.

    Why does schema access make Claude Code more accurate?

    With schema access, Claude Code reads your real table names, column types, and relationships, so it writes queries that work the first time instead of guessing. Without it, you get plausible-looking SQL that fails because user_status is actually onboarding_state. It also improves migration drafting and query debugging by matching your existing conventions.

    How do I debug a Postgres MCP server that won’t connect?

    Use three commands: claude mcp list to check registered servers and status, claude mcp test db to test a specific server, and claude –debug to tail logs including MCP stderr. Most failures are a wrong connection string, a missing env var, or a Node version issue with npx — the debug log shows the exact server error.

  • How to Connect Any Tool to Claude with MCP: Complete Setup Guide

    Last verified: June 2026

    MCP (Model Context Protocol) is how you give Claude hands. Out of the box Claude can talk; with an MCP server connected, it can read your files, query a database, hit an API, or drive a browser. This guide covers the two places you actually wire servers up: the claude_desktop_config.json file for the Claude Desktop app, and the claude mcp add command for Claude Code (the terminal/IDE tool). It ends with the troubleshooting section the official docs skip: path problems, JSON syntax traps, servers that silently never load, and the Windows quirks that cost people an afternoon.

    Everything below is checked against the current Claude Code MCP docs and tested commands. If you want the wider picture of how MCP fits into a working setup, see the AI operator’s stack.

    What is MCP and what is an MCP server?

    MCP is an open standard for connecting AI models to external tools and data. An MCP server is a small program that exposes a set of tools (functions Claude can call) over that protocol. Claude is the client; the server is the thing that actually does the work, like reading a Postgres table or creating a GitHub issue.

    There are two transport types you will deal with in practice:

    • stdio (local): the server runs as a process on your machine. Claude talks to it over standard input/output. Best for filesystem access, local databases, and custom scripts. This is what most “install this MCP server” instructions mean.
    • HTTP (remote): the server lives on the internet at a URL. Best for cloud services (Notion, Sentry, Stripe, GitHub). Often uses OAuth. SSE is the older remote transport and is now deprecated; use HTTP for new remote servers.

    The same server can usually be added to both Claude Desktop and Claude Code. The mechanics differ: Desktop uses a JSON file you edit by hand, Claude Code gives you a CLI that writes the config for you.

    How do I add an MCP server to Claude Desktop?

    Claude Desktop reads a single JSON file. You edit it, fully quit the app, and reopen. There is no in-app “add server” button for custom servers as of June 2026, so the file is the source of truth.

    Where is claude_desktop_config.json?

    • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
    • Windows: %APPDATA%\Claude\claude_desktop_config.json (paste that into the File Explorer address bar; it expands to C:\Users\YOU\AppData\Roaming\Claude\)

    The fastest way to open it: in Claude Desktop go to Settings > Developer > Edit Config. That button creates the file if it does not exist and opens the folder. If the file is brand new it may be empty or just {}.

    The config file structure

    Everything lives under a top-level mcpServers object. Each key is a name you choose; each value describes how to launch the server. Here is a complete, working file with a local filesystem server and a remote Notion server:

    {
      "mcpServers": {
        "filesystem": {
          "command": "npx",
          "args": [
            "-y",
            "@modelcontextprotocol/server-filesystem",
            "C:\\Users\\YOU\\Documents"
          ]
        },
        "notion": {
          "command": "npx",
          "args": ["-y", "@notionhq/notion-mcp-server"],
          "env": {
            "NOTION_TOKEN": "secret_your_token_here"
          }
        }
      }
    }

    Three fields do all the work:

    • command the executable to run (npx, node, python, uvx, or an absolute path to a binary).
    • args an array of arguments. Each flag and value is its own array element. "--port 8080" as a single string will not work; use "--port", "8080".
    • env an object of environment variables (API keys, tokens). Optional.

    After saving, completely quit Claude Desktop (on Windows, right-click the system tray icon and choose Quit; closing the window is not enough) and reopen it. You should see a tools/connector indicator in the chat input. For a full Notion walkthrough including the token, see connecting Notion to Claude with MCP.

    How do I add an MCP server to Claude Code (CLI)?

    Claude Code does not make you hand-edit JSON. The claude mcp command manages servers for you and writes to the right file. This is the part people get wrong most often, so here is the exact, verified syntax.

    claude mcp add

    The general form for a local (stdio) server is:

    claude mcp add [options] <name> -- <command> [args...]

    The -- is load-bearing. Everything before it is for Claude Code; everything after it is the command that launches your server. Real examples:

    # Local filesystem server
    claude mcp add filesystem -- npx -y @modelcontextprotocol/server-filesystem ~/Documents
    
    # Local server with an environment variable
    claude mcp add --env AIRTABLE_API_KEY=YOUR_KEY airtable -- npx -y airtable-mcp-server
    
    # Remote HTTP server
    claude mcp add --transport http notion https://mcp.notion.com/mcp
    
    # Remote HTTP server with an auth header
    claude mcp add --transport http github https://api.githubcopilot.com/mcp/ --header "Authorization: Bearer YOUR_PAT"

    Option ordering matters. All flags (--transport, --env, --scope, --header) must come before the server name. Put a flag after the name and you will get a confusing parse error or the flag will be passed to your server instead of to Claude Code.

    Scopes: local, project, user

    The --scope flag decides where the config is written and who sees it:

    • local (the default) loads only in the current project, private to you. Stored in ~/.claude.json keyed by the project path.
    • project loads in the current project and is shared with your team. Stored in a .mcp.json file at the project root that you commit to git.
    • user loads across all your projects, private to you. Also stored in ~/.claude.json.
    # Available across all your projects
    claude mcp add --scope user --transport http sentry https://mcp.sentry.dev/mcp
    
    # Shared with your team via .mcp.json in the repo
    claude mcp add --scope project filesystem -- npx -y @modelcontextprotocol/server-filesystem .

    When the same server name exists at multiple scopes, local wins over project, which wins over user. The whole entry from the winning scope is used; fields are not merged.

    claude mcp list, get, and remove

    # List every configured server and its connection status
    claude mcp list
    
    # Show the full config for one server
    claude mcp get github
    
    # Remove a server
    claude mcp remove github

    claude mcp list is your first diagnostic. It shows each server as connected, pending, or failed. Project-scoped servers from a .mcp.json you have not approved yet show as Pending approval until you run claude interactively and accept them.

    Other useful commands

    # Add from a raw JSON blob (handy when copying from a server's README)
    claude mcp add-json weather '{"type":"stdio","command":"npx","args":["-y","weather-mcp"]}'
    
    # Import everything you already set up in Claude Desktop (macOS / WSL)
    claude mcp add-from-claude-desktop

    Inside a running Claude Code session, type /mcp to see live server status, tool counts, and to trigger OAuth login for remote servers that need it.

    Troubleshooting: the errors the docs skip

    Most MCP failures are not exotic. They are paths, quoting, and the app not restarting. Work this list top to bottom.

    Server not loading / no tools appear

    1. Did you actually restart? Claude Desktop only reads the config at launch. Fully quit (tray icon > Quit on Windows, Cmd+Q on macOS) and reopen. In Claude Code, run claude mcp list to see the real status instead of guessing.
    2. Is the command on PATH? The single most common stdio failure is npx, node, python, or uvx not being found by the app. GUI apps often have a narrower PATH than your terminal. Fix it by using an absolute path. Find it with which npx (macOS/Linux) or where npx (Windows), then put that full path in command.
    3. Read the logs. Claude Desktop writes per-server logs. macOS: ~/Library/Logs/Claude/. Windows: %APPDATA%\Claude\logs\. Look for mcp-server-NAME.log. The actual error (missing module, bad token, wrong path) is almost always sitting right there.

    spawn ENOENT or “command not found”

    This means the OS could not find the executable named in command. It is a PATH problem, not a Claude problem. Use the absolute path (see above). On Windows specifically, see the npx note below.

    JSON syntax errors (the silent killer)

    If claude_desktop_config.json has a single syntax error, Claude Desktop loads zero servers and usually says nothing. The usual culprits:

    • Trailing commas. JSON forbids a comma after the last item in an object or array. "args": ["a", "b",] is invalid.
    • Smart quotes. If you edited the file in a word processor, curly quotes (the slanted kind) break the parser. Use a code editor and straight quotes only.
    • Unescaped Windows backslashes. In JSON, \ is an escape character, so every backslash in a Windows path must be doubled: C:\\Users\\YOU\\Documents. A single backslash silently corrupts the string.

    Paste the whole file into any JSON validator before restarting. Thirty seconds there saves an hour of staring.

    Claude Code: flag passed to the wrong place

    If claude mcp add behaves strangely, you almost certainly put a flag after the server name or forgot the --. Reread the order: claude mcp add [flags] NAME -- COMMAND ARGS. The -- separates Claude Code’s flags from your server’s command.

    Windows quirks

    • npx needs a wrapper in some setups. If a bare "command": "npx" fails on Windows, launch it through cmd: "command": "cmd" with "args": ["/c", "npx", "-y", "the-server-package"]. This resolves a class of “npx works in my terminal but not in Claude” failures.
    • Use the right config root. It is %APPDATA%\Claude\ (which is AppData\Roaming), not AppData\Local. Mixing these up means you are editing a file the app never reads.
    • Git Bash mangles paths. If you run commands through Git Bash, it can rewrite paths like /c/Users or absolute paths inside arguments. Prefer PowerShell or cmd for claude mcp add, or pass paths exactly as Windows expects them.
    • WSL is a separate world. A server installed inside WSL is not visible to a Windows-native Claude Desktop, and vice versa. Keep both on the same side.

    Remote server returns 401 / 403

    The server needs authentication. In Claude Code, run /mcp and complete the OAuth flow in your browser. If you hardcoded an Authorization header and it is rejected, the token is wrong for that endpoint; remove the header and let OAuth handle it instead.

    Frequently asked questions

    What is an MCP server in one sentence?

    A small program that exposes tools (functions like read-file or query-database) to Claude over the Model Context Protocol, so Claude can take real actions instead of only producing text.

    What is the difference between Claude Desktop and Claude Code for MCP?

    Claude Desktop is the chat app and you configure servers by hand-editing claude_desktop_config.json, then restarting. Claude Code is the terminal/IDE tool and you configure servers with the claude mcp add command, which writes the config for you.

    Where is the Claude Desktop config file?

    macOS: ~/Library/Application Support/Claude/claude_desktop_config.json. Windows: %APPDATA%\Claude\claude_desktop_config.json. The quickest way to open it is Settings > Developer > Edit Config inside the app.

    Why is my MCP server not showing up?

    In order of likelihood: you did not fully restart the app, the command is not on the app’s PATH (use an absolute path), or there is a JSON syntax error such as a trailing comma, a smart quote, or an unescaped Windows backslash. Check the per-server log in the Claude logs folder for the exact error.

    What does the double dash do in claude mcp add?

    The -- separates Claude Code’s own flags from the command that launches your server. Flags like --transport and --env go before it; the actual launch command (npx -y some-server) goes after it.

    What is the default scope for claude mcp add?

    local. The server loads only in the current project and stays private to you. Use --scope user to make it available in every project, or --scope project to share it with your team via a committed .mcp.json.

    Is SSE or HTTP the right transport for remote servers?

    HTTP. SSE still works but is deprecated. Use --transport http for any new remote server unless its documentation specifically requires SSE.

    How do I remove an MCP server?

    In Claude Code, run claude mcp remove NAME. In Claude Desktop, delete that server’s entry from the mcpServers object in claude_desktop_config.json and restart the app.

    Where to go next

    Once your servers connect cleanly, the leverage comes from using them well. For how this fits a daily workflow, read the AI operator’s stack; if you are choosing between coding environments, see Claude Code vs Cursor. And if you want a concrete first server to wire up, the Notion MCP setup is a clean, high-value place to start.

  • Claude 4.6 vs GPT-5: The 2026 Leaderboard

    Claude 4.6 vs GPT-5: The 2026 Leaderboard

    This page is continuously updated by our autonomous tracker. Bookmark it to stay informed on the current state of the LLM race.

    🏆 Current LMSYS Chatbot Arena Standings

    Last Updated: 2026-05-30

    1. Claude 4.6 Sonnet (Elo: 1345)
    2. GPT-5 (Early Preview) (Elo: 1338)
    3. Claude 4.6 Haiku (Elo: 1312)

    Anthropic’s Sonnet variant continues to dominate the coding and reasoning benchmarks, specifically pulling ahead due to its massive multi-file context window stability.

  • The Top Claude 4.6 Prompt for React Developers This Week

    The Top Claude 4.6 Prompt for React Developers This Week

    If you are building front-end applications, you already know that Claude 4.6 Sonnet’s context window can handle massive files. But how do you prevent the model from ‘lazy coding’ (leaving // rest of code here comments)?

    The Anti-Lazy Prompt:

    “You are a Senior Staff Engineer. Rewrite this entire React component. Under NO circumstances are you allowed to use placeholders, comments like ‘// existing code’, or brevity. You must output the entire, complete, and fully functional file from line 1 to EOF. Failure to do so will break the CI/CD pipeline.”

    Why it works: By framing the omission as a pipeline-breaking failure, Claude’s alignment training prioritizes the completion of the file over token conservation.

  • Claude Artifacts API Release: What We Are Hearing

    The Claude “Artifacts” Wrapper is Coming to the Core API

    Anthropic’s “Artifacts” feature—which allows Claude to instantly render and preview code, diagrams, and UI elements in a side panel—has revolutionized the ChatGPT-style web interface. But for developers building their own applications using the Claude API, they’ve been forced to build those UI rendering wrappers from scratch.

    According to emerging chatter on X (Twitter), that is about to change.

    Social Radar Intel:
    “Rumors circulating that the Artifacts UI wrapper is finally coming to the core API next week. If developers can render interactive React components directly inside their own chat UIs using Claude, it’s game over for generic wrappers.”

    Why This Matters for Builders

    If Anthropic exposes the Artifacts rendering engine natively through the API, it significantly lowers the barrier to entry for building rich, interactive AI tools. You will no longer need a senior front-end engineer to parse JSON and render a React component on the fly; the API will handle the interactive framing.

    The Tygart Verdict: We are keeping a close eye on the official Anthropic changelog over the next two weeks. If this drops, expect a flood of “wrapper” apps to pivot or die.

  • Claude Code Plan Mode: How to Use It, When to Skip It (2026 Guide)

    Claude Code Plan Mode: How to Use It, When to Skip It (2026 Guide)

    Published: May 25, 2026 | Last fact-check: May 25, 2026 against Anthropic docs and Claude Code v2.1+ behavior

    Quick Answer

    Plan Mode is a Claude Code setting that forces the agent to think through and approve a plan before taking destructive actions. Trigger it with Shift+Tab pressed twice in the terminal (the first press cycles to Auto-Accept Mode; the second lands on Plan Mode). Use it for risky multi-step work; skip it for simple read-only or contained edits.

    How to enable it, when it pays off, and when it gets in your way below.

    Plan Mode (sometimes called “planning mode”) is one of the more underused features in Claude Code in 2026. It changes how the agent works in a specific, measurable way: before Claude Code edits files, runs commands, or modifies state, it produces a plan and waits for your approval. You see what it intends to do, you say yes or no, and only then does it act.

    For the right kind of task, Plan Mode is the difference between a clean execution and a regrettable one. For the wrong kind of task, it is friction that slows you down. This guide separates the two.

    What Plan Mode Actually Does

    In default mode, Claude Code is allowed to take actions as it reasons. It can read files, write files, run bash, edit code, all in one conversational flow. This is the strength of Claude Code as an agent — it gets work done without asking permission for every step.

    In Plan Mode, Claude Code’s behavior changes:

    1. You describe the task.
    2. Claude Code investigates the codebase (read-only operations are still allowed).
    3. Claude Code drafts a plan listing every file it intends to change, every command it intends to run, and every decision point.
    4. You read the plan. You approve it, modify it, or reject it.
    5. Only after approval does Claude Code start writing files or running commands.

    The plan is presented in the terminal as a structured outline. You can ask Claude Code to revise the plan, add steps, remove steps, or change the order. Iterating on the plan is fast because no actions have been taken yet.

    How to Enable Plan Mode

    There are four ways to activate Plan Mode in Claude Code:

    1. Shift+Tab pressed twice. Each press of Shift+Tab cycles through the three permission modes: Default → Auto-Accept → Plan → Default. Two presses lands on Plan Mode. The status bar shows ⏸ plan mode on when active.
    2. The /plan slash command. Type /plan at the start of any prompt to enter Plan Mode for that turn only. Useful for one-off plans without flipping the whole session.
    3. The –permission-mode plan flag at startup. Start the session in Plan Mode from the command line.
    4. Headless mode for scripts and CI. claude --print --permission-mode plan "your task" for automation that should never edit files.
    # Start session in Plan Mode
    claude --permission-mode plan
    
    # Or mid-session — press Shift+Tab TWICE
    # (first press = Auto-Accept Mode, second press = Plan Mode)
    
    # Or one-shot Plan Mode for next prompt only
    /plan

    Plan Mode is persistent within a session — it stays on until you cycle out with another Shift+Tab. Close and reopen Claude Code and it defaults back to off. Toggle it on for risky work, leave it on for the whole session if you are doing higher-risk work end-to-end.

    Important: Plan Mode is a hard read-only sandbox enforced at the tool level. Claude Code physically cannot edit files, run commands, or modify state while Plan Mode is active. This is not a suggestion or a soft check — the write tools are unavailable.

    When Plan Mode Pays Off

    Plan Mode is worth the friction in these situations:

    • Multi-file refactors. When the agent will touch 5+ files, you want to see the list before it starts editing. A small confusion about which files to change becomes a big mess fast.
    • Database migrations or schema changes. Anything that touches durable state and is hard to undo benefits from a confirmed plan.
    • Production code paths. If a session affects code that ships to users, the plan checkpoint is cheap insurance.
    • Ambiguous instructions. When you are not sure how the agent will interpret your request, Plan Mode surfaces the interpretation before any work happens.
    • New repository onboarding. When you do not yet know the codebase well, Plan Mode lets the agent show you what it learned during investigation before it acts.
    • Long-running batch jobs. Approving a plan for 200 file edits and then walking away is safer than launching 200 edits blind.

    When Plan Mode Gets In the Way

    Plan Mode is not free. The friction it adds is a real cost for certain workflows:

    • Single-file tweaks. Asking Claude Code to fix a typo or rename a variable does not need a plan. The plan takes longer than the fix.
    • Tight feedback loops. When you are iterating quickly — try a change, see the result, adjust — Plan Mode slows the loop. Default mode wins here.
    • Read-only investigation. If you are asking questions about the codebase (“how does this auth flow work”), there is nothing to plan. Plan Mode is irrelevant.
    • Work in a sandbox. If you are working in a throwaway directory or branch where mistakes are cheap, the safety net of Plan Mode is overkill.

    The decision is not “is Plan Mode good.” It is “is the cost of approval less than the cost of an unintended action.” For risky multi-step work, yes. For cheap iteration, no.

    Working Inside the Plan

    Once Claude Code presents a plan, you have several options:

    1. Approve as-is. Tell Claude Code to proceed. It executes the plan in order.
    2. Approve with modifications. Tell Claude Code to remove specific steps, reorder them, or add additional steps. It revises the plan and re-presents.
    3. Ask questions. Drill into specific steps. “Why are you editing file X?” Claude Code explains the reasoning.
    4. Reject and restart. If the plan is wrong-shape, tell Claude Code so. It will rebuild the plan from a corrected understanding.
    5. Cancel. Exit Plan Mode entirely if you’ve decided this is not the right task or session for it.

    The plan is conversational. You are not stuck with the first draft. Iterating on the plan is much cheaper than iterating after the work is done.

    What Plan Mode Does Not Protect Against

    Plan Mode is not a sandbox. The plan, once approved, executes for real. Plan Mode does not:

    • Prevent you from approving a bad plan
    • Catch logic errors inside individual file edits
    • Prevent destructive bash commands if you approved them in the plan
    • Replace tests or code review

    It is a thinking checkpoint, not a safety net. The human still owns the decision.

    Plan Mode vs Other Safety Patterns

    Plan Mode is one of several safety patterns Claude Code supports:

    • Read-only sessions: Restrict the agent to read operations only.
    • Per-tool permissions: Approve each tool use individually as it happens.
    • Plan Mode: Approve a batch of intended actions before execution begins.
    • Auto-accept mode: The opposite — accept all tool uses without asking. Fast and risky.

    Per-tool permission is more granular but slower. Plan Mode is bulkier but faster once approved. Use the right tool for the situation; do not assume one is always correct.

    A Working Habit

    The habit that has worked across hundreds of Claude Code sessions: default mode on, Shift+Tab twice into Plan Mode before any session that will (a) touch production state, (b) edit more than 5 files, or (c) run commands that are hard to undo. Shift+Tab again to cycle back to default for everything else.

    The shortcut becomes muscle memory in a week. Once it is muscle memory, the cost of Plan Mode drops to nearly zero, and you can use it liberally on anything that even smells risky.

    Frequently Asked Questions

    What is Plan Mode in Claude Code?

    Plan Mode is a Claude Code setting that forces the agent to produce a written plan and wait for your approval before making changes. It surfaces what the agent intends to do so you can adjust it before any work happens.

    How do I enable Plan Mode in Claude Code?

    Press Shift+Tab twice in the terminal (the first press cycles to Auto-Accept; the second lands on Plan Mode), type /plan as a slash command, or start the session with –permission-mode plan. The status bar shows ⏸ plan mode on when active.

    When should I use Plan Mode?

    For multi-file refactors, database migrations, production code paths, ambiguous instructions, new repositories you don’t know yet, and long-running batch jobs. Skip Plan Mode for single-file tweaks, tight iteration loops, and read-only investigation.

    Does Plan Mode make Claude Code slower?

    Yes, for short tasks — the plan adds latency that is not worth it on quick edits. For long or risky tasks, the plan is faster than fixing mistakes afterward.

    Can I edit the plan before approving it?

    Yes. Tell Claude Code to revise the plan — add steps, remove steps, reorder. Iterating on the plan is much cheaper than iterating after execution.

    Is Plan Mode the same as a sandbox?

    Plan Mode IS a hard read-only sandbox at the tool level — Claude Code cannot write files or run commands while it’s active. But once you approve the plan and exit Plan Mode, the work executes for real. Plan Mode prevents accidental writes during planning; it does not prevent you from approving a bad plan.

    What’s the difference between Plan Mode and per-tool permissions?

    Per-tool permissions ask you to approve each tool use individually as it happens (more granular, slower). Plan Mode batches all intended actions into one plan you approve up front (bulkier, faster once approved).

    The Bottom Line

    Plan Mode is leverage for risky work and friction for everything else. Make Shift+Tab+Shift+Tab muscle memory. Use Plan Mode whenever the cost of an unintended action exceeds the cost of approval — multi-file refactors, production changes, ambiguous specs. Skip it on cheap iteration. That single rule will save you more headaches than any other Claude Code habit.

  • Claude Code Router: Model Routing, OpenRouter & Custom Rules in 2026

    Claude Code Router: Model Routing, OpenRouter & Custom Rules in 2026

    Published: May 25, 2026 | Last fact-check: May 25, 2026 — current model lineup: Opus 4.7, Sonnet 4.6, Haiku 4.5

    Quick Answer

    A Claude Code router is any layer that decides which Claude model handles which request — Opus for hard reasoning, Sonnet for daily work, Haiku for fast cheap tasks. Anthropic ships some built-in routing, but the most leveraged users build their own routing rules on top to optimize cost and latency.

    Built-in routing, manual model selection, and the third-party router landscape below.

    “Claude Code router” is a phrase that means different things to different people in 2026, and the differences matter for what you should actually build or buy.

    It can mean (1) Anthropic’s built-in logic that picks a model when you do not specify one, (2) third-party tools that route between Anthropic models and other LLMs through one Claude Code interface, or (3) custom routing rules you build yourself to match models to tasks. This guide walks through each, when each makes sense, and the trade-offs.

    Why Routing Matters in the First Place

    Claude is not one model. It is a family. As of 2026 the production tiers are roughly:

    • Claude Opus 4.7 — $5/$25 per million tokens. Current flagship. Best for hard, ambiguous, multi-step reasoning and agentic coding.
    • Claude Sonnet 4.6 — $3/$15 per million tokens. The workhorse. Within ~1 point of Opus on coding benchmarks at 40% less cost. Right answer for 80% of daily work.
    • Claude Haiku 4.5 — $1/$5 per million tokens. Fast and cheap. Right answer for high-volume formulaic tasks: classification, extraction, formatting, routing, simple Q&A.

    Output costs 5x input across all three tiers. Prompt caching cuts cached input costs by ~90%. Batch API cuts everything by 50% if you can wait up to 24 hours.

    Using Opus for everything is wasteful. Using Haiku for everything is sloppy. Routing — matching the model to the task — is how you get the best output for the lowest cost. For someone running Claude Code several hours a day, intelligent routing is the difference between a $100/month Max bill and a $1,000/month API bill for the same work.

    Anthropic’s Built-In Claude Code Routing

    When you launch Claude Code without specifying a model, it picks a default. As of 2026 the default for most users is Sonnet, with Opus accessible via flags or settings, and Haiku used internally for some sub-tasks like tool selection and simple file operations.

    You can override the default at session start:

    # Start Claude Code with Opus for a tough refactor
    claude --model claude-opus-4-7   # current flagship
    
    # Or set it in your settings.json
    {
      "model": "claude-sonnet-4-6"  // current workhorse
    }

    Anthropic also routes internally: when Claude Code uses sub-agents for parallel work, it can route those sub-agents to lighter models automatically. This routing is opaque to you and generally well-tuned. You usually do not need to think about it.

    Manual Model Selection: The 80/20 Approach

    For most users, manual routing beats automatic routing. The rule:

    • Sonnet by default. Daily work, content drafts, code edits, file operations, debugging.
    • Opus when you hit a wall. Architectural decisions, hard refactors, ambiguous specs, anything that requires real reasoning.
    • Haiku for batch. Classification, taxonomy assignment, metadata generation, SEO meta descriptions, anything formulaic at volume.

    This 80/20 split is achievable with two or three commands and zero infrastructure. It is the right starting point.

    Third-Party Claude Code Routers

    A small ecosystem has emerged around third-party routers that sit between Claude Code and the model layer. The two most common patterns:

    OpenRouter and Multi-Provider Routers

    OpenRouter is the most widely used third-party router. You point Claude Code at OpenRouter as the API endpoint, and OpenRouter routes your requests to Claude (or to GPT, Gemini, DeepSeek, Llama, etc.). Why use it:

    • You want fallback when Anthropic has an outage.
    • You want to mix Claude with other models on a per-task basis.
    • You want a single billing surface across providers.
    • You want BYOK (bring your own key) routing where you mix your own provider keys.

    The trade-off: latency adds a few hundred milliseconds per call, and some Anthropic-specific features (prompt caching, certain beta tools) work less smoothly through the proxy.

    Custom In-House Routers

    Larger teams build their own routing layer. A typical pattern: a small Python or TypeScript service that inspects the incoming request, applies routing rules (length thresholds, task type detection, cost ceilings), picks a model, and forwards the call to Anthropic.

    This is overkill for most individuals. It pays off when you have:

    • Strict cost controls that need enforcement, not suggestion
    • Multi-tenant usage where different customers get different models
    • Compliance requirements that need request inspection and logging
    • A real engineering team that can maintain the service

    Routing Rules That Actually Work

    If you are going to invest in any routing logic, these are the rules that pay back:

    1. By task type. Code review → Opus. New code generation → Sonnet. Format conversion → Haiku.
    2. By input length. Long context (40K+ tokens) where you need careful reasoning → Opus. Long context where you need extraction → Sonnet with prompt caching.
    3. By cost ceiling. Anything over a threshold token count gets a hard cap or downgrade.
    4. By time of day. Overnight batch jobs route to cheaper models. Interactive daytime work routes to your preferred quality tier.
    5. By failure recovery. If a Sonnet call returns a low-confidence or refused response, retry once with Opus before giving up.

    Most of these rules are five lines of code each. The discipline is more about deciding the rules than implementing them.

    What Anthropic Does Not Yet Ship

    As of writing, Anthropic does not ship a built-in “route this query to the right model” intelligence layer in Claude Code. The model you set is the model you get for the session, with the exception of internal sub-agent routing.

    This is likely to change. The shape of where Claude Code is going — more autonomy, longer sessions, more parallel agents — implies more sophisticated internal routing. For now, the routing decisions worth making are the ones you make yourself.

    Costs: What Routing Actually Saves

    Concrete example. An operator running a Claude Code content pipeline that:

    • Drafts articles (Sonnet): 8,000 input + 4,000 output tokens per article
    • Generates SEO meta and FAQ (Haiku): 2,000 + 500 tokens
    • Reviews and edits (Opus): 10,000 + 2,000 tokens for trickier articles

    Running everything on Opus would roughly triple the cost. Running everything on Sonnet would save vs Opus but produce noticeably weaker meta-generation than Haiku at similar quality. Routing by task type saves real money — often 40-60% versus a single-model approach — without sacrificing output quality.

    When Not to Build a Router

    Routing is leverage when you operate at volume. If you run Claude Code casually — a couple of hours a day, one task at a time — you do not need a router. You need to learn the three models well enough to pick the right one by feel. Build a router only when (a) cost is a real line item in your budget, (b) you are running multiple workflows that have genuinely different model needs, or (c) you want fallback infrastructure for resilience.

    Frequently Asked Questions

    What is a Claude Code router?

    A Claude Code router is any layer — Anthropic’s built-in defaults, a third-party tool like OpenRouter, or custom code — that decides which Claude model handles a given request.

    Does Claude Code have built-in routing?

    Partial. Claude Code picks a default model (Sonnet) and routes internal sub-agent tasks to lighter models. It does not automatically promote your main session to Opus when a task gets hard.

    What’s the difference between OpenRouter and a custom router?

    OpenRouter is a hosted multi-provider gateway with billing and fallback built in. A custom router is something you build to enforce your own rules. OpenRouter is right for most teams. Custom routers are right for teams with strict requirements.

    Should I use OpenRouter with Claude Code?

    Useful if you want fallback, multi-provider mixing, or unified billing. Less useful if you only use Claude and want Anthropic-specific features like prompt caching to work optimally.

    How do I pick the right Claude model for a task?

    Default Sonnet. Opus for hard reasoning, architectural decisions, ambiguous specs. Haiku for high-volume formulaic tasks (classification, formatting, metadata).

    How much can routing save me?

    For volume users, 40-60% versus running everything on Opus, with no measurable drop in output quality if the routing rules are sensible.

    Is there a cost to routing through OpenRouter?

    OpenRouter adds a small markup on token pricing in exchange for the routing and aggregation features. For most users this is acceptable; for very high volume, going direct to Anthropic is cheaper.

    The Bottom Line

    Claude Code routing is leverage when you operate at volume and a distraction when you do not. Start by learning the three Claude models by feel and picking manually. Add OpenRouter if you want fallback. Build a custom router only when cost or compliance actually justifies the engineering. The router is not the goal; the right model on the right task is the goal.

  • Anthropic API Key: How to Get One, Set Up Billing & Keep It Safe (2026)

    Anthropic API Key: How to Get One, Set Up Billing & Keep It Safe (2026)

    Published: May 25, 2026 | Last fact-check: May 25, 2026 against Anthropic Console behavior and current API key format

    Quick Answer

    Get an Anthropic API key at console.anthropic.com → API Keys → Create Key. The key starts with sk-ant- and is shown once — copy and store it in a password manager immediately. Add billing credits before making API calls.

    Full setup, security, and usage walkthrough below.

    An Anthropic API key is the credential that lets your application, script, or tool call Claude programmatically. Whether you are wiring Claude into Claude Code, building an internal agent, or integrating Claude into a SaaS product, the API key is the first step. This walkthrough covers how to create one, how to keep it safe, and the most common mistakes people make in the first 48 hours after they have it.

    What an Anthropic API Key Is (and Isn’t)

    The Anthropic API key authenticates requests to the Anthropic Messages API. It identifies which workspace and organization is making the call, what model permissions it has, and where to bill the token usage.

    What an API key is not: a login. You cannot use an API key to sign into claude.ai. The web interface and the API are separate billing surfaces. Your Pro or Max subscription does not grant API credit by default; API usage requires its own billing setup.

    How to Get an Anthropic API Key

    The process takes three minutes if you already have an Anthropic account, ten if you do not.

    1. Go to console.anthropic.com. This is the Claude Console (sometimes called the Anthropic Console), the developer dashboard separate from the consumer claude.ai interface.
    2. Sign in or create an account. If you already use claude.ai, your login works here. New accounts require email verification.
    3. Click “API Keys” in the left sidebar. You may need to expand the navigation under your workspace name first.
    4. Click “Create Key.” Give the key a descriptive name (e.g., “Claude Code Laptop,” “Production Backend,” “Local Dev”). The name is for your reference only.
    5. Copy the key immediately. Anthropic shows the full key exactly once. After you close the modal, you cannot retrieve it — only revoke it and create a new one.
    6. Store it in a password manager or secret vault. 1Password, Bitwarden, AWS Secrets Manager, GCP Secret Manager — anywhere except a text file on your desktop or a committed .env in a public repo.

    Adding Billing Before You Can Use the Key

    A common surprise: a freshly created API key cannot make calls until you add a payment method and credits to your Anthropic account. The key exists, but every request returns a billing error.

    To add billing:

    1. In the Claude Console, click “Billing” or “Plans & Billing” in the left sidebar.
    2. Add a payment method (credit card; Anthropic also supports invoicing for enterprise).
    3. Either pre-purchase API credits or enable auto-recharge. Most users enable auto-recharge with a low threshold to avoid hitting empty mid-job.
    4. Set a monthly usage limit if you want a safety cap.

    Once billing is set up, your API key works.

    Anthropic API Key Format

    An Anthropic API key starts with the prefix sk-ant- followed by a long alphanumeric string. The full key is roughly 100 characters. If your key does not start with sk-ant-, you have copied something incomplete.

    Different key types exist:

    • Live keys (sk-ant-api...): Production calls, real billing.
    • Admin keys (sk-ant-admin...): Workspace admin operations, not for inference calls.

    Most developers only need a live key.

    Which Claude Models the API Key Works With

    A standard live API key gives you access to the current generation of Claude models:

    • Claude Opus 4.7 (claude-opus-4-7) — current flagship, released April 16 2026. $5/$25 per million tokens.
    • Claude Sonnet 4.6 (claude-sonnet-4-6) — released February 17 2026. $3/$15 per million tokens. The production default for most workloads.
    • Claude Haiku 4.5 (claude-haiku-4-5) — released October 15 2025. $1/$5 per million tokens. Fast and cheap for high-volume work.

    Earlier model versions (Sonnet 4, Opus 4.6, Haiku 3.5, etc.) are still callable by their specific snapshot IDs until Anthropic announces deprecation. Check the deprecation timeline in the Claude Console for any model you depend on in production.

    How to Use the API Key

    You pass the key in the x-api-key header on every request to the Messages API:

    curl https://api.anthropic.com/v1/messages \
      --header "x-api-key: $ANTHROPIC_API_KEY" \
      --header "anthropic-version: 2023-06-01" \
      --header "content-type: application/json" \
      --data '{
        "model": "claude-opus-4-7",
        // Other current options: claude-sonnet-4-6, claude-haiku-4-5
        "max_tokens": 1024,
        "messages": [{"role": "user", "content": "Hello"}]
      }'

    In Python or Node.js, the official SDKs read ANTHROPIC_API_KEY from your environment automatically. You should never hardcode the key in source code.

    Security: How to Not Leak Your Key

    Anthropic API keys leak constantly. Most leaks happen the same way:

    1. Committing the key to a public GitHub repo. The single most common leak. GitHub scans for known credential patterns and notifies Anthropic; your key gets auto-revoked within minutes. You will know because your calls suddenly start failing.
    2. Pasting the key into a shared chat or document. Anyone with access becomes a credential holder.
    3. Putting the key in client-side JavaScript. A browser app shipping its API key to users is giving the key away. Always proxy through a backend.
    4. Logging the key. Any logging system that captures HTTP headers can leak the key. Mask sensitive headers in your logger config.

    The good rule: treat your API key like a credit card number, because that’s what it functions as.

    Rotating an Anthropic API Key

    You should rotate keys quarterly at minimum, and immediately if a key is suspected compromised. Rotation in the Claude Console:

    1. Go to API Keys.
    2. Create a new key with a fresh name (e.g., “Claude Code Laptop 2026 Q3”).
    3. Update your application’s environment variable or secret manager to use the new key.
    4. Verify the new key works.
    5. Revoke the old key.

    The five-minute rotation is far cheaper than dealing with a leaked key that was used by an attacker for hours before you noticed.

    Workspace and Organization Keys

    Anthropic accounts are organized as: Organization → Workspaces → API Keys. Most individuals only use one of each. Teams use multiple workspaces to separate environments (production, staging, dev) or projects.

    Each key belongs to one workspace. Billing rolls up to the organization. If you need separate billing visibility per project, separate workspaces are the lever.

    Monitoring API Key Usage

    The Claude Console shows per-key usage in the “Usage” section. You can see:

    • Token spend per key per day
    • Model breakdown (Opus, Sonnet, Haiku usage)
    • Input vs output token split
    • Cache usage (if you have prompt caching enabled)

    Set up usage alerts in Billing. The Anthropic console can email you when daily or monthly spend crosses a threshold. This is the cheapest insurance against a runaway loop or compromised key.

    Frequently Asked Questions

    How do I get an Anthropic API key?

    Sign in to console.anthropic.com, open API Keys in the sidebar, click Create Key, name it, and copy the key immediately. You cannot retrieve the full key after closing the creation modal.

    Is the Anthropic API key free?

    The key itself is free to generate. Using it costs money — Anthropic bills per token at the API pricing in effect. You must add billing credits before the key works.

    Does my Claude Pro or Max subscription include API credits?

    No. Pro and Max subscriptions cover the chat interface and Claude Code (with usage caps). API usage is billed separately against your Anthropic account.

    What does an Anthropic API key start with?

    Live API keys start with sk-ant-api. Admin keys start with sk-ant-admin. The key is roughly 100 characters long.

    What happens if my Anthropic API key gets leaked?

    Anyone with the key can use it to make API calls billed to your account until the key is revoked. If you suspect a leak, revoke immediately in the Claude Console and check Usage for any suspicious activity.

    Can I use the same API key for Claude Code and my own app?

    You can, but you should not. Use separate keys per environment (Claude Code Laptop, Production Backend, Local Dev). Separate keys make revocation surgical instead of catastrophic.

    Where should I store my Anthropic API key?

    In a password manager (1Password, Bitwarden) for personal use, or in a secret manager (AWS Secrets Manager, GCP Secret Manager, HashiCorp Vault) for production. Never commit it to a repo or hardcode it in source.

    How do I rotate an Anthropic API key?

    Create a new key in the Claude Console, update your application to use the new key, verify it works, then revoke the old key. Rotate quarterly as a baseline.

    The Bottom Line

    Getting an Anthropic API key is a three-minute process. Keeping it safe is a discipline. Use a password manager, rotate quarterly, never put the key in client-side code, and set usage alerts in the Claude Console. Treat the key as production infrastructure, not a developer toy, and it will serve you for years without incident.

  • Claude Code Pricing in 2026: Pro vs Max vs API Costs Explained

    Claude Code Pricing in 2026: Pro vs Max vs API Costs Explained

    Published: May 25, 2026 | Last fact-check: May 25, 2026 against Anthropic’s pricing page. Rates change — always verify at anthropic.com/pricing before commitments.

    Quick Answer

    Claude Code is included with Pro ($20/month), Max 5x ($100/month), Max 20x ($200/month), and Team Premium seats ($100/seat annual, 5-seat minimum). Team Standard does NOT include Claude Code. API-only billing is also available: Sonnet 4.6 at $3/$15 per million tokens, Opus 4.7 at $5/$25, Haiku 4.5 at $1/$5. Most individual developers get the best value from Max 5x at $100/month.

    Full pricing breakdown and which tier fits which user below.

    Claude Code pricing in 2026 is structured around two paths: subscription plans (Pro, Max, Team) that include Claude Code with usage caps, and API-only access where you pay Anthropic per token used. Most users choose a subscription. Heavy enterprise users sometimes choose the API path, and some use both.

    This guide breaks down what each tier actually costs, what you get, and which path makes sense for which kind of user. The price ceiling sits at the Max $200/month plan for individuals, and at custom enterprise contracts above that.

    Claude Code Subscription Plans (2026)

    Anthropic offers four consumer-facing tiers that include Claude Code:

    Plan Price Best For
    Free $0 Trying Claude in the browser; not Claude Code
    Pro $20/month ($17/month annual) Light Claude Code use; focused coding sessions
    Max 5x $100/month (monthly only) Daily Claude Code users; solo devs and operators
    Max 20x $200/month (monthly only) Heavy users; multi-agent workflows; long sessions
    Team Standard $25/seat/mo ($20 annual, 5-seat minimum) Small teams; collaboration but NO Claude Code access
    Team Premium $125/seat/mo ($100 annual, 5-seat minimum) Engineering teams; required for Claude Code on Team plans
    Enterprise Custom Larger orgs with security/compliance needs

    Critical note for Team customers: Team Standard does NOT include Claude Code. You need Team Premium seats ($100/seat annual, $125/seat monthly) for any developer who needs Claude Code access. You can mix Standard and Premium seats on one team — useful when only part of your org codes.

    What Each Tier Actually Includes

    Pro: $20/month

    Pro gives you access to Claude.ai (the chat interface), Claude Desktop, and Claude Code via the CLI. Usage limits are tighter than most committed users prefer — running multi-file refactors or long agent sessions hits the cap quickly. Pro is reasonable as a starting point. It is not adequate for serious daily Claude Code work.

    Max 5x: $100/month

    The 5x designation refers to the rough multiplier on usage limits compared to Pro. For most individual developers who use Claude Code several hours per day, this tier provides enough headroom to work without running into limits constantly. It is the sweet spot for solo operators and small consultancies.

    Max 20x: $200/month

    20x headroom for users who run Claude Code as an always-on agent — overnight jobs, batch processing, multi-hour orchestration. If you find yourself routinely worried about hitting limits on the 5x tier, the 20x tier removes that worry.

    Team Standard: $20-25/seat/month (5-seat minimum)

    Team Standard gives a small group shared admin, SSO, SCIM, shared projects, usage analytics, and centralized billing. It is collaboration infrastructure. Crucially, Team Standard does not include Claude Code access — any developer who needs Claude Code must be on a Premium seat.

    Team Premium: $100-125/seat/month (5-seat minimum)

    Team Premium adds Claude Code to the Team Standard feature set. At $100/seat annual, the per-seat economics match individual Max 5x ($100/month) while adding team management. For an engineering team of 5+ developers using Claude Code daily, Team Premium is a straight upgrade over individual Max subscriptions. You can mix Standard and Premium seats on one team — non-coding teammates can sit on Standard while developers get Premium.

    Claude Code via API: Pay-Per-Token

    The alternative to a subscription is using Claude Code with API credentials directly. You provide an Anthropic API key, and your token usage gets billed against your Anthropic account at API rates.

    API pricing (per million tokens, May 2026 standard rates):

    • Claude Haiku 4.5: $1.00 input / $5.00 output — cheapest current-generation model, ideal for classification, routing, summarization at volume
    • Claude Sonnet 4.6: $3.00 input / $15.00 output — best price-to-quality ratio; the production default
    • Claude Opus 4.7: $5.00 input / $25.00 output — current flagship; complex reasoning and agentic coding
    • Prompt caching: cached reads at 10% of standard input rate — up to 90% savings on repeated context
    • Batch API: 50% off both input and output if you can wait up to 24 hours for results
    • Output:input ratio: consistently 5x across all current-generation models

    One catch with Opus 4.7: list price is identical to Opus 4.6, but Anthropic shipped a new tokenizer that can produce up to 35% more tokens for the same input text. Your effective bill per request can go up even though the rate card did not. Worth knowing before you switch your default model.

    Always check anthropic.com/pricing for current rates — these change.

    For heavy users, the API path can be cheaper than Max, but you give up the predictability of a flat monthly fee. For lighter users, the API path is almost always more expensive than Pro.

    How to Decide: Subscription vs API

    The decision tree is simpler than it looks.

    • You use Claude Code less than an hour a day: Pro at $20/month.
    • You use Claude Code several hours a day: Max 5x at $100/month.
    • You run Claude Code as an unattended agent or for batch work: Max 20x at $200/month, or API with prompt caching enabled.
    • You’re a team of 5+ developers: Team at $30/seat/month, or look at Enterprise.
    • You have unpredictable spikes: API with budget alerts gives you the most control.

    What’s Not Included in Subscription Plans

    Even on Max 20x, a few things still cost extra or fall outside the standard plan:

    • Anthropic API tokens for non-Claude Code use: If you build apps that call the Anthropic API directly, those tokens bill against API credits, not your Max subscription.
    • Third-party MCP servers with their own costs: Many MCP servers are free, but some integrate with paid services that bill you separately.
    • Storage and infrastructure costs: Where you actually run Claude Code (your laptop, your cloud VM) still costs whatever it costs.

    Hidden Value: Why Max Pays Back Quickly

    $100/month sounds steep until you compare it to what Claude Code replaces. For an operator running multi-step content workflows, infrastructure automation, or coding tasks that would otherwise require additional contracting hours, the Max plan typically pays back inside the first week of the month.

    One concrete example: drafting and publishing a single SEO-optimized WordPress article with full schema, taxonomy, internal linking, and AEO/GEO optimization takes a human content team 3-5 hours. Running it through a Claude Code pipeline takes 15 minutes of supervised work. The output quality difference is small; the cost difference is large.

    This is the framing that matters: Claude Code pricing is not “how much does the AI cost.” It is “how much labor does the AI replace.” On that framing, Max 5x is the cheapest line item in most knowledge-work budgets.

    Annual vs Monthly Billing

    Anthropic offers a discount for annual prepayment on Pro and Max tiers — generally around 20% off. If you are confident in your usage pattern, the annual prepay is the right call. If you are still evaluating, monthly gives you flexibility to change tiers as your needs shift.

    Frequently Asked Questions

    How much does Claude Code cost per month?

    Claude Code is included with Claude Pro ($20/month), Max 5x ($100/month), or Max 20x ($200/month). API-only usage is billed per token at separate rates.

    Is there a free version of Claude Code?

    No. Claude Code requires either a paid Claude subscription (Pro, Max, or Team) or API credentials with a funded account. The Claude free tier does not include Claude Code.

    What’s the difference between Max 5x and Max 20x?

    The numbers refer to roughly how much usage you get relative to Pro. Max 5x ($100/month) suits daily developers. Max 20x ($200/month) suits heavy users running agent workflows or long batch jobs.

    Can I use Claude Code with just an API key instead of a subscription?

    Yes. Claude Code accepts an Anthropic API key for authentication. You pay per-token usage at API rates instead of a flat subscription fee.

    Is Claude Code cheaper than GitHub Copilot or Cursor?

    At the entry level, Copilot ($10/month) and Cursor Pro ($20/month) cost less than Max. Per unit of output for serious work, Claude Code on Max often comes out cheaper because of how much it can do per session.

    Does Team pricing include Claude Code?

    Only Team Premium ($100/seat annual, $125/seat monthly, 5-seat minimum) includes Claude Code. Team Standard does NOT include Claude Code. You can mix Standard and Premium seats on the same team so non-coding teammates can sit on Standard while developers get Premium.

    What happens if I hit my Claude Code usage limit?

    On Pro and Max, Claude Code slows or pauses until your usage window resets (typically rolling 5-hour windows on Pro, longer reset cadences on Max). You can upgrade tiers anytime for immediate additional capacity.

    The Bottom Line on Claude Code Pricing

    For most serious users: Max 5x at $100/month. For light users: Pro at $20/month. For heavy agent workloads: Max 20x at $200/month or API with prompt caching. The pricing is competitive with other AI coding tools, and the value relative to labor it replaces makes Max the cheapest line item on most knowledge-work budgets.

  • Installing Claude Code on Windows in 2026: The Native Installer Walkthrough That Actually Works

    Installing Claude Code on Windows in 2026: The Native Installer Walkthrough That Actually Works

    If you have spent any time in the Claude Code subreddit or the GitHub issues tracker in the last six months, you have seen the same Windows install problem cycle through every week. Someone runs the install command, the installer prints “successfully installed,” and then claude --version returns “is not recognized as the name of a cmdlet.” Then come the suggestions: switch to Git Bash, switch to WSL2, reinstall Node, blow away npm. Half of them are wrong for the current installer. This guide is the one I wish existed when I set up Claude Code on a fresh Windows 11 machine this month.

    What changed in 2026: the native installer is now the default

    Anthropic shipped a native installer in 2025 that removed the Node.js dependency entirely. As of May 2026 it is the recommended path on every platform, and npm install of @anthropic-ai/claude-code is still supported but is no longer the primary method Anthropic tests and updates. The native installer downloads a single binary, drops it in ~/.local/bin, registers it on your PATH, and auto-updates in the background.

    What this means in practice on Windows: you do not need Node, you do not need npm, and you do not need WSL2 unless you specifically want a Linux toolchain. PowerShell on Windows 10 or 11 (64-bit) is enough.

    The two commands that actually work

    Open Windows PowerShell — not the x86 version, not Git Bash, not Command Prompt. The x86 entry runs as a 32-bit process and will fail on a 64-bit machine. Git Bash does not support the TTY features Claude Code’s interactive CLI needs, so you will hit the “Raw mode is not supported” error before you finish authenticating.

    Then run:

    irm https://claude.ai/install.ps1 | iex

    That is the entire install. irm is Invoke-RestMethod, iex is Invoke-Expression, and the script handles the binary download, PATH update, and shell hooks. When it finishes, close the terminal and open a new PowerShell window. This is the step everyone skips. The PATH change applies to new shells only — your current session still has the old PATH and will not find the binary.

    In the new window:

    claude --version

    You should see a version string. Then run claude with no arguments from any project directory. The CLI opens your default browser, asks you to sign in to your Anthropic account, and authorizes the local install. Setup, end to end, is under five minutes on a clean machine.

    You need a paid account — the free tier does not include Claude Code

    This catches new users every week. The free Claude.ai plan gets you chat on web, iOS, Android, and desktop. It does not get you Claude Code. To use the terminal CLI you need one of:

    A Pro subscription at $20 per month (or $17 per month billed annually). A Max 5x subscription at $100 per month. A Max 20x subscription at $200 per month. A Team Premium seat at $100 per seat per month annual or $125 monthly, minimum five seats. Or API credits — new API accounts get a small free credit pool to test with, but you are billed per token from there.

    Pro and Max draw from the same token budget as your regular Claude chat usage. The Pro window is roughly 44,000 tokens per five-hour rolling window, which third-party tracking puts at 10 to 40 prompts depending on codebase complexity. Max 5x and 20x scale that linearly. If you are evaluating whether to upgrade, the Pro window will tell you within a week — you either hit the cap during real work or you do not.

    The five errors you will hit, and what fixes them

    “claude is not recognized as the name of a cmdlet.” Your PATH was not updated, or you did not open a new terminal. First, close PowerShell and reopen. If the error persists, the install location exists but your user PATH does not reference it. Run this in PowerShell:

    $currentPath = [Environment]::GetEnvironmentVariable('PATH', 'User')
    [Environment]::SetEnvironmentVariable('PATH', "$currentPath;$env:USERPROFILE\.local\bin", 'User')

    Close the terminal again, open a new one, and claude --version should work.

    “Raw mode is not supported.” You are running Claude Code inside Git Bash. Git Bash does not provide the TTY interface the CLI needs. Switch to Windows PowerShell. Everything you would do in Git Bash you can do in PowerShell; you just need to use Windows path syntax inside the prompt.

    Microsoft Store popup interrupts installation. A popup saying “Get an app to open this ‘claude’ link” sometimes appears during the install on Windows 11. This is a known issue tracked in Anthropic’s GitHub. Dismiss the popup, then re-run the install command. If it persists, install Git for Windows first — the installer registers a couple of URL handlers that resolve the popup.

    Duplicate npm and native installs. If you previously installed via npm and later ran the native installer, you have two binaries on PATH. The native one wins on some shells and the npm one wins on others, which produces confusing version mismatches. Remove the npm install:

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

    Then verify with where.exe claude in PowerShell. Only one path should come back.

    “Invalid code” during OAuth. The browser-based login generates a one-time code that you paste back into the terminal. The code expires fast and is sensitive to copy-paste truncation. Press Enter to retry, complete the browser flow, and paste the code immediately — do not let it sit in your clipboard while you check email.

    What to do in the first session

    Once claude --version returns and the OAuth flow completes, run claude from inside a real project directory — not a fresh empty folder. Claude Code reads context from the surrounding repo, and the first thing it does in a useful session is index files and look for a .clauderules or CLAUDE.md. If you start in an empty directory the first interaction feels useless because there is nothing to ground the model on.

    If you want to lock to a specific model rather than the default, the current strings as of May 2026 are claude-opus-4-7 for the flagship, claude-sonnet-4-6 for the workhorse, and claude-haiku-4-5-20251001 for the fast tier. Sonnet 4.6 is what you want for almost all coding work — it is 30 to 50 percent faster than Sonnet 4.5 and ships with a 1M context window. Reserve Opus 4.7 for the hardest agentic refactors; it eats tokens noticeably faster.

    The setup is not the hard part

    Most of the Windows pain in the Claude Code ecosystem comes from people following install guides written for the npm-era CLI, then layering troubleshooting from the WSL2-era guides on top of that, then asking why nothing works. The current path is one PowerShell command, a new terminal, and a browser login. If you hit one of the five errors above, the fix is short. If you hit something else, the troubleshooting docs at code.claude.com cover it — most novel issues turn out to be PATH or shell-choice problems in a slightly different costume.

    The next thing to figure out is not installation. It is whether your Pro window survives a real week of work, and whether your team needs Premium seats. That math is what determines the actual cost of Claude Code on Windows — not whether the binary runs.