How to use Claude Code CLI: a working developer's setup

6 min read

TL;DR

  • How to use Claude Code CLI begins with npm install -g @anthropic-ai/claude-code and Node 18 or later.
  • Three auth paths are available: Max plan OAuth ($20/month), Anthropic API key (pay-per-token), or Bedrock/Vertex passthrough.
  • The default model as of June 2026 is claude-sonnet-4-6; break-even versus PAYG billing is roughly 33 sessions per month at Sonnet rates.
  • A CLAUDE.md file gives Claude persistent, project-scoped instructions loaded automatically at every session start.
  • Use --print to run Claude Code headlessly in shell scripts and CI pipelines.

The question developers ask after the first demo is the practical one: how do you actually ship something with this?

Knowing how to use Claude Code CLI is less about memorizing flags and more about three early decisions that shape everything else: which authentication path, which billing model, and what persistent context to give the session. From install to a first real file edit takes under ten minutes. Getting the setup to stay useful past day one takes one more step: dropping a CLAUDE.md. This guide covers both, plus the flags, billing math, and the configuration layer that changed significantly between late 2025 and mid-2026.

Getting Claude Code installed and authenticated

One command installs Claude Code globally:

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

The only hard prerequisite is Node 18 or later. On macOS and Linux, any version manager (nvm, fnm, mise) handles that cleanly. Windows requires WSL2 (the CLI does not run on native Windows as of June 2026).

Three authentication paths appear on first launch.

Max plan OAuth. Subscribe to Claude.ai at the $20/month Max tier and authenticate via browser. CLI access was bundled into the Max plan at the November 2025 GA release. No API key to rotate, no per-token billing to track. Rate limits apply, but for most coding sessions they don't become a bottleneck.

Anthropic Console API key. Create a key at console.anthropic.com and export it as ANTHROPIC_API_KEY. Billing is per token. This path fits teams that need cost attribution per project or that run Claude Code in automated pipelines where flat-rate limits would interfere.

Enterprise passthrough. AWS Bedrock and Google Vertex AI both host Claude models. Teams already on either platform can route Claude Code through existing cloud credentials, keeping spend inside their current contracts and governance frameworks.

The first two paths cover the majority of individual and small-team setups. The billing section below has the math to choose between them.

How to use Claude Code CLI on a real project

Navigate to a project directory and run claude. The AI terminal assistant indexes the repository on first start, respects .gitignore, and loads any CLAUDE.md file it finds at the project root. Then type an instruction in plain language:

Rename getUserData to fetchUserProfile across the codebase and update all call sites.

Claude Code reads the relevant files, proposes a diff inline, and waits. Nothing is written until you confirm. The permission model runs in three tiers: read (scans and reports, no writes), write (proposes and applies edits after your approval), execute (runs shell commands such as test suites or linters within the session).

A typical session runs 5-10 turns: a clarifying instruction or two, a diff review, a test run, a confirmation. The default model as of June 2026 is claude-sonnet-4-6, which balances response quality with token throughput for iterative editing work.

How to use Claude Code CLI well comes down to task framing. "Fix the bug in auth.ts" produces diffuse, hard-to-review edits. "The signIn function in auth.ts returns 401 when the email contains uppercase characters. Make the comparison case-insensitive and add a unit test" produces a bounded, reviewable change. Brief this coding agent in your terminal the same way you would brief a junior engineer on a pull request: concrete scope, explicit acceptance criteria, named files.

The CLI flags and slash commands worth memorizing

The full reference is in the Anthropic docs. The subset below is what comes up in daily use.

FlagEffect
--model claude-opus-4-7Override the default model for this session
--print / -pNon-interactive: one response, then exit
--allowedTools "Read,Write"Restrict which permission tiers the session can use
--output-format jsonStructured output for programmatic consumption
--add-dir /other/repoAdd a second directory to the session context

Slash commands are typed inside an active session:

  • /clear resets conversation history without ending the session, useful when a thread has wandered.
  • /compact summarizes conversation history to reduce token usage in long sessions.
  • /cost shows cumulative token consumption and estimated spend for the current session.
  • /model claude-haiku-4-5 switches model mid-session, for example to move to a cheaper model for a simple follow-up.

