Inside Claude Code: Understanding How Context, Tokens, Tools, and Subagents Work
Claude Code assembles layered context from rules, Skills, MCP, files, and tool output, then manages tokens and subagents while running tests.
Key Takeaways
- Claude Code does not load an entire repository into the model; it builds a working context by retrieving only the relevant files, tools, and results needed for each task.
- Context is assembled in layers through CLAUDE.md, path-specific rules, and Skills, allowing persistent project guidance without overloading every request.
- MCP tools, subagents, and tool outputs become part of the execution loop, while subagents can return distilled results to keep the main context smaller.
- Token usage grows across multiple turns, not from a single prompt, because each step may include prior context, file reads, tool calls, and task state.
- The context window is not the same as actual token consumption: a large repository can exceed the window without Claude Code loading all of it at once.
Meta description: Learn how Claude Code assembles context, loads CLAUDE.md, Skills, MCP results, and tool output while generating tests and managing token use.
Tags: Claude Code, context engineering, coding agents, token usage, MCP
Featured image: An abstract, friendly illustration of repository files, search tools, test output, and token counters flowing into a model loop, with no real people, logos, or text.
When a developer gives Claude Code a coding task on a large repository, the agent does not send the entire codebase to the model. It builds a working context, searches and edits files, runs commands, reads results, and decides the next action. Anthropic describes this as a model working with tools in a loop. For developers and architects, a prompt like “Analyze this Spring Boot repository, identify the technology stack, generate JUnit 5 tests for BookingService, run the tests, fix failures, and prepare changes for review” is a chain of decisions: what to learn, which files to inspect, which tools to call, and what to do after each result.
Claude Code Uses a Working Set, Not a Repository Dump
A repository with 5 million lines of code, thousands of files, multiple modules, Java and Spring Boot, Angular, Docker, Kubernetes, Terraform, and CI/CD cannot become one giant prompt. Anthropic describes Claude Code as using a hybrid context strategy, and uses it as an example of navigating large environments without loading the entire environment into context. CLAUDE.md may load early, while file search and shell commands retrieve information just in time. The useful question is not “How big is my repository?” but “Which parts did Claude retrieve for this task?”
Anthropic defines context as the tokens available during an inference and emphasizes continuously curating it as the task progresses. Context can include system instructions, tools, MCP, external data, message history, and task results. In Claude Code, it can grow from project instructions and the current prompt into previous conversation, relevant files, tool results, MCP results, test failures, and state needed for the next decision. When context grows too large, compaction can summarize earlier history. After a subagent finishes, the main agent can receive a result rather than the full exploration.
CLAUDE.md, Rules, and Skills Load Context in Layers
Separate knowledge from work: CLAUDE.md and Skills influence what Claude knows; subagents and Agent Teams perform work in separate contexts.
CLAUDE.md holds persistent project instructions. It might say to use Maven, not Gradle; run unit tests with ./mvnw test; use JUnit 5 and Mockito; do not modify src/legacy; use constructor injection; and follow existing exception-handling patterns. Because it stays relevant across turns, it is a token decision; Anthropic recommends keeping it focused, not a full repository manual.
Rules add path-specific context. In a monorepo, conventions may differ under src/test/, src/security/, or src/legacy/**. A rule can apply only in the relevant area, so not every fact rides along in every request.
Skills load reusable knowledge when needed. A spring-boot-testing skill can carry JUnit conventions, Mockito conventions, test naming, coverage rules, test-data builders, mock verification rules, and supporting references without occupying every unrelated task. This is progressive disclosure: start small, then reveal more only when it matters.
MCP, Subagents, and Tool Results Enter the Loop
For the BookingService example, Claude Code may locate the service and inspect files around it. Repository exploration becomes part of the task. Anthropic describes just-in-time retrieval as a core technique for agents in large environments.
External context can arrive through MCP, the Model Context Protocol. A workflow may depend on Jira, internal APIs, databases, or documentation systems. Claude Code supports MCP servers, and Anthropic describes ways to limit unnecessary tool-schema context until a tool is needed. When an MCP tool returns information, that result becomes working context and influences the next decision. Hooks and permissions sit in the broader execution environment as controls around tool use; the loop still moves from context to model inference, tool execution, result, and another decision.
Subagents change the loop. Delegating work lets the main agent receive a distilled outcome while the subagent explores in its own context, reducing raw search history in the main session.
Tokens Grow Across Turns, Not From One Prompt
There is no fixed token number for a task. Anthropic does not publish a rule that generating JUnit tests for a Spring Boot service costs 40,000 tokens. Current usage documentation says each turn includes the conversation so far, project context such as CLAUDE.md and files read, and the new prompt. Claude Code provides /context to inspect the working context and /cost to inspect session token and spend information when using API billing.
If a task requires six steps—find service, inspect dependencies, inspect existing tests, generate tests, run tests, and fix failures—token use is not simply files read multiplied by one model call. Each step can build on the previous one. Anthropic notes coding-agent sessions can be more token-intensive because they include system prompts, file context, tool calls, and multi-turn work.
Context window and token usage differ. Current Claude documentation lists context windows up to 1 million tokens for supported Claude models in Claude Code, depending on model and account configuration. That does not mean Claude loads 1 million tokens every time. A five-million-token repository can exceed the context window without forcing the system to load all of it at once.
What Developers Should Watch Next
The code change is only the visible outcome of a larger execution loop. For teams, prompt quality is one part of the result. A focused CLAUDE.md, path-specific rules, Skills that load when needed, disciplined MCP usage, and clear subagent boundaries shape what the agent can do and what it costs. The practical step is to inspect /context during real tasks, watch /cost across sessions, and treat project instructions as a budgeted working set rather than a place to store every possible document.

Comments (0)