Task statement 3.1 · Claude Code

3.1 · Claude Code Operation

In Shelfwise, the course example, the three engineers run Claude Code on the service's own repository to add branches and to fix the stock-feed client. Operating it means knowing what a session loads, how to resume one, what runs without asking, and how to script it.

Why it's tested

The tempting habits are to approve every prompt as it appears and to reach for --dangerously-skip-permissions the first time a script stalls. Approving by habit checks nothing, and skipping permissions on a laptop removes nearly every check, but the script only needed a chosen mode and a short allow list.

KnowledgeCore components and where they live

Claude Code's core components are files that a session discovers at launch, under the project's committed .claude/ or under ~/.claude/ for you in every project. Rules guide every session, while Skills and commands load only when invoked. An agent is a subagent definition that works in its own context window. Agent memory is what an agent writes for itself to read later. Filing a procedure as a rule is the usual mistake, because a rule costs context on every request while a Skill waits until needed.

Rules

Markdown in .claude/rules/, loaded at launch, or with paths frontmatter only when Claude touches a matching file (2.6).

Skills

.claude/skills/<name>/SKILL.md. Claude invokes one when its description fits the task, or you type /<name> (8.3).

Commands

Built-in commands control the session. A custom command, .claude/commands/<name>.md, runs as /<name>; commands are now merged into Skills.

Agents

.claude/agents/<name>.md with name, description and optional tools. Claude delegates by description, an @-mention forces one, and --agent runs the session as it.

Agent Memory

A subagent's memory field: project keeps notes in .claude/agent-memory/<name>/, user in ~/.claude/agent-memory/<name>/, local in .claude/agent-memory-local/<name>/.

Auto memory is the main session's version, and it is easy to confuse with CLAUDE.md because both load at every session's start. You write CLAUDE.md, while Claude writes auto memory from your corrections, loading the first 200 lines or 25 KB of its MEMORY.md index each session. It stays on one machine, and /memory turns it on or off. The subagent memory field is the closest docs match for the guide's "Agent Memory" (1.3).

KnowledgeThe CLAUDE.md hierarchy, initialisation and settings.json

The CLAUDE.md hierarchy runs from a managed policy file through ~/.claude/CLAUDE.md to the project's CLAUDE.md and CLAUDE.local.md in the launch directory and every directory above it, concatenated from the top down (2.6 has the full rules). The guide's "repository initialization" is /init: Claude analyses the codebase and writes a starting CLAUDE.md with the build commands, test instructions and conventions it finds, or suggests improvements when one already exists. /memory lists every CLAUDE.md location, while /context shows which files actually loaded. settings.json is the enforced side of configuration, holding permission rules, hooks, env and permissions.defaultMode. One operational detail: "defaultMode": "auto" has no effect from a project's .claude/settings.json or .claude/settings.local.json, so a repository cannot switch its users into auto mode.

KnowledgeSession management and slash commands

Session management works on transcripts, local files of each conversation tied to the project directory. claude --continue reopens the most recent conversation in the current directory, claude --resume takes a session ID or name or opens a picker, and /resume switches from inside a session. Naming a session with claude -n or /rename lets you resume it by name. Sessions started with claude -p or the Agent SDK stay out of the picker and out of --continue, so you resume one by its session ID. A resumed session restores its history and model, but launch flags such as --add-dir must be passed again. When to clear or branch instead is session hygiene (2.5). Slash commands drive this from the prompt. Built-in ones such as /init, /compact, /permissions and /model control Claude Code itself. A custom slash command is a Markdown file you write, run as /<name> with any following text as its arguments.

KnowledgePermission modes and auto mode

