Skip to content

Lesson 13 ยท Claude Code and Agents

CLAUDE.md and Permission Modes

Give Claude Code lasting project instructions with CLAUDE.md and auto memory, then control what it may do with permission modes and allow, ask and deny rules.

Two settings shape almost every Claude Code session: what it knows about your project and what it may do without asking. The first comes largely from instruction files, the second from permissions. Keep them separate in your mind, because instructions are guidance and permissions are enforcement.

CLAUDE.md: instructions you write

Each session starts with a fresh context window. A CLAUDE.md file is read at the start, so you do not have to repeat yourself. If your repository uses an AGENTS.md file for coding agents, recent versions can read it in place of CLAUDE.md. By default this happens only when there is no CLAUDE.md or CLAUDE.local.md in your working folder or above it. A CLAUDE.md can also import it with @AGENTS.md.

Location Scope
./CLAUDE.md or ./.claude/CLAUDE.md The project, shared through version control
./CLAUDE.local.md Your private notes for this project; keep it out of Git
~/.claude/CLAUDE.md Your preferences for all projects
Managed policy file Set by an organization for its users

Run /init to generate a starting file from your codebase, then edit it. /memory lets you edit these files and manage auto memory.

A focused example:

MARKDOWN
# Project notes

## Commands
- Install: `npm install`
- Test: `npm test`
- Lint: `npm run lint`

## Conventions
- Use 2-space indentation.
- API handlers live in `src/api/handlers/`.
- Every bug fix needs a test that failed before the fix.

## Care
- Never edit files in `migrations/` that are already released.
- Ask before adding a dependency.

The official guidance suggests concrete instructions that can be checked, and a target of under 200 lines per file. Longer files use more context and are followed less reliably. You can import other files with @path/to/file, but imported text still counts toward context. For instructions that apply only to some files, use rules in .claude/rules/ that are scoped by path.

Auto memory

Claude Code also keeps auto memory: notes it writes itself from your corrections and preferences. Use /memory to read it or turn it off. Check these notes now and then, since a wrong note can repeat a mistake.

Permission modes

A permission mode sets the baseline for what runs without asking.

Mode Behavior in short
default (also manual) Reads in your working folders run; edits, commands and network access prompt
acceptEdits Also accepts file edits and common file commands in your working folders
plan Explores; edits wait until you approve a plan
auto Runs with few prompts while a classifier model reviews and blocks risky actions
dontAsk Only pre-approved tools and ordinary reads; anything that would prompt is denied
bypassPermissions Skips prompts; only for isolated containers or virtual machines

As of December 2026, the documentation says that auto mode is the starting mode for interactive terminal and VS Code sessions on recent versions with a supported model, and that administrators can disable it. It reduces prompts but does not guarantee safety. So check which mode you are in. In the terminal, Shift+Tab cycles through modes, and you can start in a chosen one:

Terminal
claude --permission-mode plan

Some actions can still prompt in every mode, for example ones that match your explicit ask rules.

Rules: allow, ask, deny

Rules refine the mode. You can manage them with /permissions or in a settings file such as .claude/settings.json:

JSON
{
  "permissions": {
    "defaultMode": "default",
    "allow": ["Bash(npm test)", "Bash(npm run lint)"],
    "ask": ["Bash(git push *)"],
    "deny": ["Read(./.env)"]
  }
}

The documentation states that deny rules apply in every mode, including bypass mode. Rule matching has subtleties, so read the permissions page before you rely on a rule to protect something important. For strong isolation, use sandboxing, a container or a virtual machine without access to your secrets.

Model the precedence idea

This stand-in uses simple pattern matching to show why checking deny first is the safe order. Real Claude Code rule syntax and matching are more detailed.

Python Stand-in: deny, ask and allow rules

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

read .env.production matches both a broad allow rule and a deny rule; deny wins. Likewise, the push asks even though a wider rule allows Git commands.

Good practice

  • Start unfamiliar repositories in plan or manual mode.
  • Keep secrets out of the project folder where possible.
  • Read commands before approving them, especially ones that delete, install, deploy or send data.
  • Treat a repository from a stranger as untrusted: its instruction files, settings and scripts can try to steer the agent.

Grow the file from real mistakes

Do not try to write the perfect instruction file on the first day. Start short. Add a line when Claude repeats a mistake, when a review finds something it should have known, or when you type the same correction twice. Remove lines that are outdated or that describe what is already obvious from the code. A procedure with many steps, or knowledge that matters only now and then, fits better in a skill, which the next lesson covers.

Check what is really active

When Claude Code behaves in an unexpected way, do not guess. Check the current permission mode, run /permissions to see the rules and where they come from, and run /context all to see which memory files were loaded. Settings can come from several places, including a managed policy from your organization, the project and your own user folder. A rule that you wrote in the wrong file has no effect.

Common mistake: writing "never touch production" in CLAUDE.md and considering production protected. It is context that the model usually follows, not a lock. Remove the credentials, use deny rules or hooks, and restrict the environment.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. How is CLAUDE.md best described?

    It guides behavior. Permissions and hooks enforce limits.
  2. 2. Which mode explores and waits for plan approval before editing?

    Plan mode is for exploring before changing anything.
  3. 3. Where is bypassPermissions appropriate?

    It removes prompts, so the environment must limit the damage.
  4. 4. Which makes a better CLAUDE.md line?

    It is specific and can be verified.

Summary

  • CLAUDE.md and auto memory give lasting context; keep them short and accurate.
  • Permission modes set what runs without asking; know your current mode.
  • Allow, ask and deny rules refine the mode.
  • Protect important things with real controls, not only instructions.

Next: Claude Code Skills, Hooks, MCP and Subagents

Your progress is saved in this browser. No account needed.