Claude Code CLI Tutorial: The Developer's Complete Guide

Claude Code CLI Tutorial: The Developer's Complete Guide

If you've been writing code the old-fashioned way โ€” toggling between browser tabs, copying answers from ChatGPT, and manually pasting them into your editor โ€” it's time to upgrade. The Claude Code CLI is Anthropic's terminal-based AI coding agent, and after months of using it daily, I can tell you it has fundamentally changed how I build software. This Claude Code CLI tutorial covers everything from installation to advanced workflows that will make you dramatically more productive.

What is Claude Code?

Claude Code is an agentic coding tool that lives directly in your terminal. Unlike browser-based AI assistants or IDE plugins that offer suggestions, Claude Code operates as a full agent. It reads your files, understands your project structure, writes code, runs commands, manages Git operations, and even debugs failing tests โ€” all through natural language conversation.

Think of it as a senior developer pair programmer who sits inside your terminal session. You describe what you want in plain English, and Claude Code figures out which files to read, what changes to make, and how to verify its own work. It launched in February 2025, reached general availability in May 2025, and by late 2025 had become the dominant AI coding tool for terminal-first developers.

What makes Claude Code different from tools like GitHub Copilot or Cursor is its agentic nature. Copilot suggests completions. Cursor edits files you point it to. Claude Code autonomously explores your codebase, makes multi-file changes, runs your test suite, and iterates until things work. You watch, redirect, or walk away entirely.

Why Claude Code Matters for Developers

The developer tooling landscape is crowded, so why should you care about yet another AI tool? Three reasons:

1. Context-aware coding at scale. Claude Code doesn't just see the file you have open. It reads your entire project, understands relationships between modules, and makes changes that respect your existing architecture. When I ask it to add a new API endpoint to my Astro project, it checks my existing route patterns, middleware setup, and database schema before writing a single line.

2. Terminal-native workflow. If you live in the terminal like I do, Claude Code fits perfectly. No context switching to a browser. No copying and pasting. You stay in your shell, your git workflow, your SSH sessions. It uses CLI tools like gh, aws, and docker natively.

3. Automation-ready. With non-interactive mode (claude -p "prompt"), you can integrate Claude Code into CI/CD pipelines, pre-commit hooks, code review automation, and batch processing scripts. It's not just a chat tool โ€” it's programmable infrastructure.

Getting Started with Claude Code CLI

Prerequisites

Before installing Claude Code, you need:

  • Node.js 18+ installed on your system
  • A Claude subscription (Pro at $20/month, or Max/Team for higher usage)
  • A terminal you're comfortable working in (macOS Terminal, iTerm2, Windows Terminal with WSL, or any Linux terminal)

Installation

Install Claude Code globally via npm:

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

Verify the installation:

claude --version

First Launch

Navigate to your project directory and start Claude Code:

cd ~/projects/my-app
claude

On first launch, it will open your browser for authentication. Sign in with your Anthropic account, and you're ready to go. Claude Code automatically indexes your project structure and reads key configuration files.

Your First Interaction

Once inside the Claude Code session, try something practical:

> Read the src/ directory and explain the project architecture. Don't make any changes yet.

Claude Code will explore your files, trace imports, and give you a structured overview. This is the Explore phase โ€” and it's the right way to start every session.

Then move to a real task:

> Add input validation to the POST /api/users endpoint. Check what validation the other endpoints use and follow the same pattern.

Notice I'm not telling Claude Code how to validate. I'm telling it what I want and asking it to match existing patterns. This is key to getting good results.

Deep Dive: Advanced Claude Code Features

CLAUDE.md โ€” Your Project's AI Playbook

The CLAUDE.md file is the single most impactful thing you can configure. Place it in your project root, and Claude Code reads it at the start of every session. Think of it as a persistent system prompt tailored to your codebase.

Here's what a good CLAUDE.md looks like:

# My Project

## Tech Stack
- Framework: Next.js 15 with App Router
- Database: Supabase (PostgreSQL + Auth)
- Styling: Tailwind CSS 4

## Commands
- `npm run dev` โ€” Start dev server
- `npm run test` โ€” Run Vitest test suite
- `npm run lint` โ€” ESLint check

## Code Style
- Use named exports, not default exports
- All API routes return { data, error } shape
- Database queries go in src/lib/queries/

## Architecture Decisions
- Server components by default, 'use client' only when needed
- All forms use server actions, not API routes
- Auth middleware in src/middleware.ts handles all protected routes

What to include: build commands, code conventions that differ from defaults, architectural decisions, and common gotchas. What to leave out: anything Claude can figure out by reading your code. Don't document every function โ€” document the rules.

Custom Slash Commands

Create reusable prompt templates in .claude/commands/. Each markdown file becomes a slash command:

mkdir -p .claude/commands

Create .claude/commands/review.md:

Review the changes in the current git diff. Check for:
1. Security issues (SQL injection, XSS, auth bypasses)
2. Performance problems (N+1 queries, missing indexes)
3. Code style violations per our CLAUDE.md conventions
4. Missing error handling or edge cases

