Inside Claude Code: How CLAUDE.md, Hooks, Skills, and Subagents Actually Work
For developers relying on Claude Code or Codex for daily coding, understanding these five mechanisms is the difference between a tool that works reliably and one that seems to "forget" instructions or behave unpredictably. The same architectural patterns — context budgeting, layered rules, mandatory hooks, on-demand skills, and isolated subagents — are becoming standard across AI coding agents, making this knowledge transferable to any agent harness.
Claude Code's context window holds seven types of content, not just conversation history — file contents, command outputs, CLAUDE.md, auto-memory, loaded Skills, and system instructions all compete for space. When the window fills, Claude Code first clears older tool outputs, then compresses the conversation history into a summary. This compression is the real reason Claude "forgets" instructions in long sessions: rules mentioned in round three become a vague sentence after compression.
The solution is to put persistent rules into CLAUDE.md, which gets re-injected after every compression. CLAUDE.md loads from four concatenated levels — managed policy, user, project, and local — and all levels merge rather than override, which can cause conflicting rules. For rules that must be enforced, Hooks provide mandatory interception at over 20 lifecycle events, from session start to individual tool calls. Hooks can block, allow, ask, or even modify tool inputs before Claude executes them.
Skills load on demand from a 1% context budget index, so a poorly written description means Claude never discovers the Skill exists. Subagents run in isolated context windows, with three built-in types — Explore (fast, read-only Haiku), Plan (read-only, inherits main model), and General-purpose (full tools, loads CLAUDE.md). Custom Subagents can be defined in Markdown files with their own tools, models, and even dedicated MCP servers.
The most common reason Claude Code "forgets" instructions is not a model limitation but a predictable consequence of context compression — the real fix is structural, not prompt-based.
CLAUDE.md's concatenation design is a double-edged sword: it enables layered rules but creates silent conflicts when different levels specify contradictory instructions.
Hooks are the most underutilized feature — the ability to modify tool inputs before execution opens up security and compliance use cases far beyond simple validation.
The 1% context budget for Skill index means developers must treat Skill descriptions as critical UX copy, not afterthoughts.
Explore and Plan Subagents skipping CLAUDE.md is a deliberate trade-off that prioritizes speed over rule adherence — a design lesson for any multi-agent system.
Custom Subagents with dedicated MCP servers represent a new architectural pattern: disposable, task-specific micro-environments that don't pollute the main context.
The five-mechanism architecture (CLAUDE.md, Hooks, Skills, Subagents, context management) is becoming a de facto standard for AI coding agents — learning it on Claude Code transfers directly to Codex and future tools.