🎯 SQL Practice

Claude Code (CLI Agent)

The terminal-based AI agent that reads your codebase, writes files, runs tests, and commits to Git.

What is Claude Code?

Claude Code is Anthropic's agentic coding CLI — a terminal-based AI coding assistant that reads your actual codebase, writes files, runs commands, and iterates on solutions. Unlike pasting code into Claude.ai, Claude Code operates inside your project directory with full context of every file.

It's not just autocomplete. Claude Code can:

CLAUDE CODE VS CLAUDE.AI Claude.ai is a web UI for conversations. Claude Code is a CLI agent that acts on your codebase. Use Claude.ai for learning, design discussions, and writing. Use Claude Code when you need it to actually touch files.

Installation

Prerequisites

Step 1: Install globally

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

Step 2: Set your API key

Terminal — add to ~/.bashrc or ~/.zshrc
export ANTHROPIC_API_KEY="sk-ant-api03-..."
source ~/.zshrc   # reload

Step 3: Launch inside your project

Terminal
cd ~/my-project
claude          # starts interactive session
claude "fix the failing tests in test_orders.py"   # one-shot task
claude --model claude-opus-4-5 "refactor auth module"  # specify model

The Claude Code interface

After running claude, you see an interactive prompt:

What the Claude Code session looks like
✓ Authenticated | claude-sonnet-4-5 | /my-project
  Context: 23 files, 4,821 tokens

> Add input validation to the /api/orders POST endpoint.
  Validate: customer_id is integer, amount is positive decimal, 
  items is non-empty list. Return 422 with error detail on failure.

  ✦ Reading: src/api/orders.py, src/models/order.py, tests/test_orders.py
  ✦ Writing: src/api/orders.py
  ✦ Writing: tests/test_orders.py
  ✦ Running: python -m pytest tests/test_orders.py -v

  ✓ All 8 tests pass. Changes made:
    - Added Pydantic model OrderRequest with validators
    - Added 422 error handler returning field-level error details
    - Added 4 new test cases for validation edge cases

Key commands inside a Claude Code session

CommandWhat it does
/helpShow all slash commands
/clearClear context and start fresh
/compactSummarize history to save tokens
/memoryView and edit Claude's memory about your project
/mcpList connected MCP servers and their tools
/costShow token usage and cost for this session
/modelSwitch model mid-session
/exit or Ctrl+CEnd session

The CLAUDE.md file — your project memory

Create a CLAUDE.md file in your project root. Claude Code reads this automatically at the start of every session. It's your project's "onboarding doc for AI":

CLAUDE.md — recommended structure
# Project: Orders API

## Stack
- Python 3.12, FastAPI 0.110, PostgreSQL 15
- Testing: pytest + httpx for async tests
- Linting: ruff, black (line length 88)

## Conventions
- snake_case for all names
- BIGINT for all IDs, NUMERIC(12,2) for money — never FLOAT
- Every endpoint must have a corresponding test
- Error responses: {"error": "message", "field": "field_name"}

## Commands
- Run tests: `pytest tests/ -v`
- Start dev server: `uvicorn src.main:app --reload`
- Lint: `ruff check . && black --check .`

## Important files
- src/main.py — FastAPI app setup and router registration
- src/models/ — SQLAlchemy models
- src/api/ — route handlers (one file per resource)
- tests/ — mirrors src/api/ structure

Agentic mode — let Claude work autonomously

Use --dangerously-skip-permissions flag (only in safe environments like Docker) to let Claude make all file changes without confirming each one:

Terminal — autonomous mode for CI/batch tasks
claude --dangerously-skip-permissions   "Add comprehensive docstrings to all functions in src/api/"
USE WITH CARE In agentic mode, Claude can delete files, run arbitrary commands, and push to Git. Always run this in a Docker container or a git branch — never on a live production codebase.

Claude Code with VS Code and JetBrains

Claude Code has extensions for both major IDEs:

Both extensions let you open a Claude Code session with the current file or selection in context, and show diffs of proposed changes before applying.

Real-world use cases for data engineers

COST TIP Claude Code sessions consume API tokens. For long agentic sessions, use /compact frequently to summarize context and reduce token usage. For exploration and design discussions, use Claude.ai (flat subscription) instead of Claude Code (pay per token).