Claude Certified Architect · Foundations

Module 2: Claude Code setup and workflows

Study notes written by Sanjay Shah. Not official Anthropic material. Facts marked "check before relying on it" may have changed.

Practice this module

On this page

Course: Claude Architect (Foundations): Design production systems with Claude · Study notes, our own words · Facts checked 2026-11-25

Exam domain: Claude Code Configuration & Workflows, 20% (official exam guide v1.1, November 2026)

Take first: Claude Code in Action (opens in a new tab) (free, Anthropic Academy). It covers installing Claude Code and using it day to day. These notes are about designing a setup for a team: where each rule lives, and which rules actually hold.

Video: Module 2 long video, "How I Set Up Claude Code for a Whole Team (Rules It Can't Ignore)" (planned). Diagrams D2.1 to D2.4 match the video.

Claude Code changes often. Everything below was checked against the Claude Code docs (opens in a new tab) on 2026-11-25; recheck before copying a config.


What you'll be able to do

  • Explain the configuration layers (managed, project, local, user), which ones are shared, and which one wins.

  • Write a short CLAUDE.md that carries knowledge, and know why it can't carry enforcement.

  • Turn "must never" rules into permission rules and hooks that actually block.

  • Choose between CLAUDE.md, a skill, a subagent, a hook and an MCP server for a given team need.

  • Design a team pipeline: plan mode, parallel worktrees, headless review in CI, human merge.

  • Spot setups that look safe but aren't.


Key ideas

1. Two kinds of configuration: knowledge and enforcement

Everything you configure in Claude Code is one of two kinds.

Knowledge tells Claude what it should know and how you'd like things done: the build commands, the architecture, the naming conventions, "we use the repository pattern here". It lives in memory files (CLAUDE.md and friends) and skills. Claude reads it and usually follows it. Usually.

Enforcement decides what Claude can do, whatever it has read or been told: which files it can read, which commands it can run, what happens after every edit. It lives in settings: permission rules and hooks. It doesn't depend on Claude agreeing.

The design rule that runs through this whole module: knowledge in memory, rules in settings. If a rule must hold every time, with no exceptions, it can't live only in CLAUDE.md.

2. The settings layers and who wins

Settings files are JSON. There are several, at different levels, and they combine. From highest priority to lowest (checked 2026-11-25):

  1. Managed settings: set by the organisation (deployed to the machine or from the admin console). Users and projects can't override them.

  2. Command-line arguments for this one session.

  3. Local project settings: .claude/settings.local.json. Personal to you, for this repo. Not committed.

  4. Shared project settings: .claude/settings.json. Committed, so the whole team gets it.

  5. User settings: ~/.claude/settings.json. Yours, for every project.

A higher layer wins when two layers set the same thing. For permissions, there's an extra rule: a deny anywhere beats an allow (section 4).

Two details that trip people up:

  • When Claude Code creates settings.local.json itself, it adds it to your global git ignore. If you create the file by hand, add it to .gitignore yourself, or you may commit your personal settings.

  • /status in a session shows which settings sources were loaded. Use it when "my setting isn't working".

3. Memory files: they add up, they don't override

Memory files are Markdown that Claude loads as context. Unlike settings, they don't override each other; they all add together. The main ones:

FileScopeCommitted?
Managed CLAUDE.md (an OS-level path set by IT)Everyone in the organisationn/a
~/.claude/CLAUDE.mdYou, in every projectNo
./CLAUDE.md or ./.claude/CLAUDE.mdThis project, the whole teamYes
CLAUDE.local.mdYou, in this projectNo
CLAUDE.md in a subfolder, e.g. payments/CLAUDE.mdLoaded when Claude reads or edits files in that folderYes

CLAUDE.md files in parent folders above where you start are loaded at launch. Ones in subfolders load on demand. Claude Code also supports a .claude/rules/ folder of rule files whose frontmatter can limit them to certain paths. That is useful for "these conventions apply only to migrations/" (checked 2026-11-25).

