claude-mastery-course

# πŸ’» Module 05 β€” Claude Code [![Module](https://img.shields.io/badge/05-Claude_Code-B197FC?style=for-the-badge&labelColor=2a1f1a)](#) [![Time](https://img.shields.io/badge/⏱️_30_min-FF7A4D?style=for-the-badge&labelColor=2a1f1a)](#) [![Level](https://img.shields.io/badge/🌿_Intermediate-FFD23F?style=for-the-badge&labelColor=2a1f1a)](#) [![Requires](https://img.shields.io/badge/πŸ“¦_Node.js_18%2B-6BCF7F?style=for-the-badge&labelColor=2a1f1a)](#) ***Goal:** install Claude Code, run your first session, use it as a real coding partner on a real project.*

5.1 What is Claude Code?

Claude Code is a command-line agent that turns Claude into a developer who lives in your terminal.

πŸ‘€ You  ──describe goal──▢  πŸ’» Claude Code  ──reads + edits──▢  πŸ“‚ Your repo
   β–²                              β”‚
   β”‚                              β”œβ”€β”€runs──▢  βš™οΈ Commands (tests, builds, git)
   β”‚                              β”‚
   └──◀────asks for approvalβ”€β”€β”€β”€β”€β”€β”˜

Unlike Claude.ai (which talks about your code), Claude Code can:


5.2 Installation

Prerequisites

Install via npm

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

πŸ“¦ Official package: @anthropic-ai/claude-code on npm

First run

cd ~/projects/my-app
claude

You’ll be prompted to authenticate on first use.


5.3 The core loop

   πŸ‘€ You describe a goal
            β”‚
            β–Ό
   🧠 Claude plans  ◀──────────────┐
            β”‚                      β”‚
            β–Ό                      β”‚
      Read-only or edit?           β”‚
       β”‚            β”‚              β”‚
       β–Ό            β–Ό              β”‚
  πŸ“– Read       πŸ“ Propose         β”‚
   files         edit              β”‚
       β”‚            β”‚              β”‚
       β”‚            β–Ό              β”‚
       β”‚     πŸ‘€ You approve?       β”‚
       β”‚      β”‚           β”‚        β”‚
       β”‚     yes          no ──▢ πŸ’¬ push back β”€β”€β”˜
       β”‚      β–Ό
       β”‚   ✏️ Apply
       β”‚      β”‚
       β–Ό      β–Ό
   πŸ’¬ Report  ── Done? ──▢ βœ… Finished
                  β”‚
                  no ──▢ (back to plan)

5.4 Your First Session

> Take a look at this repo and give me a 5-bullet summary of what it does and how it's organized.

> The README is out of date β€” it still references the old folder structure.
  Read the actual repo and rewrite the README's "Project Structure" section.
  Show me the diff before applying.

You’ll see Claude plan β†’ read β†’ propose β†’ ask permission β†’ apply.


5.5 The Core Commands

Command What it does
/help Show all commands
/model Switch model (opus, sonnet, opusplan)
/clear Reset the conversation
/init Generate a CLAUDE.md for this repo
/cost Show token usage and cost so far
/exit Quit

CLAUDE.md β€” your project’s system prompt

Run /init once per repo. It creates a CLAUDE.md Claude reads at the start of every session.

# CLAUDE.md

## Project: my-app
A Next.js 14 app with TypeScript, Tailwind, Prisma.

## Conventions
- Components live in `src/components/`, one per file, named exports.
- API routes use Zod for input validation.
- Never commit to `main` directly. Branch from `develop`.

## Commands
- `npm run dev`     β€” dev server
- `npm test`        β€” Jest test suite
- `npm run lint`    β€” ESLint
- `npm run build`   β€” production build (run before claiming "done")

## Don't
- Touch `src/legacy/`
- Modify migrations without explicit instruction