A permission mode sets what runs without asking. Manual mode, config value default, asks before edits and most shell commands. acceptEdits approves file edits and commands such as mkdir in the working directory. plan reads and proposes, but blocks edits until you approve the plan. dontAsk denies whatever would prompt. bypassPermissions approves nearly everything, so it belongs in isolated containers. Auto mode, the guide's "auto-mode", hands the prompts to a classifier, a second model that reviews each action before it runs and blocks anything that goes beyond your request or looks driven by content Claude read. Reads and edits in the working directory skip it. It needs a supported Opus-, Sonnet- or Fable-family model, not a Haiku-family one. An organisation can remove it with permissions.disableAutoMode. Current versions start interactive sessions in it when available. In every mode, deny rules hold and a PreToolUse hook runs first (7.3). Shift+Tab cycles modes, and --permission-mode picks one at launch, as in the Agent SDK (8.1).

Interactive · what three actions do in four permission modes

A table with four columns, the permission modes Manual, acceptEdits, auto and bypassPermissions, and three rows of actions in a Shelfwise session. Edit a file in stock_mcp: Manual asks you; acceptEdits runs it; auto runs it without the classifier; bypassPermissions runs it. A shell command no allow rule covers: Manual asks you; acceptEdits asks you; auto lets the classifier decide; bypassPermissions runs it. git push origin main: blocked by the push guard hook in all four modes, because the PreToolUse hook runs before the mode is checked. edit a file IN stock_mcp/ shell command NO ALLOW RULE git push origin main Manual (default) asks you EVERY EDIT asks you EACH COMMAND blocked PUSH GUARD, EXIT 2 acceptEdits runs IN THE WORKING DIR asks you ONLY mkdir, mv… RUN blocked PUSH GUARD, EXIT 2 auto runs SKIPS THE CLASSIFIER classifier decides BLOCKS BEYOND-TASK blocked PUSH GUARD, EXIT 2 bypassPermissions runs NO CHECK runs NO CHECK blocked HOOKS STILL RUN The PreToolUse hook runs before any mode is checked, so the push is blocked in every column.

Choose the mode a Shelfwise engineer's session runs in.

Manual (config value default): reads run, but Claude asks before each edit and before any shell command no allow rule covers. The push to main never reaches a prompt, because the push guard hook exits 2 first.

acceptEdits: edits in the working directory run, and so do common filesystem commands such as mkdir and mv. Other shell commands still ask, and the push guard still blocks the push.

auto: reads and working-directory edits run without the classifier. Other commands go to the classifier, which blocks anything beyond the request. Deny rules and the push guard still apply.

bypassPermissions: edits and commands run with no check, so this mode belongs in an isolated container. Hooks still run first, so the push guard still blocks the push.

Each column is one mode; read down the actions. Green runs, amber asks you, blue goes to the classifier, ember is blocked.

KnowledgeHeadless mode and streaming

Headless mode is Claude Code without its interface: claude -p "<prompt>" runs one task and exits, loading the same CLAUDE.md, settings, hooks and MCP servers as an interactive session unless --bare skips them. Nobody is there to answer a permission prompt, so each prompt is denied, and a run that sets no mode starts in that account's built-in default. --output-format takes text, json or stream-json. json is one object with result and session_id, and stream-json is one JSON event per line as the run proceeds, ending with a result line that lists any permission_denials.

More precise than the guide. The docs call claude -p non-interactive or print mode, under "Run Claude Code programmatically"; "headless" survives in the page's address, and no feature is named "streaming mode" (as of 2026-10-05). Streaming is the stream-json format, written with --output-format and read with --input-format; the Agent SDK's long-lived equivalent is streaming input mode. Exam answer: "streaming mode" is a print-mode run that sends or reads stream-json events as they happen, not a separate way to start Claude Code.

SkillWorked example: a script that adds a branch

Adding a shop is a repeated chore, so one engineer wrapped it in scripts/add_branch.sh, which first ran Claude Code headless with no mode set:

claude -p "Add the York branch to config/branches.toml, then run the tests"
# exit 0; the reply says the edit needs approval; no file changed