Imports. A CLAUDE.md can pull in another file with @path/to/file. Paths are relative to the importing file, and imports can nest up to 4 levels deep (checked 2026-11-25). Careful: imported files are loaded at launch, together with the file that imports them. Imports organise a long file, but they don't reduce its context cost. For material that's needed only sometimes, use one of these instead:

  • a skill, which loads only when invoked or relevant (section 6);

  • a path-scoped rule or a folder CLAUDE.md, which loads only when Claude works on matching files;

  • a plain-text pointer ("for API style, read docs/api-style.md"), which Claude opens only when the task needs it.

What a good project CLAUDE.md contains (aim for under about 100 lines):

  • how to build, test, lint and run a single test;

  • a short architecture map: what each top-level folder is;

  • conventions that aren't obvious from the code;

  • known traps ("the legacy/ folder is frozen; don't refactor it");

  • plain-text pointers to long documents instead of pasting them in.

/init generates a starting CLAUDE.md from the repo, and /memory opens the loaded memory files for editing.

What it should not contain: secrets; long pasted documents; things the linter already enforces; and "must never" rules that you rely on for safety. You can also write the rule there, so Claude understands why, but the enforcement goes in settings.

Why short? Every line loads for every task, costs tokens on every request, and buries the important lines.

D2.1 Config layers. Settings override from the top down; memory files are combined.

4. Permissions: allow, ask, deny

Permission rules go under permissions in a settings file, in three lists:

  • allow: run without asking.

  • ask: always ask the user first.

  • deny: never allowed.

Claude Code checks deny first, then ask, then allow, and the first match wins (checked 2026-11-25). So a deny in any layer can't be undone by an allow somewhere else.

Rules name a tool and, optionally, a pattern. Current examples from the docs use forms like Read(./.env) and Bash(git push *):

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

Check the exact pattern syntax on the permissions page (opens in a new tab) before you copy this; it has changed over time.

Two cautions:

  • There is no ignore file that hides files from Claude. If you want Claude not to read secrets, use Read deny rules. (The docs say a .claudeignore file has no effect, checked 2026-11-25.)

  • Patterns on shell commands match the command text. A determined or confused agent can sometimes reach the same effect with a different command. Treat Bash patterns as a strong guard rail, not a sandbox, and add a hook (section 5) for anything critical.

Permission modes set the default behaviour for a session. The current set (checked 2026-11-25): default (shown as "Manual"; asks for anything not allowed), acceptEdits (file edits without asking), plan (read-only exploration and planning), auto (a background classifier reviews actions), dontAsk (denies anything that would need a prompt, useful unattended), and bypassPermissions (no checks; only for throwaway, isolated environments). auto and bypassPermissions can't be switched on from project or local settings files. Shift+Tab cycles modes in a session.

5. Hooks: code that runs at fixed points

A hook is your own command (or HTTP call, or other handler) that Claude Code runs at a fixed point in its lifecycle. Hooks are configured in settings under hooks, by event, with a matcher that picks which tools they apply to.

The events you'll use most (the docs list many more, checked 2026-11-25):

EventFiresTypical use
PreToolUseBefore a tool runsBlock an edit, a command or a file read; require approval
PostToolUseAfter a tool succeedsRun the formatter, run affected tests, log
UserPromptSubmitWhen the user sends a promptAdd context, block prompts containing secrets
SessionStartAt session startLoad dynamic context, such as the current branch's ticket
Stop / SubagentStopWhen Claude or a subagent finishesCheck the work is really done (tests pass) before stopping
PreCompactBefore context is compactedSave notes that must survive

How a command hook blocks (checked 2026-11-25):

  • Exit code 0: success; the action goes ahead.

  • Exit code 2: blocking. For PreToolUse, the tool call is stopped, and what the hook printed to stderr is sent to Claude as the reason.

  • Any other exit code (including 1): a non-blocking error. The action goes ahead.

That last point is a classic bug: a "blocking" script that exits 1 blocks nothing. A PreToolUse hook can also print JSON with a permissionDecision (allow, deny, ask or defer) and a reason, for finer control.

Here is a hook that blocks edits to migrations that have already been applied:

