devHọc Dev

Week 1 - Day 2: Claude Code Basics: Installation, CLAUDE.md, Permissions, Context Management

Week 1 – Day 2

This lesson combines 4 topics: Installation and your first session, CLAUDE.md and memory, Permission modes and settings, Slash commands, context management and reviewing changes.

Learning Objectives

  • Install Claude Code, log in and run your first session in a repo
  • Understand Claude Code's agent loop: gather context → take action → verify
  • Know which tools Claude Code uses (reading, editing files, running commands, searching, web) and why that changes how you write prompts
  • Write a good CLAUDE.md: short, specific, with build/test commands and reasons
  • Distinguish user, project, local and managed CLAUDE.md; know .claude/rules/ and @import
  • Understand auto memory: what Claude records on its own, where it is stored, how to turn it on and off
  • Know the 6 permission modes and when to use each
  • Write allow / ask / deny rules and understand the evaluation order deny → ask → allow
  • Know the 4 settings files and their precedence
  • Use /context, /compact, /clear, /rewind, /diff, /usage, /model, /effort fluently
  • Have a process for reviewing Claude's changes before committing

Part 1: Installation and your first session

1. Installation

According to the official documentation (as of 11/2026), the recommended method is the native installer, which auto-updates in the background:

# macOS, Linux, WSL
curl -fsSL https://claude.ai/install.sh | bash

# Windows PowerShell
irm https://claude.ai/install.ps1 | iex

Other methods:

MethodCommandNotes
Homebrewbrew install --cask claude-codeStable channel; does not auto-update, run brew upgrade claude-code
WinGetwinget install Anthropic.ClaudeCodeDoes not auto-update
VS Code / Cursor"Claude Code" extensionInline diffs, plan review in the editor
JetBrains"Claude Code" pluginRequires installing the CLI separately
Desktop appCode tab in the Claude appRequires a paid plan
Webclaude.ai/codeRuns in the cloud, no install needed

Verify the installation:

claude --version

Be careful with curl ... | bash commands: only run them when the URL is on the official domain. This is also a security habit you will see again on Day 7.

2. Logging in

The first time you run claude, the tool asks you to log in. There are two groups:

  • Claude plans (Pro, Max, Team, Enterprise...): log in with your claude.ai account and use your plan's quota.
  • Claude Console / API key: billed per token. If ANTHROPIC_API_KEY is already set in your environment, Claude Code asks whether you want to use that key.

Claude Code can also run via Amazon Bedrock, Google Cloud and Microsoft Foundry for organizations that want to keep billing and data within their own cloud (see the docs).

3. Your first session

cd ~/code/acme-shop
claude

Some useful opening prompts when facing an unfamiliar repo:

Explain the overall architecture of this repo: the main directories, the request
flow from HTTP to the database, how to run the tests. Cite specific files for each point.
Find where shipping fees are calculated. List the related functions and existing tests.
Don't change anything yet.

Other ways to start:

CommandEffect
claude "question"Open an interactive session with a first prompt
claude -p "question"Run non-interactively, print the result and exit (Day 3, Part 4)
claude --continueContinue the most recent conversation in this directory
claude --resumePick an old session to continue (inside a session: /resume)
claude --permission-mode planStart in plan mode (Part 3)

4. How Claude Code Works

Claude Code is an agent: it does not just answer, it calls tools on its own to gather information, take action, then check the result, repeating until done.

┌──────────────┐┌──────────────┐┌──────────────┐│Gather│────▶│Takeaction│────▶│Verify││context││││results││Read,Grep,││Edit,Write,││Bash:test,││Glob,Bash││Bash││lint,tsc│└──────────────┘└──────────────┘└──────┬───────┘▲│└────────────────notdone───────────────┘

Main tool groups:

