Claude Code in Practice

How Claude Code works and how to set it up well: the agentic loop and harness, where it runs, defaults (auto mode, Opus 5.5 at medium effort), CLAUDE.md, rules and auto memory, permission modes and rules, the sandbox, hooks, skills, sub-agents, MCP, plugins, output styles, checkpoints and sessions — from the official documentation.

On this page

Simple definition#

Claude Code is Anthropic’s agentic coding tool. It reads your codebase, edits files, runs commands and integrates with your development tools — in the terminal, VS Code, JetBrains IDEs, a desktop app, the browser (cloud sessions), mobile, Slack and CI. It is a harness around a Claude model: the model reasons and decides; Claude Code supplies the tools, manages what goes into the context window, and enforces permissions.

How it works: the agentic loop#

Every task runs through three blended phases — gather context, take action, verify results — repeated until the task is done. You are part of the loop: press Esc at any time to interrupt and redirect.

Tool category What Claude can do
File operations Read, edit, create, rename and reorganise files
Search Find files by pattern, search content with regex, explore codebases
Execution Run shell commands, start servers, run tests, use git
Web Search the web, fetch documentation, look up error messages
Code intelligence Type errors after edits, jump to definition, find references (with a code-intelligence plugin)
Claude Code: harness, context and controls · drawn with Archify · zoom, guided views, search and SVG/PNG export. © 2026 Samir Kumar Sahoo, all rights reserved. Open full screen ↗

Where it runs#

Surface Best for Notes
CLI Terminal workflows, scripting, remote servers Most complete surface; scripting (claude -p) and the Agent SDK are CLI-only
Desktop app Visual diff review, parallel sessions, app preview Side-by-side worktree sessions, scheduled tasks
VS Code / JetBrains Working inside the IDE Inline diffs, selection sharing
Web (cloud sessions) Long tasks that need little steering; work that continues offline Anthropic-managed or self-hosted environments; claude --cloud, /teleport to pull a session back
Mobile, Remote Control Start and monitor work away from your desk /remote-control continues a local session from another device
Integrations Chrome, GitHub Actions, GitLab CI/CD, Code Review, Slack, Claude Tag MCP and connectors for everything else

Configuration, project memory and MCP servers are shared across the local surfaces.

The defaults — and when to change them#

A new session already makes sensible choices:

  • Auto mode for interactive terminal and VS Code sessions: Claude works without routine approval prompts while a separate classifier model reviews risky actions before they run.
  • Claude Opus 5.5 at medium effort on most plans and providers.
  • Automatic delegation to sub-agents (the built-in Explore agent for broad searches) when there is a reason to.
  • Automatic compaction of the conversation as it approaches the context window.

Change a default only when a task costs more time, tokens or interruptions than it should — /usage shows where it went.

Lever Command When
Effort /effort low…max, or ultrathink in one prompt Raise for tricky bugs, flaky tests, schema changes; lower for quick iterative work; max only for hard unattended problems
Model /model opus|sonnet|haiku|fable, opusplan Sonnet for routine work, Fable for the hardest problems, Haiku for simple sub-agents; opusplan plans with Opus and executes with Sonnet
Permission mode Shift+Tab, --permission-mode See the table below
Speed /fast Fast mode on Opus when waiting costs more than tokens

Project memory: CLAUDE.md, rules and auto memory#

Claude starts every task by reading your code, and current models are very good at it. Only write down what Claude cannot find by reading the repo, or what it would rediscover every session: decisions made in meetings, deploy processes in someone’s head, the environment variable integration tests need, misleading code it must not copy.