JSON
{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Edit|Write",
        "hooks": [
          { "type": "command", "command": ".claude/hooks/protect-applied-migrations.sh" }
        ]
      }
    ]
  }
}
Bash
#!/usr/bin/env bash
# Reads the tool call as JSON on stdin. Blocks edits to applied migrations.
file=$(jq -r '.tool_input.file_path // empty')
if [[ "$file" == */migrations/applied/* ]]; then
  echo "Applied migrations are immutable. Create a new migration in migrations/pending/ instead." >&2
  exit 2
fi
exit 0

The reason matters as much as the block. Claude reads it and changes course, here by writing a new migration. A hook that blocks with no reason leaves Claude guessing, and it may try the same thing another way.

D2.3 Hook flow. The red-bordered step in the video is the PreToolUse hook: it is enforcement, not advice.

6. Skills, subagents and MCP servers

Three more places a team need can go.

Skills package a repeatable job: instructions, and optionally scripts and reference files, in .claude/skills/<name>/SKILL.md. The frontmatter description tells Claude when the skill is relevant. Claude sees the short descriptions up front and loads the full skill only when needed, so many skills cost little context. You can also run a skill directly as /name. Custom slash commands in .claude/commands/ have been merged into skills and still work (checked 2026-11-25).

Markdown
---
name: add-endpoint
description: Add a new API endpoint the house way (route, input validation, tenant filter, test). Use when asked to add or scaffold an endpoint.
---
1. Create the route in api/routes/ following api/routes/_example.ts.
2. Validate input with the shared schema helper. Never trust client tenant IDs.
3. Every query filters by the tenant from the request context.
4. Add a test in api/tests/ covering success, bad input and wrong tenant.
5. Run the endpoint's tests and show the output.

Subagents are specialised assistants defined in Markdown files in .claude/agents/ (project) or ~/.claude/agents/ (user), with frontmatter for name, description, tools and model (plus newer options such as permissionMode and maxTurns). Each runs in its own context window, so it can read a lot and return a little, and it gets only the tools you list. That makes subagents the natural home for a read-only reviewer.

Markdown
---
name: payments-reviewer
description: Reviews changes under payments/ for money-handling, rounding and tenant-isolation bugs. Use after any edit to payments/.
tools: Read, Grep, Glob
model: sonnet
---
You review code; you never edit it. Report each issue with file, line, severity and a suggested fix.

Notes (checked 2026-11-25): the tool that launches subagents is now called Agent (it used to be Task). Subagents can start their own subagents, up to three levels by default. If you don't want that, leave Agent out of the subagent's tools.

MCP servers connect Claude Code to outside systems: the issue tracker, a database, internal APIs (Module 4 covers MCP design). In Claude Code a server can be added at three scopes:

  • local (the default): just you, just this project;

  • project: in .mcp.json at the repo root, committed, shared with the team;

  • user: you, in all projects.

.mcp.json can read environment variables with ${VAR} or ${VAR:-default}, so the file holds the name of the secret, never the secret:

JSON
{
  "mcpServers": {
    "tracker": {
      "type": "http",
      "url": "https://tracker.example.com/mcp",
      "headers": { "Authorization": "Bearer ${TRACKER_TOKEN}" }
    }
  }
}

Claude Code asks each person to approve project-scoped servers from .mcp.json before using them in an interactive session. A command such as claude mcp add --transport http tracker https://tracker.example.com/mcp adds one from the terminal.

7. Where does a rule belong?

Put together, the decision looks like this:

D2.2 Where a rule belongs. The first question comes first on purpose: enforcement is never optional.

8. Team workflows: plan, parallel, headless, human

Plan mode for big changes. In plan mode Claude explores and proposes a plan without editing. Use it for anything that touches many files: you review the plan, then switch modes and let it work. It's cheaper to correct a plan than a 30-file diff. /plan also enters it.

Worktrees for parallel sessions. Two Claude sessions editing the same checkout will collide. Git worktrees give each session its own working folder and branch. claude --worktree <name> creates one (checked 2026-11-25).

Checkpoints and context. /rewind (or Esc twice) rolls back to an earlier point in the session; it doesn't replace git. /clear starts fresh between unrelated tasks, and /compact summarizes a long session.

Headless mode for automation. claude -p "…" runs one task without the interactive UI and prints the result. Useful flags (checked 2026-11-25): --output-format text|json|stream-json, --allowedTools to list exactly which tools it may use, --permission-mode, and --json-schema to get output that fits a schema (it appears in a structured_output field). The docs also recommend --bare for scripted runs: it skips hooks, skills, MCP servers and CLAUDE.md discovery, which makes runs reproducible, but it means you must pass the context the run needs. Check --bare before relying on it; the docs say it will become the default for -p.

The Agent SDK (renamed from the Claude Code SDK) gives you the same agent loop, tools, hooks and subagents as a library in Python and TypeScript, for when you build your own agent rather than script Claude Code.

D2.4 Team pipeline. In CI: no write tools, and no secrets beyond what the review needs. A person merges.


Worked example: the Claude Code setup of a multi-tenant SaaS platform I build

Shown here on a demo repo with the same structure: api/, web/, migrations/ (split into applied/ and pending/) and billing/ (the sensitive, money-handling area). Five problems, five fixes.

Problem 1: everyone re-explains the commands. Fix: a root CLAUDE.md of about 60 lines: build, test, single-test, lint; a ten-line folder map; the five conventions that aren't obvious; and a one-line pointer to docs/api-style.md for the long style guide. That's a plain pointer, not an @ import, so the guide is read only when a task needs it. A trimmed file beat the earlier 600-line one, which had pasted design docs and was mostly ignored.

Problem 2: secrets must never be read. Fix: Read deny rules for .env* and secrets/** in the shared .claude/settings.json, so they apply to everyone. CLAUDE.md also says why, so Claude doesn't keep trying.

Problem 3: applied migrations got edited. Fix: the PreToolUse hook shown above, with a reason that names the right action. In the live demo, Claude tries the edit, gets blocked, reads the reason and creates a new migration in pending/. A PostToolUse hook runs the formatter and the tests next to the edited file, and the test output goes back to Claude.

Problem 4: billing code needs a second look. Fix: billing/CLAUDE.md with the extra rules (money in integer minor units, rounding rules, idempotency keys), plus the payments-reviewer subagent with read-only tools. A Stop hook could also require the billing tests to pass before Claude reports "done".

Problem 5: the issue tracker lives outside the repo. Fix: a project .mcp.json entry for the tracker, with ${TRACKER_TOKEN} from each person's environment. Nobody's token is in git.

And in CI: on every pull request that touches billing/, a headless Claude review runs with only read tools, returns JSON, and the pipeline posts the findings as comments. It never approves or merges. A person does.

The lesson: none of the safety in this setup depends on Claude remembering a sentence. The sentences are there to explain. The settings and hooks are there to enforce.

Your turn: design exercise

A six-person team on a monorepo with web/, api/ and payments/. Two juniors and one outside contractor. Production credentials must never be read. Payments code needs a second look. Everyone keeps re-explaining the test commands.

Design: what goes in which CLAUDE.md; which rules are enforced and how; what is shared and what is personal; which skills, subagents and MCP servers to add; what CI does; and how the company stops a local file from loosening the rules. The model answer walkthrough is in the locked lesson on the site.


Design decisions and trade-offs

DecisionOption AOption BHow to choose
Where a "must never" rule livesCLAUDE.md sentenceDeny rule or hookEnforcement always goes in settings. A sentence in CLAUDE.md can explain the rule as well.
Deny rule or hookPermission rulePreToolUse hookA permission rule for simple "this tool on this path or command". A hook when the decision needs logic (which folder, which branch, file contents) or a tailored reason.
Shared or personal.claude/settings.json (committed)settings.local.json (personal)Team rules and safety are shared. Personal preferences are local. Company-wide limits go in managed settings so no one can loosen them.
One CLAUDE.md or severalEverything in the rootRoot + folder files + path rules + skillsKeep the root short. Folder rules go in folder files or path-scoped rules. Occasional long guides become skills or plain pointers. @imports only organise; they still load everything at launch.
Skill or subagentSkill (instructions in the main context)Subagent (own context and tools)A skill for "do this job the house way". A subagent when the job reads a lot, should have fewer tools (read-only review), or should keep its exploration out of the main context.
MCP scopelocal / userproject (.mcp.json)Project scope when the whole team needs the same server. Secrets always via env vars.
CI run setupNormal -p (loads CLAUDE.md, hooks)--bare (reproducible, loads nothing)Normal if the review needs project conventions. Bare for reproducible scripts, passing context explicitly. Either way, the fewest tools needed.
Mode for unattended runsbypassPermissionsExplicit --allowedTools (+ dontAsk)Allow-list exactly what is needed. Bypass only in a throwaway, isolated environment.

Anti-patterns

  • The 800-line CLAUDE.md. Pasted docs, every preference, every past incident. It costs context on every request, and the important lines get lost.

  • "Please don't read .env" as the only control. Advice, not enforcement. Use a deny rule.

  • A blocking hook that exits 1. Only exit 2 blocks. Exit 1 is a non-blocking error, and the action goes ahead.

  • A block with no reason. Claude can't adapt to "no". Tell it what to do instead.

  • Secrets in .mcp.json or in CLAUDE.md. Committed files are read by everyone and live in git history. Use ${VAR}.

  • Company limits in project settings only. A contractor's local settings can't loosen a deny rule, but anything that isn't denied can be allowed locally. Organisation-wide limits go in managed settings.

  • A "reviewer" subagent with write tools. Give reviewers Read, Grep and Glob.

  • bypassPermissions in CI on a real repo with real credentials. Allow-list the tools instead.


Remember

  • Knowledge in memory, rules in settings. CLAUDE.md informs; permissions and hooks enforce.

  • Settings: managed > command line > local > project > user. Memory files add up.

  • Permissions are checked deny → ask → allow; a deny can't be overridden by an allow.

  • Hooks: exit 2 blocks and sends stderr to Claude. Any other non-zero exit does not block.

  • Keep CLAUDE.md short. Folder files and path rules load on demand; skills load when relevant. @imports (up to 4 levels) load at launch, so they organise but don't save context.

  • Skill = a repeatable job. Subagent = its own context and fewer tools. MCP = an outside system, secrets via ${VAR}.

  • Team flow: plan mode for big changes, worktrees for parallel work, headless read-only review in CI, a human merges.


Facts in this module, and where to check them

All checked 2026-11-25 on code.claude.com/docs (opens in a new tab).

FactPage
Settings precedence; settings.local.json git-ignore behaviour; /statussettings (opens in a new tab)
allow / ask / deny, order deny → ask → allow, rule syntax, permission modes, no .claudeignorepermissions (opens in a new tab)
Memory file locations, load order, @imports up to 4 levels and loaded at launch, .claude/rules/ path rules loaded on matching files, skills for occasional contentmemory (opens in a new tab)
Hook events, matchers, exit code behaviour, permissionDecision valueshooks (opens in a new tab)
Skills, /name, commands merged into skillsskills (opens in a new tab)
Subagent files and frontmatter, own context, Agent tool, nesting depthsub-agents (opens in a new tab)
MCP scopes, .mcp.json, ${VAR} expansion, project-server approvalmcp (opens in a new tab)
claude -p, --output-format, --allowedTools, --permission-mode, --json-schema, --bareheadless (opens in a new tab)
claude --worktreeworktrees (opens in a new tab)
/rewind, /compact, /clear, /memory, /init, /plancommands (opens in a new tab)

Check before relying on it:

  • --bare becoming the default for -p (the docs say it will; timing unknown).

  • --max-turns and --disallowedTools for headless runs: not confirmed on the pages we read.

  • The repository name of the official GitHub Action: the GitHub Actions page (opens in a new tab) exists; we didn't confirm the name, so these notes don't use it.

  • Exact pattern syntax for Bash(...) rules: the current docs use Bash(git push *); older guides show other forms.

Practice: 15 questions for this module.

↑ ↓ navigate · ↵ select · esc close