5.6 Plan first, execute second

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  ❌  WITHOUT PLAN MODE                                      β”‚
β”‚                                                             β”‚
β”‚      You: "Add soft-delete to Posts"                        β”‚
β”‚      Claude: *immediately starts editing files*             β”‚
β”‚      You: *15 minutes later*: "no wait, that's wrong way"  β”‚
β”‚      β†’ mess to undo                                         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  βœ…  WITH PLAN MODE                                         β”‚
β”‚                                                             β”‚
β”‚      You: "Plan adding soft-delete to Posts. Don't touch    β”‚
β”‚            files yet."                                      β”‚
β”‚      Claude: *writes a 7-step plan*                         β”‚
β”‚      You: *review, push back on step 4*                     β”‚
β”‚      Claude: *revises plan*                                 β”‚
β”‚      You: "Approved. Execute."                              β”‚
β”‚      β†’ clean implementation                                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Use /model opusplan for an automatic Opus-plans / Sonnet-executes hybrid that saves cost while keeping quality.


5.7 Five Practical Workflows

A β€” Bug fix from a stack trace

> I got this stack trace in production:
[paste]

Track down the cause. Don't change anything yet β€” show me where the
bug is and propose a fix.

B β€” Refactor across files

> We're renaming `User.email_address` to `User.email` everywhere.
Find every usage, plan the migration (including DB), walk me through
it before changing files.

C β€” Add a feature step-by-step

> Add a "soft delete" feature to the Posts model:
1. Add a `deleted_at` column
2. Update queries to exclude soft-deleted rows by default
3. Add a `withDeleted()` helper
4. Update tests

Implement step by step. Run tests after each step.

D β€” Code review your own branch

> Review the changes in the current branch (compare to develop).
Flag anything risky, anything that violates our conventions in
CLAUDE.md, and anything missing tests.

E β€” Onboard to a new repo

> I just inherited this codebase. Spend a few minutes exploring it,
then teach me the architecture in 10 minutes. Start with a high-level
diagram, drill into the 3 most important modules.

5.8 Permissions & Safety

Claude wants to run a command, edit a file, or make a network request
                              β”‚
                              β–Ό
                  Configured as auto-allow?
                   β”‚                    β”‚
              YES (safe ops:       NO (everything else)
              git status, npm           β”‚
              test, etc.)               β–Ό
                   β”‚              πŸ‘€ Asks you first
                   β–Ό                    β”‚
              βœ… Auto-allow              β–Ό
                              You approve?
                              β”‚           β”‚
                             yes          no
                              β–Ό           β–Ό
                          ✏️ Execute   🚫 Skip & explain

[!CAUTION] Never run Claude Code on a directory you can’t afford to lose. Use git. Commit before big agentic runs. You’ll thank yourself.


5.9 Tips From Power Users

1. Always start with a plan.
   It's faster to throw away a bad plan than a bad commit.

2. Keep CLAUDE.md curated.
   Whenever you correct Claude on a convention, add it to the file.

3. Use small models for grunt work.
   Sonnet/Haiku for repetitive edits, Opus for architecture.

4. Commit often.
   After each successful step: git add . && git commit. Easy rollback.

5. Don't watch silently.
   If Claude is going down a wrong path, interrupt. You're the senior.

6. Watch the cost.
   /cost shows token usage. Stay aware if you're paying per token.

5.10 When to Use Claude Code vs. Claude.ai

Task Best tool
πŸ—οΈ Brainstorming architecture πŸ’¬ Claude.ai
✍️ Writing the launch blog post πŸ’¬ Claude.ai
πŸ”§ Single function in isolation Either
πŸ”„ Multi-file refactor πŸ’» Claude Code
πŸ” PR review πŸ’» Claude Code
πŸ› Debugging a flaky test suite πŸ’» Claude Code
🀝 Pair programming on a new feature πŸ’» Claude Code

A lot of pros use both: Claude.ai for thinking, Claude Code for shipping.


βœ… Module 5 Checkpoint

You should now have:

πŸ‘‰ Next up: Module 06 β€” API Development β€” building your own apps powered by Claude.


πŸ“š Further reading


← Previous 🏠 Home Next β†’
Module 04 β€” Claude.ai Features Course README Module 06 β€” API Development