Claude Code
Operate Claude Code correctly on every surface (sessions, CLAUDE.md, settings.json, permission modes, headless) and choose the right extension mechanism (Skill, Rules file, hook, subagent, slash command, plugin) for a team workflow.
- Claude Code Operation across CLI, desktop, IDE, web, and mobile: sessions, CLAUDE.md hierarchy, settings.json, permission modes, headless/streaming, built-in commands
- Claude Code Customization and Extension: Skill, plugin, Rules file, hook, subagent, slash command; packaging for distribution
Domain overview
Domain 3 accounts for 8% (about 5 scored items). The exam tests two skills: (1) operating Claude Code — choosing a surface, managing sessions, reading the CLAUDE.md hierarchy and settings.json, choosing a permission mode, running headless in CI; (2) customization & extension — starting from a repeatable team workflow, choosing the mechanism that fits and packaging it for distribution. Items often present a configuration file or a "works on my machine" scenario and ask what actually happens when someone else, CI, or a different scope runs it.
Surfaces and sessions
Choosing a surface
| Surface | Key traits | Choose it when |
|---|---|---|
| CLI (terminal) | Features ship here first; access to the directory where claude runs and all its subdirectories |
You need the full feature set, scripting, CI |
| IDE | The VS Code extension closely matches the terminal; the JetBrains plugin runs the claude command, so the CLI must be installed first |
You want Claude Code tied to your editor |
| Desktop (Code tab) | Ships with Claude Code, no CLI install needed; runs in the background and can run in the cloud | You want Claude working in the background while you do something else |
Web (claude.ai/code) |
Cloud session in a VM, starting from a fresh clone of the GitHub repo | No local setup needed; run many tasks in parallel |
| Mobile/browser via Remote Control | The session still runs on your machine; the phone is just a control window (/remote-control) |
You are mid-task in the terminal and need to step away |
Remote Control keeps the local environment intact (filesystem, MCP servers, configuration), but the machine must stay on and the claude process must keep running; closing the terminal takes the session offline. A cloud session (claude --cloud "<task>" or the web) keeps running when you close your laptop, but it sees only what has been pushed to the repo (including the repo's CLAUDE.md); unpushed commits, MCP servers at local/user scope (stored in ~/.claude.json), and interactive logins such as AWS SSO don't come along.
Exam trap
"The commit is on my laptop, so the cloud session will see it" — wrong. The cloud VM clones the GitHub remote at the current branch; it does not copy your local checkout. Push first, or use Remote Control if the task needs something that exists only on your machine.
Session management
- Checkpoints & rewind: every prompt creates a checkpoint.
/rewind(or pressing Esc twice on an empty prompt) lets you Restore code and conversation, the conversation only, the code only, or Summarize from here / up to here. Files changed by shell commands (e.g. installing a package) are not rolled back. - Context:
/contextshows how context is allocated;/compact <instructions>produces a focused summary when you continue on the same feature;/clearwipes everything when you move to a new task (assigning a newsession.id). Knowledge that must persist across sessions goes intoCLAUDE.md. - Resuming sessions:
claude --continuereopens the most recent conversation in the current directory;claude --resumeopens a picker or takes a session ID;/resumeworks inside a session;--fork-sessioncreates a new session ID when resuming. Transcripts are stored in~/.claude/projects/*/*.jsonl. - Parallel work: one git worktree per session (
claude --worktree feature-auth) so sessions don't step on each other's files;.worktreeincludelists git-ignored files (such as.env) to copy into the worktree.
CLAUDE.md: hierarchy, precedence, and imports
| Location | Who uses it | Notes |
|---|---|---|
| Managed policy | The whole organization (managed by the platform team) | Cannot be excluded |
User ~/.claude/CLAUDE.md |
Just you, across all projects | Personal preferences |
Project ./CLAUDE.md (or .claude/CLAUDE.md) |
The whole team, committed to the repo | Build/test commands, conventions, architecture |
Local CLAUDE.local.md |
Just you, this repo only, git-ignored | Personal notes for a refactoring branch |
| CLAUDE.md nested in subdirectories | The corresponding part of the code | The narrower file is an intentional override for that directory |
The files stack; none is dropped. @path/to/file.md imports are expanded inline at startup: they help organize files but do not reduce context. /init generates a draft; trim it to under a page, keeping build/test/lint commands, key conventions, and "things Claude often gets wrong"; when Claude repeats a mistake twice, write the fix into CLAUDE.md.
Rules files (.claude/rules/*.md) split conventions into separate files; the paths: frontmatter (globs) limits a rule to work on matching files, and a rule without paths is always loaded. The InstructionsLoaded hook fires when CLAUDE.md or a rules file is loaded, so you can audit what actually enters context.
Key point
CLAUDE.md is guidance, not enforced configuration: every line competes for attention, and the longer the file, the fewer lines get followed. Write specific, verifiable rules ("put new API routes in src/api/handlers, one route per file"), state the alternative ("use named exports, not default exports"), and write plainly instead of "IMPORTANT/YOU MUST". A rule that must never be violated → move it to a hook.
settings.json: scopes, permissions, hooks, env
Precedence from highest to lowest: managed settings → command-line arguments → .claude/settings.local.json (local, git-ignored) → .claude/settings.json (project, committed) → ~/.claude/settings.json (user). Lists such as permissions.allow are merged across scopes rather than overwritten.
{
"permissions": {
"allow": ["Bash(make test)", "Bash(git *)"],
"deny": ["Read(./.env*)", "Bash(git push *)", "WebFetch"],
"defaultMode": "acceptEdits"
},
"env": { "CLAUDE_CODE_ENABLE_TELEMETRY": "1" },
"hooks": {
"PostToolUse": [{ "matcher": "Edit|Write",
"hooks": [{ "type": "command", "command": "${CLAUDE_PROJECT_DIR}/.claude/hooks/format.sh" }] }]
}
}
- Permission rules are evaluated in the order deny → ask → allow; deny always wins. A rule for an MCP tool (
mcp__deploy-staging__release) names the server and the tool and does not inspect arguments — to tell staging from production, use a separate server per environment. - env sets environment variables for every session; Claude Code ignores OpenTelemetry exporter variables in the repo's settings, so a repo cannot turn on telemetry or change its destination on its own.
- Managed settings (MDM or the admin console) have admin-only keys:
disableBypassPermissionsMode,allowManagedPermissionRulesOnly,allowManagedHooksOnly,allowManagedMcpServersOnly,strictKnownMarketplaces,requiredMinimumVersion. WhenallowManagedHooksOnlyis on, user/project/local hooks do not run. - Agent SDK:
setting_sourcesselects the sources ("user","project","local"); when omitted, claude-agent-sdk 0.2+ loads all sources; pass[]to run in isolation.
Exam trap
A hook declared in .claude/settings.local.json exists only on your machine; for the whole team to use it, put it in .claude/settings.json and commit it (use ${CLAUDE_PROJECT_DIR} to point to the script). With the Agent SDK, hooks in the local file are loaded only when setting_sources includes "local".
Permission modes
| Mode | Runs without asking | Best for |
|---|---|---|
Manual (default) |
Reads only; everything else asks first | Close, step-by-step supervision |
Accept edits (acceptEdits) |
Reads, file edits, common filesystem commands (mkdir, mv, rm) |
Fast iteration, reviewing the diff afterward |
Plan (plan) |
Reads and exploration; no source edits | Complex changes, safe review |
Auto (auto) |
Most actions, pre-screened by a separate classifier | Hands-off work with a safety net |
Don't ask (dontAsk) |
Reads within the working directory + pre-approved tools; everything else is auto-denied | Unattended CI, cron, batch jobs |
Bypass (bypassPermissions) |
Skips all checks (--dangerously-skip-permissions) |
Only in an isolated container/VM |
Shift+Tab cycles manual → accept edits → plan → auto; on the command line, use --permission-mode. The auto mode classifier blocks production deploys, force pushes, sending sensitive data outside, and deleting pre-existing files — it checks intent, not correctness: broken auth code still gets through. So pair auto mode with a Stop hook that runs tests. In non-interactive runs, a hook that returns ask is treated as deny because no one is there to answer; with dontAsk, an allow from a PreToolUse hook still lets the tool run.
Scenario example
A staging release pipeline runs claude -p ... --allowedTools "mcp__deploy-staging__release,mcp__deploy-staging__status,mcp__deploy-staging__rollback" --permission-mode dontAsk. The job holds only a staging token. If Claude calls a production server's tool, the call is denied immediately instead of hanging while it waits for approval. The option "use bypassPermissions for speed" is wrong: CI holds real credentials, and bypass removes every layer of protection.
Headless, streaming, and CI
claude -p "<prompt>" (--print) runs once with no UI, reading stdin and writing to stdout. By default it loads the same context as an interactive session: hooks, skills, plugins, MCP servers, CLAUDE.md.
--output-format text | json | stream-json:jsonreturns an object withresult,is_error,session_id; with--json-schema, the schema-conforming object is instructured_output.stream-jsonemits events line by line as they happen, which suits UIs that need streaming or long jobs.- Multiple steps: take the
session_idfrom the JSON, thenclaude --resume "$(jq -r .session_id plan.json)". --bareskips auto-discovery of hooks/skills/plugins/MCP/CLAUDE.md, leaving only Bash + file read/edit and whatever is passed through--settings/--mcp-config; it doesn't use subscription login, so it needsANTHROPIC_API_KEY. Don't use--barewhen CLAUDE.md, skills, or hooks are themselves what is being tested.- Limits:
--allowedTools/--disallowedTools,--max-turns 5,--model. Verify a headless run by its JSON result and exit code; don't trust the summary.
The automation spectrum: cloud scheduled tasks (/schedule, run on Anthropic infrastructure, scheduled at most hourly, start from a fresh clone of the default branch and push to a claude/ branch) → -p when you need your own environment → --bare when CI needs the same setup on every machine → Agent SDK (query() with allowedTools, a system prompt, a permission mode) when embedding into a product. The GitHub Action anthropics/claude-code-action@v1 is installed via /install-github-app; with a prompt it runs automatically, and without one it waits for the trigger_phrase (default @claude); CLI arguments go through claude_args.
Common built-in commands
| Command | Effect |
|---|---|
/init |
Scans the codebase and generates CLAUDE.md |
/compact, /clear, /context |
Focused summary / wipe everything / view context allocation |
/rewind, /diff, /code-review |
Return to a checkpoint / view the diff / review from a clean context (low, high) |
/hooks, /mcp |
List hooks (read-only) / MCP server status |
/agents |
Points to where subagent files live (unlike claude agents, which opens the agent view) |
/plugin, /reload-plugins, /reload-skills |
Manage plugins; reload plugins/skills |
/model, /effort, /usage, /status |
Choose the model, set effort, view usage, check configuration status |
Choosing an extension mechanism
| Mechanism | Activation | Deterministic? | Used for |
|---|---|---|---|
| CLAUDE.md | Loaded into every conversation | No | Conventions that always apply |
| Rules file | Always, or when files match paths |
No | Conventions for one part of the codebase |
| Skill | Claude matches the description to the request | No | Task-specific procedures/knowledge |
| Slash command | The user types /name |
No | Manually invoked prompt templates, with $ARGUMENTS |
| Subagent | Claude delegates; separate context | No | Research, "fresh eyes" review, a different tool set |
| Hook | Lifecycle events | Yes | Things required every time, blocking actions |
| MCP server | External tools/resources | — | Connecting external systems |
| Plugin | Install once | — | Packaging everything for distribution |
Selection rules: you have typed the same multi-step instructions twice → Skill; it must happen every time or must never be skipped → hook (PreToolUse to block, PostToolUse to format/lint, Stop to block finishing while tests are red); you need the result but not the journey → subagent. A Skill is only an advisory control: a mandatory policy needs a hook (and a check on the PR, because an Edit|Write hook doesn't fire when a shell command edits a file) behind it.
Hooks: mechanics you must know
- Exit
0= success (stdout JSON is parsed); exit2blocks, and stderr is fed back to Claude; any other code (including1) does not block. - PreToolUse returns JSON
hookSpecificOutput.permissionDecision:allow/deny/ask;updatedInputrewrites the call but replaces the entire input object. - PostToolUse runs after the tool has already run: it cannot block, only feed a response back. To re-inject context after compaction, use SessionStart with matcher
compact, not PostCompact.
Subagents
File .claude/agents/<name>.md (project) or ~/.claude/agents/ (user): frontmatter name, description (determines when it is invoked and shapes the delegation prompt; add "proactively" for automatic delegation), tools, model (sonnet, opus, haiku, fable, a model ID, or inherit), skills (loaded in full at startup); the file body is the system prompt. Define an output format and an "Obstacles Encountered" section; restrict tools (a reviewer needs Bash for git diff but not Edit). Avoid: "expert" personas, sequential pipelines where a later step depends on what an earlier step found, and subagents that run tests (they hide the output you need for debugging).
Exam trap
A subagent does not see the skills you invoked in the main conversation; built-in agents (Explore, Plan) don't preload skills. If you declare tools for a subagent, keep Skill so it can still invoke skills that aren't listed.
Writing and distributing Skills
SKILL.md must sit in a named directory (not at the root of skills/). Frontmatter: name (defaults to the directory name; for upload to Claude.ai/the API: lowercase letters, digits, hyphens, ≤ 64 characters), description (says what it does and when to use it; ≤ 1,024 characters for upload), allowed-tools (pre-approves tools, does not restrict them), disallowed-tools, model, effort, disable-model-invocation: true (manual invocation only). Progressive disclosure: name+description always in context → the SKILL.md body when it matches → supporting files (references/, scripts/) when needed; keep SKILL.md under 500 lines and tell Claude to run scripts, not read them. Precedence on name conflicts: Enterprise → Personal → Project; plugin skills are namespaced, so they coexist.
Key point
Skill doesn't trigger → fix the description (add the phrases users actually say). Skill not loaded → check the directory and the SKILL.md file name; run claude plugin validate and claude --debug. Wrong skill chosen → the descriptions are too similar. Personal skill "ignored" → an enterprise skill has the same name.
Packaging plugins and marketplaces
my-review/
├── .claude-plugin/plugin.json # name (the only required field), version, description, author
├── skills/<skill>/SKILL.md
├── agents/<agent>.md
├── hooks/hooks.json # the "hooks" object moved out of settings.json
└── .mcp.json
Test with claude --plugin-dir ./my-review; once it works, delete the originals in .claude and the hooks in settings.json, otherwise each hook runs twice. Skills run under the name /my-review:<skill>. The team adds a private marketplace once (/plugin marketplace add your-org/claude-plugins) and then runs /plugin install name@marketplace; admins lock down sources with strictKnownMarketplaces. Plugins run code with your permissions, and their hooks stack with yours — read the details before installing.
Key point
Three distribution paths: commit .claude/ to the repo (project-specific standards), plugins through a marketplace (reuse across many repos/teams), managed settings (mandatory organization-wide, highest precedence).
Scenario example
Policy: "fields tagged pii must never appear in logs". The right design: a secure-api-review skill that Claude applies when writing endpoints; a PostToolUse hook on Edit|Write that runs scripts/check-endpoints.sh and exits 2 on a violation; and the same script as a required check on PRs. Writing the rule only in CLAUDE.md or only in a skill is not enough, because both are instructions that Claude can skip.
Exam tip
"Always / never / mandatory" → hook or managed settings. "Automatically when relevant" → Skill. "The user types a shortcut" → slash command. "Don't pollute the context / fresh-eyes review" → subagent. "Many repos, many teams" → plugin + marketplace.
Quick summary
- Cloud sessions start from a fresh GitHub clone: unpushed commits and local/user MCP servers don't come along; Remote Control keeps the local environment, but the machine and the
claudeprocess must keep running. /compact <focus>when continuing the same feature,/clearwhen moving to a new task;/rewinddoes not undo the side effects of shell commands.claude --continuereopens the most recent conversation;--resume <session_id>chains headless steps.- CLAUDE.md exists at managed, user, project, local, and subdirectory levels; they all stack;
@pathimports don't reduce context. - Rules files in
.claude/rules/withpaths:load conventions for matching files. - Settings precedence: managed → CLI → local → project → user; lists are merged; deny always beats allow.
- MCP permission rules don't inspect arguments: split servers by environment.
dontAskfor CI;bypassPermissionsonly in an isolated container/VM; auto mode checks intent, so pair it with a Stop hook that runs tests.-ploads the full context;--bareskips all of it and needsANTHROPIC_API_KEY;--json-schema→structured_output.- Hooks: exit 2 blocks, exit 1 doesn't;
updatedInputreplaces the entire input; SessionStartcompactre-injects context. - Skills trigger automatically from their description;
allowed-toolspre-approves rather than restricts; precedence Enterprise → Personal → Project. - Subagents don't inherit skills already invoked; avoid subagents that run tests and sequential pipelines with dependencies.
- Plugins: the manifest requires only
name, hooks move tohooks/hooks.json, skills are namespaced/plugin:skill; plugins run with your permissions.