File Location Shared with
Managed policy /Library/Application Support/ClaudeCode/CLAUDE.md (macOS), /etc/claude-code/CLAUDE.md (Linux) and the Windows equivalent Whole organisation (IT-deployed)
User ~/.claude/CLAUDE.md Only you, all projects
Project ./CLAUDE.md or ./.claude/CLAUDE.md (or AGENTS.md) Team, via Git
Local ./CLAUDE.local.md (add to .gitignore) Only you, this project
Rules .claude/rules/*.md, optionally scoped with paths: frontmatter Team; path-scoped rules load only when matching files are touched
Auto memory Written by Claude per repository Learnings and corrections; first 200 lines / 25 KB load each session

A CLAUDE.md that passes the “can Claude find this itself?” test stays short:

# Commands
- Build and test: ./mvnw -q verify
- One test: ./mvnw -q -Dtest=RefundServiceTest test
- Local stack: docker compose up -d

# Conventions
- Money is always MonetaryAmount in the domain; never double
- src/legacy/ is live, but don't copy its patterns into new code

# Gotchas
- Integration tests need KAFKA_BOOTSTRAP set, see .env.example
  • Target under 200 lines. Long files consume context and reduce adherence; move partial-scope rules to .claude/rules/ with paths: and procedures to skills.
  • Write verifiable instructions: “Run npm test before committing”, not “Test your changes”.
  • Import other files with @path/to/file; run /init to draft a first version, /memory to edit, /doctor prompt-audit to find stale or contradictory instructions.
  • Don’t shout. If a line keeps being missed, either the file is too long or the rule cannot have exceptions — then it belongs in a hook or deny rule.

Permissions#

Permission modes#

Mode Runs without asking Best for
default (shown as Manual) Reads only Sensitive work; reviewing every action
acceptEdits Reads, file edits, common filesystem commands Iterating on code you review as a diff
plan Reads (plus classifier-approved commands when auto mode is available) Exploring and planning before changing anything
auto Everything, with background classifier checks Long tasks; less prompt fatigue (the interactive default)
dontAsk Pre-approved tools only; everything else is denied Locked-down CI and scripts
bypassPermissions Everything Isolated containers and VMs only

Cycle modes with Shift+Tab; start in one with --permission-mode. Writes to protected paths are never auto-approved except in bypassPermissions. After three classifier blocks in a row (or twenty in total) auto mode pauses and asks you; blocked actions appear under Recently blocked in /permissions.

Permission rules#

{
  "permissions": {
    "allow": ["Bash(./mvnw *)", "Bash(git diff *)"],
    "ask":   ["Bash(git push *)"],
    "deny":  ["Read(./.env)", "Read(./.env.*)", "Read(./secrets/**)"]
  }
}
  • Deny rules hold in every mode, including auto and bypassPermissions; allow rules have no effect in bypassPermissions.
  • Rules match tool calls, not intent: a Read deny also catches cat .env, but not a script that opens the file; a WebFetch domain deny does not stop curl unless the sandbox is on.
  • Tune auto mode in ~/.claude/settings.json under autoMode (environment, allow, soft_deny) — keep "$defaults" in each list; /auto-mode-setup drafts it.
  • /fewer-permission-prompts scans transcripts and adds an allowlist of common read-only commands.

The sandbox#

/sandbox confines Claude’s shell commands at the OS level (macOS, Linux, WSL2): filesystem and network boundaries, with domain allowlists, and it honours your Read deny and WebFetch(domain:…) rules. Strict sandbox mode removes the “retry outside the sandbox” escape hatch. For security-relevant rules, use deny rules and the sandbox; for whole-process isolation, run Claude Code in a dev container or VM.

Extending Claude Code#

Feature What it is Add it when…
CLAUDE.md / rules Context loaded every session (rules can be path-scoped) Claude gets a convention or command wrong twice
Output style Role, tone and response format for the session You keep asking for shorter answers or a fixed format
Skill .claude/skills/<name>/SKILL.md — a procedure or knowledge; description always visible, body loaded when relevant; /name to invoke You paste the same playbook for the third time
Sub-agent .claude/agents/<name>.md — own context, tools, model, permission mode A side task floods your context, or you want an independent, read-only reviewer
Hook Command, HTTP, MCP-tool, prompt or agent handler on a lifecycle event Something must happen every time
MCP server External tools and data You keep copying data from a system Claude can’t see
Code intelligence plugin Language-server navigation and live diagnostics Typed language, large codebase
Plugin / marketplace Bundles skills, hooks, sub-agents, MCP servers; namespaced /plugin:skill A second repository needs the same setup
Artifact Publish session output as a private interactive page Output is better seen than read in a terminal

Context cost: CLAUDE.md and output styles cost tokens on every request; skills cost only their descriptions until used (zero with disable-model-invocation: true); MCP servers load tool names, with schemas on demand; hooks cost nothing unless they return context; sub-agents use their own window.

Skills#

Full detail: skills reference.

---
name: release
description: Cut a release — bump version, write changelog, tag and push so CI publishes.
disable-model-invocation: true   # only runs when you type /release
---
1. Ensure you are on main with a clean tree; otherwise stop and ask.
2. Run `./mvnw versions:set` with the new version and commit.
3. Summarise merged PRs since the last tag into CHANGELOG.md, user-facing changes only.
4. Tag v<version> and push the tag. CI publishes; never publish from your machine.

Useful frontmatter: description (when to use it), disable-model-invocation, user-invocable, allowed-tools, model, effort, context: fork (run in a sub-agent), paths (activate only for matching files), hooks.

Sub-agents#

Full detail: sub-agents reference.

Built-in sub-agents: Explore (fast, read-only search), Plan (research during plan mode) and general-purpose. Your own live in .claude/agents/ (project) or ~/.claude/agents/ (user):

---
name: reviewer
description: Reviews changed files against the spec. Use after implementing a feature, before the PR.
tools: Read, Grep, Glob
model: sonnet
---
You are reviewing code you didn't write. Check every requirement in the spec is implemented
and edge cases have tests. Report only gaps that affect correctness. Skip style.

Fields include tools, disallowedTools, model, effort, permissionMode, maxTurns, skills, mcpServers, hooks, memory (user/project/local), isolation: worktree and background. Sub-agents give parallelism, clean context and an independent reviewer — not a smarter answer, and every one costs tokens. Use model: haiku for simple jobs.

Hooks#

Full detail: hooks reference.

Hooks run your handler at fixed points of the loop. Exit code 2 blocks the action (or, for Stop, sends Claude back to work with your stderr). Use command or http hooks for real enforcement; prompt/agent hooks ask a model and are not deterministic. Add onFailure: "block" when a crashed hook must not let the action through.

Event group Events
Session SessionStart, Setup, SessionEnd, InstructionsLoaded, ConfigChange, CwdChanged
Prompt UserPromptSubmit, UserPromptExpansion
Tools PreToolUse, PermissionRequest, PermissionDenied, PostToolUse, PostToolUseFailure, PostToolBatch
Agents and tasks SubagentStart, SubagentStop, TaskCreated, TaskCompleted, TeammateIdle
Turn end Stop, StopFailure, Notification
Context PreCompact, PostCompact, PreModelSwitch, PostModelSwitch
Other FileChanged, DirectoryAdded, WorktreeCreate, WorktreeRemove, Elicitation, ElicitationResult, MessageDisplay
Where hooks enforce in the loop · drawn with Archify · zoom, guided views, search and SVG/PNG export. © 2026 Samir Kumar Sahoo, all rights reserved. Open full screen ↗
{
  "hooks": {
    "PostToolUse": [{
      "matcher": "Edit|Write",
      "hooks": [{ "type": "command",
                  "command": "npx prettier --write \"$(jq -r '.tool_input.file_path')\"" }]
    }],
    "Stop": [{
      "hooks": [{ "type": "command", "command": "./mvnw -q -DskipITs test 1>&2 || exit 2" }]
    }]
  }
}

MCP servers#

Full detail: MCP reference.

claude mcp add --transport http sentry https://mcp.sentry.dev/mcp          # remote, HTTP
claude mcp add --transport stdio db -- npx -y @bytebase/dbhub --dsn "$DSN"  # local process
claude mcp add --transport http shared --scope project https://example.com/mcp  # team, in .mcp.json
claude mcp list            # then /mcp in a session to authenticate or disable

Scopes: local (default — you, this project, stored in ~/.claude.json), project (.mcp.json, committed; each user approves it) and user (you, all projects). Prefer a CLI when one exists — with gh signed in, Claude opens PRs and reads review comments without any MCP server. Turn off servers you don’t use: their tool names sit in context.

Sessions, checkpoints and context#

  • Checkpoints: every prompt creates one. Esc Esc (on an empty prompt) or /rewind restores code, conversation, or both — or summarises from a point. Checkpoints cover Claude’s file-tool edits, not files changed only by Bash; use Git as well.
  • Sessions: claude -c continues the latest; claude -r <name> resumes a named one; /rename, /branch, /fork, /resume. claude --from-pr 123 finds sessions linked to a PR.
  • Context: /context shows what fills the window; /compact <focus> summarises; /clear starts fresh (free, and the next task stops paying for old history); /btw asks a side question without adding to history.
  • Prompt cache: about one hour on a subscription, five minutes on API keys and cloud providers. Switching model mid-session causes a slow uncached turn.

Common mistakes#

Review questions#

What does Claude Code do by default in a new interactive session? Starts in auto mode, runs Opus 5.5 at medium effort, delegates broad searches to sub-agents, and compacts automatically.

Where do you put a rule that must never be broken, such as “never read .env”? A deny permission rule (holds in every mode), plus the sandbox for OS-level enforcement — not CLAUDE.md.

How do CLAUDE.md, .claude/rules/ and skills differ? CLAUDE.md loads every session for the whole project; rules load every session or only for matching paths; skills load on demand when invoked or relevant.

What does a Stop hook that exits with code 2 do? Prevents Claude from ending its turn and sends the hook’s stderr back as the reason, so Claude keeps working until the check passes (up to a block limit).

Summary#

  • Claude Code is a harness: model decides, harness supplies tools, context and enforcement.
  • Defaults are good — auto mode, Opus 5.5 at medium, automatic delegation and compaction; change them when /usage shows a reason.
  • Keep CLAUDE.md short and about what the repo can’t tell; use rules, skills and sub-agents for scoped knowledge and work.
  • Enforce with hooks, deny rules, the sandbox and managed settings.

References#