Claude Code

How it works and the extension map

Claude Code's agentic loop, models, tools, context loading, execution environments, extensions, and five-minute/one-hour caching.

This guide combines the official Overview, How Claude Code works and Extend Claude Code guides into a practical map. Understand the client before choosing CLAUDE.md, a skill, subagent, MCP, hook or plugin.

Claude Code is an agent harness around the Claude model. It loads project context, exposes tools, executes commands, manages permissions, saves sessions and feeds results back to the model for the next decision.

#Agentic loop

Three stages repeat and overlap throughout a real task:

StageWhat Claude doesYour contribution
Gather contextReads files, searches symbols, checks Git, loads CLAUDE.md, rules, skills and MCP informationSupply the goal, paths, logs, screenshots and boundaries
Take actionEdits files, runs commands, calls MCP, dispatches subagents, writes plans or generates artifactsSet permissions and interrupt an incorrect direction
Verify resultsRuns tests, lint and builds, checks diffs, verifies in a browser or GUIProvide acceptance commands and failure evidence

This is not a fixed script. The model chooses the next step from previous tool results: inspect code, edit, test, then revisit a failed implementation.

#Models, tools and the harness

PartRoleTypical configuration
ModelUnderstands code, breaks down work, chooses actions and explains results/model, --model, /effort, fast mode, fallback model
ToolsRead files, edit code, run commands, access pages and external systemsPermissions, MCP, hooks, tool search, sandbox
HarnessSessions, context, permissions, calls, checkpoints, transcripts, status line and UISettings, CLAUDE_CONFIG_DIR, ~/.claude/projects

Model and effort settings participate in cache matching. Repeated /model or /effort changes prevent reuse across those configurations, regardless of five-minute or one-hour TTL.

#Built-in capability map

CategoryCapabilitiesLocal guide
FilesRead, Edit, Write, MultiEdit, diff inspectionTool reference
SearchGlob, Grep, code exploration and history searchLarge repositories
ExecutionBash, tests, builds, Git, background Bash, MonitorInteractive terminal
Web/browserWebFetch, WebSearch, Chrome, Computer UseChrome and Computer Use
External systemsMCP, Channels, GitHub, Slack, databases, ticketsMCP
AutomationHeadless, routines, /loop, CI, code reviewHeadless automation

#Execution surfaces

SurfaceExecution locationProvider/cache boundary
Terminal CLILocal working directoryStraightforward Passion8 setup with controlled local configuration
VS Code / JetBrainsIDE-managed Claude Code processCheck inherited Base URL, token, proxy and certificates
DesktopDesktop-managed local or organization environmentDepends on login and organization policy
Web / Slack / cloud reviewAnthropic cloudUsually does not inherit local Passion8 variables or caches
Agent SDKYour service starts a claude subprocessPlan state, isolation and caching for each worker/session

Moving from the local CLI to web/cloud review does not imply shared caches. These are usually different sessions, providers and execution environments.

#Context loading

Earlier, stable context is more likely to become a reusable cache prefix.

SourceWhen loadedCache effect
System prompt and tool definitionsSession start and capability changesCritical cache prefix
CLAUDE.mdCurrent/parent directories at startup; child directories on demandChanges usually require a new session and change the prefix
.claude/rules/Session start or matching filesPath-specific rules reduce unrelated context
Skill descriptionsAt startup so the model can choose skillsMore descriptions increase fixed input
Skill bodyInvocation or a matching needAppended as a message, usually preserving earlier prefixes
MCP names and schemasServer startup or deferred tool searchUpfront schemas are more likely to cause misses
Hook outputWhen the hook returns contextLonger output increases subsequent input
Subagent findingsWhen the subagent reportsIntermediate work does not occupy main-session context

Keep CLAUDE.md short, stable and relevant to every session. Put occasional references in skills, connect external systems through MCP, and enforce mandatory rules through hooks or permissions.

#Choose an extension

ProblemUseReason
Claude forgets build commands or path conventionsCLAUDE.mdNeeded in every session
A workflow repeats but is not always neededSkillLoad on demand; invoke with /skill-name
A rule applies to certain paths or file types.claude/rules/Reduces root-file noise
Access Jira, Slack, databases, browsers or internal APIsMCPServer manages connection and authentication
Automatic formatting, command blocking or notificationsHookDeterministic lifecycle behavior
Broad investigation whose intermediate work is unnecessary in the main sessionSubagentIsolates context and returns findings
Several Claude sessions must cooperateAgent TeamsSession communication and shared tasks
Share skills/hooks/MCP across projectsPluginVersioning and distribution

#Common distinctions

ComparisonGuidance
CLAUDE.md vs skillAlways-on vs on-demand; split a root file over about 200 lines into skills/rules
Skill vs subagentKnowledge/workflow vs independent worker; skills add main context while subagents isolate it
MCP vs skillTool/data connections vs instructions on using them; commonly combined
Hook vs skillEvent-triggered enforcement vs reasoning-based workflow
Subagent vs Agent TeamReports to a parent vs multiple complete sessions cooperating

#Cache and cost perspective

ActionFive-minute/one-hour effect
Continue the same conversationCache hits refresh TTL; five minutes suits frequent work
Return after 10–45 minutesFive-minute entries are often cold; one-hour entries may remain
Edit CLAUDE.md and restartNew prefix requires a cache write
Add/remove MCP serversTool definitions change; tool search can help
Invoke a skillAppends its body while usually preserving earlier prefixes
Large hook outputMay preserve the prefix but increases future input
Broad subagent explorationSubagent incurs tokens; main session receives a compact report
Plugin containing MCPMay change descriptions and tool definitions; inspect cache creation after reload

See command cache effects and prompt caching for TTL and usage fields.

  1. Run /init and record core project conventions in CLAUDE.md.
  2. Add sensitive paths to permission deny rules rather than relying only on prose.
  3. Turn repeated prompts into skills or custom commands.
  4. Add hooks for required formatting, auditing and notifications.
  5. Connect external systems with MCP when needed and check tool search.
  6. Introduce subagents, worktrees, Agent Teams or the SDK for larger tasks.
  7. Package reusable cross-project configuration as a plugin or internal marketplace.

#Official references

Support

Need help?

For setup, billing, or model issues, email us. Check the status page for uptime.

WeChat / QQ support is available at the bottom right.