Format your review as a markdown checklist.

Now you can type /review in any Claude Code session and get a consistent code review.

Hooks for CI/CD Integration

Hooks let Claude Code run scripts at specific lifecycle points. Configure them in your .claude/settings.json:

{
  "hooks": {
    "pre-commit": "npm run lint && npm run test",
    "post-edit": "npm run typecheck"
  }
}

This ensures Claude Code runs your linter after every commit and type-checks after editing TypeScript files. It catches issues before they compound.

Non-Interactive Mode for Automation

This is where Claude Code CLI becomes truly powerful. Use it in scripts and pipelines:

# Generate a commit message from staged changes
claude -p "Write a concise commit message for these staged changes" --output-format json

# Batch process: add JSDoc to all utility functions
claude -p "Add JSDoc comments to all exported functions in src/utils/" --allowedTools Edit,Read

# CI pipeline: auto-review pull requests
claude -p "Review the diff in this PR for security issues. Output a JSON report." --output-format json

You can even run multiple Claude Code instances in parallel for large-scale refactoring:

# Process multiple directories concurrently
for dir in src/components src/utils src/hooks; do
  claude -p "Add TypeScript types to all files in $dir" &
done
wait

Model Selection Strategy

Claude Code supports multiple models, and picking the right one matters:

  • Sonnet 4.6: Use for 80% of daily work โ€” feature implementation, bug fixes, writing tests. Fast and cost-effective.
  • Opus 4.6: Reserve for the hard 20% โ€” complex refactoring, architectural decisions, debugging subtle concurrency issues.
  • Haiku: Great for subagent tasks like file exploration and simple searches. Much cheaper.

Toggle models during a session or set defaults in your configuration.

Context Window Management

The most important skill in Claude Code is managing your context window. Performance degrades as it fills up. Here are the rules I follow:

  • Run /clear when switching tasks. Old context from a debugging session will hurt your next feature implementation.
  • Use /compact proactively before hitting 50% context usage.
  • Start separate sessions for unrelated tasks instead of cramming everything into one conversation.
  • Keep prompts specific and concise. "Fix the auth bug in src/middleware.ts where the token refresh fails silently" beats "there's some auth issue somewhere, can you look into it?"

Common Mistakes and How to Avoid Them

Mistake 1: Vague prompts. Saying "make the app better" wastes tokens and produces unfocused changes. Instead, be specific: "Optimize the database queries in src/lib/posts.ts to reduce the number of round trips from 4 to 1 using a join."

Mistake 2: Skipping the explore phase. Jumping straight to "implement feature X" without letting Claude Code understand your codebase first leads to code that doesn't match your patterns. Always start with exploration on new projects.

Mistake 3: Ignoring CLAUDE.md. Without a CLAUDE.md file, Claude Code has to guess your conventions every single session. Spending 15 minutes writing a good CLAUDE.md saves hours of correcting AI-generated code that doesn't follow your style.

Mistake 4: Never clearing context. Running a 2-hour session without clearing context means Claude Code is working with a bloated, degraded window. Clear early, clear often.

Mistake 5: Not using version control. Claude Code makes extensive file changes. Always work on a branch, commit frequently, and don't be afraid to git revert if Claude goes in the wrong direction. It's faster to revert and re-prompt than to manually untangle bad changes.

FAQ

How much does Claude Code cost?

Claude Code requires a Claude Pro subscription ($20/month) at minimum. Pro gives you enough usage for moderate daily coding. For heavy usage, the Max plan ($100/month or $200/month) provides 5-20x more usage. Team and Enterprise plans are available for organizations. There's no separate charge for Claude Code itself โ€” it's included with your subscription.

Can I use Claude Code with VS Code or other IDEs?

Yes. Claude Code has an official VS Code extension that acts as a launcher, letting you open Claude Code sessions directly from your editor. It also works with Cursor and other VS Code forks. However, the core experience is terminal-based. The extension simply provides a convenient way to launch sessions in your project directory โ€” the actual interaction still happens in an integrated terminal pane.

Is Claude Code suitable for production codebases?

Absolutely. I use it daily on production projects including this blog. The key is treating Claude Code like a junior developer with superhuman speed: always review its changes, run your test suite, and use branch-based workflows. With a well-configured CLAUDE.md, hooks for linting and testing, and disciplined context management, Claude Code produces production-quality code consistently. For enterprise teams, Anthropic offers additional security features, audit logs, and usage controls.

Conclusion

The Claude Code CLI tutorial you just read covers the fundamentals through advanced patterns, but the real learning happens when you start using it on your own projects. Install it, write your CLAUDE.md, and start with the explore-plan-code workflow. Within a week, you'll wonder how you coded without it.

The developers getting the most value from Claude Code aren't the ones who type the cleverest prompts โ€” they're the ones who set up their CLAUDE.md properly, manage their context window, and treat the tool as a collaborative partner rather than a magic code generator. Start there, and the productivity gains follow naturally.



More from AI Agents & Automation