The run started in print mode's built-in default, Manual mode on the engineers' accounts. With nobody to answer, each edit prompt was denied. The fix names the mode and the one allowed command, and streams events to check the outcome:

claude -p "Add the York branch to config/branches.toml, then run the tests" \
  --permission-mode acceptEdits \             # edits in the repository run
  --allowedTools "Bash(python -m pytest *)" \  # the test command
  --output-format stream-json --verbose         # one JSON event per line

The script fails if the result line's permission_denials is not empty. It leaves out --bare, because CLAUDE.md holds the test command, and the push guard still runs.

Before starting a session, ask: who will answer a permission prompt? You, for each action → Manual, or acceptEdits while you review the diff. You, but not for every command → auto mode. Nobody → claude -p with the mode and --allowedTools written into the command.
Takeaway
  • You write CLAUDE.md; Claude writes auto memory and a subagent's memory directory. All are context, none is enforced.
  • Auto mode is a classifier, not a bypass: deny rules and hooks still apply.
  • stream-json is one JSON event per line, and the last line is the result.

check yourself

0 / 3 answered

A developer moves an Android app's network code to a new library in a long interactive Claude Code session, on a current Sonnet-family model, on her laptop. Most of her prompts are for Gradle builds and tests. She wants far fewer prompts, but risky commands, such as a force push or a production deploy, must still be checked.Which change best meets her goal?

Select one.

At 02:00 each night a script runs claude -p in a payments repository to regenerate its API docs and saves its JSON output. Next morning, in the same repository, an engineer runs claude --continue, but Claude opens her conversation from yesterday afternoon. The night run's transcript file is on disk, and she uses Claude Code only in this repository.What is the most likely root cause?

Select one.

A platform team wants a security reviewer in Claude Code that Claude hands authentication changes to on its own. The reviewer must work in its own context window and never run shell commands. Over many reviews it should build up notes on recurring issues, and every engineer's copy should read the same notes, shared through the repository.Which TWO changes together meet these needs?

Select two.

sources

  1. Claude Code Docs, "How Claude remembers your project": CLAUDE.md scopes and load order; files above the working directory at launch, subdirectories on demand, concatenated; /init and CLAUDE_CODE_NEW_INIT; /memory and /context; auto memory written by Claude, the 200-line or 25 KB MEMORY.md load, machine-local and shared across worktrees; both context, not enforced. Checked 2026-10-05.
  2. Claude Code Docs, "Create custom subagents": .claude/agents/ and ~/.claude/agents/; frontmatter fields; delegation by description, @-mention and --agent; the memory field's user, project and local directories. Checked 2026-10-05.
  3. Claude Code Docs, "Extend Claude with skills" and "Commands": custom commands merged into Skills; .claude/commands/<name>.md as /<name>; text after a command as arguments; the built-in commands named here. Checked 2026-10-05.
  4. Claude Code Docs, "Manage sessions": transcripts tied to the project directory; --continue, --resume, /resume, -n and /rename; -p and SDK sessions left out of the picker and --continue; what a resumed session restores and which flags it does not. Checked 2026-10-05.
  5. Claude Code Docs, "Choose a permission mode": the six modes and Manual as default; auto mode's classifier, what it blocks, what skips it, its model and organisation requirements, disableAutoMode; the built-in starting mode; "auto" ignored in project and local settings; deny rules in every mode; Shift+Tab. Checked 2026-10-05.
  6. Claude Code Docs, "Run Claude Code programmatically" and "CLI reference": -p loading the same context unless --bare; hooks running in -p; prompts denied with no host; text, json and stream-json; the final result message and permission_denials; --input-format stream-json; --allowedTools and --permission-mode in print mode. Checked 2026-10-05.
  7. Claude Code Docs, "Streaming Input" (Agent SDK): streaming input mode as a persistent session, beside single message input. Checked 2026-10-05.
  8. scripts/add_branch.sh, config/branches.toml, the York branch and the test command are this course's example details; the push guard comes from 7.3.