Headless mode for CI and scripting

The --print flag turns this shell-based code editor into a scriptable subprocess. A minimal example:

echo "List the exported functions in src/api.ts" \
  | claude --print --allowedTools Read --output-format json \
  | jq '.result'

This pattern runs cleanly in GitHub Actions or GitLab CI. Set ANTHROPIC_API_KEY in the runner environment, restrict tools to Read when the step should only report, and pipe JSON output into whatever downstream step consumes it. Combined with --allowedTools Read, the step never writes to disk, which makes it safe to embed in review workflows.

Max plan vs. pay-as-you-go API: which billing model fits your usage

This is the question that appears in nearly every "how to use Claude Code CLI" forum thread, and it has a clear answer once you look at the numbers.

The Max plan at $20/month gives flat-rate access to the CLI, Claude.ai web, and Projects. Rate limits apply but rarely block a standard coding session.

The API key path bills per token. According to the Anthropic pricing page as of early 2026, Sonnet rates are $3 per million input tokens and $15 per million output tokens. A typical 30-turn coding session consumes roughly 100K input tokens and 20K output tokens, which comes to about $0.60. At that rate, the Max plan breaks even at about 33 sessions per month, or one substantial session per working day.

If you use the CLI heavily every weekday, the flat rate wins. If you run a session once or twice a week, pay-as-you-go is cheaper. Two secondary factors often tip the decision:

The Max plan also covers Claude.ai web access and Projects. If you use those features regardless, the marginal cost of CLI access drops to zero. Conversely, if you need Claude Code in a CI pipeline that runs dozens of times a day, the per-token path gives you predictable unit economics and no rate limit exposure.

Enterprise teams routing through Bedrock or Vertex negotiate separate volume pricing, which makes the Max vs. PAYG calculation irrelevant for that segment.

CLAUDE.md, hooks, and what changed in 2025-2026

Two configuration features separate a tuned setup from the default experience.

CLAUDE.md is a plain Markdown file that Claude Code loads automatically at every session start. It holds project-scoped instructions that should always apply: directory layout explanations, commands to run before committing, constraints on what the AI pair programmer may or may not change without explicit confirmation, coding conventions. The hierarchy runs three levels deep: a global file at ~/.claude/CLAUDE.md applies to every project on the machine; a project-level file at .claude/CLAUDE.md or the repo root applies to that repository; a local file at a subdirectory applies to that subtree only.

The November 2025 GA release formalized this hierarchy and added @path/to/file import syntax, so large instruction sets can be split across multiple files without bloating a single document. I've been using this setup since the beta and honestly, it's the difference between Claude Code being a toy and actually useful. The persistent context means you don't have to explain your project structure every single session 😅

Hooks are newer. Configured in .claude/settings.json, they run arbitrary shell commands in response to Claude Code tool events: PreToolUse, PostToolUse, SessionStart, and Stop. Teams use them to run a linter after every file write, block writes to production config files via a pre-check script, log session activity to an audit trail, or inject environment-specific context at session start that doesn't belong in the committed CLAUDE.md.

The hooks system, introduced in late 2025, has become the standard integration point for embedding this command-line coding tool into larger engineering workflows in 2026. The permissions model was also overhauled at the November 2025 GA release: the three-tier read/write/execute structure replaced a simpler allow/deny approach, giving operators finer control over what a session can touch without operator intervention at every step. The hooks documentation covers the full event list and the JSON schema for hook configuration.

Key takeaways

Install with npm install -g @anthropic-ai/claude-code, choose Max plan OAuth for daily use or an API key for pay-as-you-go, then run claude inside a project directory. The billing break-even sits at roughly 33 sessions per month at Sonnet 4.6 rates. A CLAUDE.md file gives the session persistent project context; hooks configured in .claude/settings.json wire it into existing tooling. The CLI reference and hooks documentation are the logical next reads for teams evaluating a wider rollout.


Claude Code CLI is just the tool; the real ship happens when you wire it into your workflow with persistent project context. The production CLAUDE.md template in the kit shows you exactly how to lock down rules, declare your tools, and keep Claude focused on what ships instead of what breaks.

→ Get the welcome kit