GroupExamplesAsks for permission by default?
Read, searchRead, Grep, GlobNo, within the working directory
Edit filesEdit, WriteYes (in Manual mode)
Run commandsBashYes, except for a built-in set of read-only commands
WebWebFetch, WebSearchYes, except for some pre-approved documentation domains
ExtensionsMCP tools, subagents, skillsDepends on configuration

This changes how you write prompts compared to claude.ai:

  • No need to paste code: name the file or describe it, and Claude reads it itself.
  • Give a verification command: "run npm test -- cart" so Claude can confirm on its own.
  • Limit the scope: Claude can edit many files; state clearly what it may change and what it must not touch.

Part 2: CLAUDE.md and memory

1. Why you need CLAUDE.md

Every Claude Code session starts with an empty context. Without CLAUDE.md, you have to repeat the same information every session: what the test command is, whether to use pnpm or npm, naming conventions, which directories must not be edited.

CLAUDE.md is a markdown file Claude Code loads into context at the start of every session. It is the "onboarding doc" for Claude.

2. Locations and scopes

According to the Memory docs (as of 11/2026):

TypeLocationUsed forWho sees it
Managed policymacOS /Library/Application Support/ClaudeCode/CLAUDE.md, Linux/WSL /etc/claude-code/CLAUDE.md, Windows C:\Program Files\ClaudeCode\CLAUDE.mdOrganization-wide standards, deployed by ITEveryone on the machines it is deployed to
User~/.claude/CLAUDE.mdPersonal preferences for all projectsOnly you
Project./CLAUDE.md or ./.claude/CLAUDE.mdProject architecture, commands, conventionsThe whole team (committed to git)
Local./CLAUDE.local.mdPersonal notes for this project (sandbox URLs, test data)Only you (add to .gitignore)

How they are loaded:

  • CLAUDE.md and CLAUDE.local.md in the working directory and every parent directory are loaded at startup, in order from the root down. The files are concatenated, not overriding each other.
  • CLAUDE.md in a subdirectory is loaded on demand, when Claude reads or edits files in that directory.
  • If a repo already has an AGENTS.md for other coding agents, Claude Code can read that file (see the docs on AGENTS.md).

3. Writing a good CLAUDE.md

Example for acme-shop:

# acme-shop

E-commerce API: Node 22, TypeScript, Fastify, Prisma (PostgreSQL), Vitest.

## Commands
- Install: `pnpm install` (don't use npm: the lockfile is pnpm-lock.yaml)
- Test one module: `pnpm test -- src/cart`
- Full check before reporting done: `pnpm lint && pnpm typecheck && pnpm test`
- Migration: `pnpm prisma migrate dev --name <name>`; don't hand-edit files in prisma/migrations/

## Architecture
- src/routes: only parse the request and call a service; no business logic
- src/services: business logic, never imports from src/routes
- Money is stored as integers (VND), never float, because rounding errors have caused wrong invoices

## Conventions
- Log with `req.log` (pino) to get the request ID; don't use console.log
- User ID always comes from `req.session.userId`, never from body or query
- Business errors throw `AppError(code, message)`; error codes are listed in src/errors/codes.ts

## Don't
- Don't edit files in src/generated/ (generated from OpenAPI)
- Don't add new dependencies without asking

Principles drawn from the docs and experience:

PrincipleWhy
Short — the docs recommend under 200 lines per fileLong files cost context in every session and reduce adherence
Specific, verifiable — "use 2 spaces" rather than "format nicely"Vague instructions don't change behavior
Include the reason — "no float because of rounding errors"Claude applies it correctly even in cases not listed
No contradictions — periodically review nested CLAUDE.md filesWith two conflicting instructions, Claude may pick either one
Don't repeat what can be read from the code — obvious directory structure, README contentWastes context
No secrets — no tokens, passwords, sensitive internal URLsThe project CLAUDE.md is committed and read by everyone and every tool

Important: CLAUDE.md is context, not enforced configuration. Claude tries to follow it, but nothing guarantees it. Anything that must be enforced (blocking edits to .env, blocking rm -rf) should use a permission rule or a hook (Part 3, Day 3).

4. Quick start with /init

Run /init in a repo: Claude analyzes the codebase and creates a starter CLAUDE.md with the build and test commands and conventions it finds. If a CLAUDE.md already exists, /init suggests improvements instead of overwriting it. Always read and edit the generated version: it is usually longer than needed and may guess conventions wrong.

5. Imports and .claude/rules/

Imports: CLAUDE.md can load other files using the @path/to/file syntax:

See the release process: @docs/release.md
API conventions: @docs/api-conventions.md

.claude/rules/: for large projects, split instructions into multiple files by topic (testing.md, api-design.md...). A rule can be scoped by path with paths: frontmatter so it is only loaded when Claude works with matching files. Personal rules for all projects go in ~/.claude/rules/.

Note: rules with paths: and CLAUDE.md files in subdirectories are loaded on demand, so they may be summarized away after compaction; the CLAUDE.md at the project root is reloaded from disk. Mandatory rules that must survive compaction belong in the root CLAUDE.md.

6. Auto memory

Besides CLAUDE.md (which you write), Claude Code also has auto memory (which Claude writes itself) while working:

CLAUDE.mdAuto memory
Who writes itYouClaude
ContentInstructions, rulesThings learned: your preferences, feedback you gave, project decisions, where to find information
ScopeProject, user, organizationPer repo, shared across worktrees, only on this machine
Loaded intoEvery sessionEvery session (first 200 lines or 25KB of MEMORY.md)

Details (as of 11/2026):

  • Stored in ~/.claude/projects/<project>/memory/, with MEMORY.md as the index plus topic files.
  • On by default for local sessions; toggle it with /memory, or set "autoMemoryEnabled": false in settings, or the environment variable CLAUDE_CODE_DISABLE_AUTO_MEMORY=1.
  • When you say "remember to always use pnpm", Claude saves it to auto memory. To make it a shared team rule, say "add this to CLAUDE.md" or edit the file yourself.

Auto memory is plain markdown files: review it periodically with /memory. A wrong memory ("the project uses MySQL" when it has moved to PostgreSQL) will silently affect every later session.


Part 3: Permission modes and settings

1. The six permission modes

According to Permission modes (as of 11/2026):

ModeBehaviorWhen to use
default (shown as Manual)Asks for permission the first time each tool is used (editing files, running commands)Unfamiliar repos, sensitive work, while learning
acceptEditsAuto-accepts file edits and common filesystem commands (mkdir, touch, rm, mv, cp, sed...) for paths inside the working directory; other commands and network access still askWork with a clear plan, where you will review the diff afterwards
planOnly reads files and runs read-only commands to explore, does not edit sourcePlanning before making changes (Day 3)
autoRarely asks; a background classifier checks whether actions (shell commands, network requests) match your requestLong tasks where you want fewer interruptions, with an eligible account and model
dontAskAutomatically denies everything that would otherwise ask; only runs what is allowed or needs no permissionCI, unattended runs with a strict allow-list
bypassPermissionsSkips almost all permission promptsOnly in isolated environments (containers, disposable VMs)

Switching modes:

  • In a terminal session: Shift+Tab cycles through them. From auto, the first press goes to default, then default → acceptEdits → plan. bypassPermissions only appears if you enabled it at startup; dontAsk is not in the cycle.
  • At startup: claude --permission-mode plan (values: default, acceptEdits, plan, auto, dontAsk, bypassPermissions).
  • Persistent default: permissions.defaultMode in settings. Note: auto and bypassPermissions cannot be set from project or local settings, only from user settings, managed settings or a flag.

According to the docs, since Claude Code v2.1.283, interactive sessions in the terminal and VS Code start in auto by default when the account and model are eligible; while claude -p (since v2.1.302) starts in Manual if nothing sets the mode. Check the current mode in the status bar.

Protected paths: writes to .git, .claude, .vscode, .mcp.json, .bashrc, .zshrc, .npmrc... are never auto-approved, except in bypassPermissions. This is why bypassPermissions should only be used in throwaway environments: one wrong command could modify your git or shell configuration.

2. Permission rules

A rule has the form Tool or Tool(specifier), in three kinds:

  • allow: use without asking
  • ask: always ask
  • deny: forbidden

Evaluation order: deny → ask → allow; the first matching rule decides, and specificity does not change the order. Consequence: deny: Bash(aws *) blocks even aws s3 ls despite allow: Bash(aws s3 ls). An allow cannot "punch a hole" in a deny.

Syntax examples (from the Permissions docs):

RuleMeaning
Bash(npm run build)Exactly the command npm run build
Bash(npm run test *)Any command starting with npm run test
Bash(git log *)Only git log ... commands
Bash(git *)Every git command, including git push --force. Be careful
Read(./.env)Reading the .env file in the current directory
WebFetch(domain:example.com)Fetching from example.com
BashEvery Bash command; as a deny rule, Claude no longer sees this tool

Common wildcard traps:

  • Put * after the subcommand: Bash(git log *) is much safer than Bash(git *).
  • The space before * matters: Bash(git diff *) matches git diff main, while Bash(git diff*) also matches git diff-index.

Permission rules are enforced by Claude Code, not by the model. Writing "don't read .env" in CLAUDE.md is just a note. deny: Read(./.env) is a real barrier.

Scope of Read / Edit rules (per the docs, as of 11/2026):

  • They apply to the built-in file read/edit tools (Read, Grep, Glob, Edit, Write) and to file commands Claude Code recognizes in Bash such as cat, head, tail, sed, tee, plus the redirects > file, < file.
  • They do not apply to commands that read files without naming them (for example grep -r pattern .) or to scripts that open files themselves (node -e "...", python script.py). To block at the operating-system level for every process, use sandboxing.
  • Paths use gitignore syntax: Read(./secrets/**) for a whole directory. To forbid edits to an area, use Edit(...), for example Edit(./src/generated/**); rules of the form Write(path) never match.
  • A .claudeignore file has no effect; convert its contents into Read deny rules.

3. The four settings files and their precedence

ScopeFileAffectsUsed for
User~/.claude/settings.jsonYou, all projects on the machinePersonal preferences, your own rules
Shared project.claude/settings.jsonEveryone on the project (committed to git)Shared permissions, hooks, project env
Project local.claude/settings.local.jsonYou, only this project (not committed)Personal overrides; where "Yes, and don't ask again" choices are saved
Managedmanaged-settings.json, MDM, configuration from the admin consoleEveryone the organization deploys toSecurity and compliance policies

Precedence for the same key (highest to lowest): managed → command line (--settings) → project local → shared project → user.

Lists such as permissions.allow, however, are merged across files rather than overridden. And because deny is always evaluated first, a deny in any scope beats an allow in another scope.

Example .claude/settings.json for the acme-shop team:

{
  "$schema": "https://json.schemastore.org/claude-code-settings.json",
  "permissions": {
    "allow": [
      "Bash(pnpm lint)",
      "Bash(pnpm typecheck)",
      "Bash(pnpm test *)",
      "Bash(git status)",
      "Bash(git diff *)",
      "Bash(git log *)"
    ],
    "ask": [
      "Bash(git push *)"
    ],
    "deny": [
      "Read(./.env)",
      "Read(./.env.*)",
      "Read(./secrets/**)"
    ]
  }
}

Two notes from the docs:

  • Settings files are strict JSON: // comments or trailing commas are syntax errors.
  • permissions.allow in a repo's .claude/settings.json only takes effect after you accept workspace trust for that directory. This is a safeguard when cloning an unfamiliar repo: a repo cannot grant permissions to itself.

Check which files were loaded: /status. Manage rules interactively: /permissions.


Part 4: Slash commands, context management and reviewing changes

1. Everyday commands

Excerpted from the Commands reference (as of 11/2026; type / to see the full list on your machine):

CommandEffect
/initCreate a starter CLAUDE.md for the project
/memoryOpen and edit CLAUDE.md files, toggle and view auto memory
/contextView context usage by category, with optimization suggestions
/compact [instructions]Summarize the conversation to free up context, optionally with a focus
/clearStart a new conversation with an empty context
/rewind (or Esc twice when the input is empty)Go back to an earlier checkpoint: restore code, conversation, or summarize from a point
/diffView changes in the working tree, including edits Claude made
/reviewReview the current diff, a PR, branch or path (alias of /code-review)
/security-reviewAnalyze changes on the current branch for security vulnerabilities
/modelSwitch models (left/right arrows adjust effort on supported models)
/effortSet effort: low to xhigh, max, or auto
/usage (alias /cost)View session cost, plan quota and statistics
/permissionsManage allow/ask/deny rules
/plan [description]Enter plan mode straight from a prompt
/resumeReopen an old session
/hooks, /mcp, /skillsView hooks, MCP servers, skills configuration (Day 3)

2. Context management

Claude Code's context contains: the system prompt, CLAUDE.md, auto memory, MCP tool names, skill descriptions, every file read, every command output, every message. It fills up faster than you think, especially when Claude reads large files or runs commands that print a lot of logs.

Sessiontimeline───────────────────────────────────────────────────────────────▶│startup│taskA│taskB(unrelated)│CLAUDE.md,│reads,edits,test││memory,tools│logspileup│←/clearhere│││││contextnearlimit│││→/compactfocus│

Strategies:

SituationWhat to doWhy
Switching to an unrelated task/clearOld context adds noise and costs tokens every turn
Long task, context nearly full, need to keep the thread/compact keep the schema decisions and the still-failing testsA focused summary beats letting auto-compact guess
Claude goes the wrong way 3 turns in a row/rewind to before it went wrong, rewrite the prompt more clearlyA wrong direction left in context will pull Claude back to it
Need to explore many files just to answer one questionDelegate to a subagent (Day 3)The files read stay in the subagent's context; only the summary comes back
Unclear why the context is full/contextSee what takes the most: files, MCP tools, memory

Claude Code auto-compacts when it nears the limit. After compaction, the root CLAUDE.md and auto memory are reloaded from disk; instructions you only gave in the conversation survive only in the summary. Put important rules in CLAUDE.md, don't just say them in chat.

3. Checkpoints and rewind

Every prompt you send creates a checkpoint that saves file state before Claude edits. /rewind (or Esc twice when the input is empty) opens a menu with options: restore code and conversation, conversation only, code only, or summarize from a point.

Limitations to know (per the Checkpointing docs):

  • Files changed only by Bash commands (for example sed -i, migration scripts) are not tracked.
  • Edits made by most subagents are not restored.
  • Changes you make yourself outside Claude Code are usually not recorded.
  • Checkpoints do not replace git. Commit often to have reliable points to return to.

4. Reviewing changes before committing

Claude writes code fast; the real value lies in your careful review. Suggested process:

  1. See the big picture: /diff or git diff --stat. Are the number of files and lines reasonable for the request? A request to fix one function with a diff touching 14 files is a sign to stop.
  2. Read each hunk: watch for unrelated files, tests modified to pass, new // TODOs, commented-out code, new dependencies in package.json.
  3. Run the checks: lint, type check, tests. Don't just trust Claude's "all tests pass"; run them yourself or look at the real output.
  4. Ask Claude to explain: "Why change this line? Is there a way with fewer changes?"
  5. Second review from a different angle: /review or /security-review, or a new session that doesn't carry the assumptions of the session that wrote the code.
  6. Commit in logical units: one commit per meaningful change, with a message describing "why".

Red flags when reviewing code Claude wrote:

Red flagPossibly
Test expected values changed to make it passHiding a bug instead of fixing it
New empty try { ... } catch {}Swallowing errors
New as any, @ts-ignore, eslint-disableDodging the type check instead of fixing the types
New package nobody asked forUnnecessary or hallucinated dependency
Function duplicating an existing helperClaude didn't search for existing code

Review Questions

  1. Why do prompts in Claude Code usually not need pasted code like on claude.ai, but should include a verification command?

    Show answer

    Claude Code has the Read, Grep and Glob tools to read files in the repo itself, so you only need to name the file or describe it. It can also run commands, so with a specific test/lint/type check command, Claude checks the result itself and fixes things before reporting done. The gather → act → verify loop is only complete when the verify step has a measurable tool.

  2. Distinguish ./CLAUDE.md, ./CLAUDE.local.md and ~/.claude/CLAUDE.md. Where should "my staging environment URL" go?

    Show answer

    ./CLAUDE.md holds the project's shared instructions, committed to git for the whole team. ./CLAUDE.local.md holds personal notes for this project, added to .gitignore. ~/.claude/CLAUDE.md holds personal preferences that apply to all projects. A personal staging URL belongs in CLAUDE.local.md. If that URL is sensitive, consider not putting it in any file that Claude and other tools all read.

  3. A CLAUDE.md is 900 lines long and copies the entire README and directory structure. Name 3 problems and how to fix them.

    Show answer

    (1) It costs context in every session. (2) Adherence drops when the file is long; the docs recommend under 200 lines per file. (3) It repeats what Claude can read from the code itself, which easily goes stale and contradicts. Fix: keep the build/test commands, non-obvious conventions with their reasons, and a "don't" list; move parts relevant to only one area into .claude/rules/ with paths:, or import selectively.

  4. Is writing "Never read the .env file" in CLAUDE.md enough to protect secrets? What else should you do?

    Show answer

    Not enough. CLAUDE.md is context; the model tries to follow it but nothing enforces it. You need deny permission rules such as Read(./.env) and Read(./.env.*), enforced by Claude Code regardless of what the model decides; these rules cover both the file tools and commands like cat, head in Bash. But they cannot block scripts that open files themselves, so add sandboxing if you want blocking at the operating-system level, and ideally don't keep real secrets in the working directory at all.

  5. How does auto memory differ from CLAUDE.md? Why should you review auto memory periodically?

    Show answer

    CLAUDE.md is written by you, contains instructions, and can be shared via git. Auto memory is recorded by Claude while working (preferences, feedback, project decisions), stored locally in ~/.claude/projects/<project>/memory/, shared across worktrees of the same repo but not synced between machines. Review it because a wrong or stale memory will silently affect every later session; use /memory to view and edit it.

  6. A team has allow: Bash(git *) in .claude/settings.json. What is the risk and how should it be fixed?

    Show answer

    Bash(git *) allows every git command without asking, including git push --force, git reset --hard, git clean -fdx. Narrow it by subcommand: allow Bash(git status), Bash(git diff *), Bash(git log *); put git push in ask; deny destructive commands if needed. The docs stress putting * after the subcommand.

  7. User settings have allow: Bash(npm publish), project settings have deny: Bash(npm publish *). What happens when Claude runs npm publish --tag beta?

    Show answer

    It is blocked. Rules are evaluated in the order deny → ask → allow regardless of which file they are in, and a deny in any scope beats an allow in another scope. Moreover, the allow Bash(npm publish) only matches the exact command with no arguments, not npm publish --tag beta.

  8. Why should bypassPermissions only be used in a container or disposable VM?

    Show answer

    This mode skips almost all permission prompts, including writes to protected paths such as .git, .claude, .bashrc, .npmrc. One wrong command (from a model misunderstanding or a prompt injection) could delete data, modify shell configuration, or push code to a remote. In an isolated environment, the maximum damage is limited to that environment.

  9. When do you use /clear, and when /compact?

    Show answer

    /clear when switching to an unrelated task: the old context only adds noise and costs tokens. /compact when you are still on the same long task and the context is nearly full: the summary keeps the thread of work. Add a focus, for example /compact keep the schema decisions and the still-failing tests, so the summary keeps exactly what is needed.

  10. After /compact, Claude "forgets" the rule "don't edit src/generated" that you stated at the start of the session. Why, and how do you prevent it?

Show answer

Instructions given only in the conversation get folded into the summary and may lose detail. The CLAUDE.md at the project root is reloaded from disk after compaction. Important rules must live in CLAUDE.md; if enforcement is needed, add a permission deny for Edit on src/generated/** or a PreToolUse hook.

  1. Claude ran sed -i on 20 files and you want to go back. Can /rewind restore them?
Show answer

Not reliably. Checkpoints track edits made through Claude's file editing tools. Files changed only by Bash commands are not tracked, except files Claude had already edited with the Edit tool earlier in the session. The safe approach is git: commit or stash before letting Claude run bulk edit commands, then use git diff / git checkout to go back.

  1. List 4 red flags when reviewing a diff created by Claude.
Show answer

Test expected values changed to make it pass; empty catch {} swallowing errors; new as any, @ts-ignore, eslint-disable; new dependencies nobody asked for; helpers duplicating existing code; a diff touching many files unrelated to the request.

  1. Why can't the .claude/settings.json of a freshly cloned repo grant allow permissions to Claude by itself?
Show answer

Claude Code only applies permissions.allow and additionalDirectories from project settings after you accept workspace trust for that directory. This is a safeguard: someone else's repo cannot grant itself permission to run arbitrary commands on your machine. Deny and ask rules apply immediately because they only narrow permissions.

Hands-on Exercises

Exercise 1: Install and explore an unfamiliar repo

Install Claude Code and clone a medium-sized open-source repo you have never read. In Manual mode, ask Claude 3 questions: the overall architecture, the flow of one specific request, how to run the tests. Ask it to cite files for each point.

Expected output: a 1-page note; mark which claims you verified yourself in the code and which claims were wrong.

Exercise 2: Write a CLAUDE.md for your project

Run /init on a project you are working on. Edit the generated version following the principles in Part 2: under 80 lines, with specific test commands, at least 3 conventions with reasons, and a "Don't" section.

Expected output: the edited CLAUDE.md; a list of what you removed from the /init version and why.

Exercise 3: Test the rule evaluation order

In a test repo, create .claude/settings.local.json with allow: ["Bash(git log *)"] and deny: ["Bash(git *)"]. Ask Claude to run git log --oneline -5.

Expected output: observe that the command is blocked; explain it using the deny → ask → allow order; fix the rules so git log runs while git push is still blocked.

Exercise 4: Block reading secrets

In a test repo, create a fake .env file with API_KEY=sk-ant-test-placeholder (do not use a real key). Add the deny rule Read(./.env), then ask Claude in turn: (a) "read .env and tell me the API key", (b) "run cat .env", (c) "write a one-line Node script that reads .env and prints it".

Expected output: a 3-row table recording which requests were blocked and which were not; an explanation based on the scope of the Read rule (file tools and recognized file commands are blocked, scripts that open files themselves are not); a proposal for the next layer of protection (sandboxing, not keeping real secrets in the working directory).

Exercise 5: Measure and clean up context

In a long session (reading many files, running tests many times), run /context and note which part takes the most. Try a focused /compact, then run /context again.

Expected output: two screenshots or notes of /context before/after; observations on which parts shrank.

Exercise 6: Rewind and review

Give Claude a small refactoring task in acceptEdits. When it is done, review with /diff; deliberately /rewind to before the edits, rewrite the prompt with tighter constraints, and compare the two diffs.

Expected output: two diffs; a table comparing the number of files, number of lines, and whether there were out-of-scope changes.

References


Next lesson →