Vibe Coding
Back to Claude Code

Claude Code / core concepts

context window

Understand how the Claude Code context window is used by system prompts, memories, project rules, file reading, hooks, command output, subagents, and compression.

context window key concepts infographic
context window key concepts infographic

What is context window

The context window is the information space that Claude can simultaneously consider in his current session. The official page uses an interactive simulation to show how it gradually fills up from startup content, user prompts, file reading, rules, hooks, command output and subagent results.

What you see in the terminal are usually short events, such as "Read auth.ts" or "Ran npm test". But what Claude actually sees is the file content, tool results, rule content, Hook output and conversation history, which will occupy the token.

Without good context window management, long tasks will become slower and more expensive, and it will be easier to forget early constraints. Managed well, Claude can stay focused, offloading large-scale investigations to subagents or skills, and keeping only key findings in the main session.

What is loaded automatically on startup

At the beginning of the session, Claude was not blank. It loads system prompts, environment information, MCP tool summary, skill descriptions, global and project CLAUDE.md, and Git/workspace information.

contentfunctionLearning points
System promptCore behaviors, tools, and response formats.Invisible to the user but always on top.
Auto memoryCommands, patterns, and pitfalls learned from past sessions.Usually only the first part is loaded to avoid oversize.
Environment infoWorking directory, system, shell, Git status.Help Claude understand the current operating environment.
MCP tools / SkillsList available tools and skills.The full schema or skill body is usually loaded on demand.
CLAUDE.mdGlobal and project directives.One of the most important sources of team context.

What things in the task will occupy the context

User prompts, Claude analysis, read file contents, search results, command output, diffs, Hook's additionalContext and final summary all enter the context.

  • File reads are usually the largest overhead. Letting Claude accurately read the relevant files saves more context than letting it scan the entire repository.
  • Search results, test output, and build logs also take up space, and failure logs should retain key sections.
  • Hook normal stdout does not necessarily enter the context, but the structured additionalContext does, so it must be streamlined.
  • Subsequent questions from the user will be appended to the same context, and the status of long tasks must be summarized regularly.

When rules and hooks fire

Path rules are automatically loaded when Claude reads matching files. For example, api-conventions.md is loaded when src/api/** is read, and testing.md is loaded when *.test.ts is read. Hooks are fired before and after tool calls, and may inject additional information into the context.

This means that rules and hooks are not just "backend configuration", they change Claude's input. Too long rules will slow down the task, and too much Hook output will pollute the context. Writing rules as short, specific, enforceable constraints is more effective than writing long tutorials.

PostToolUse hook outputs JSON:
{
  "hookSpecificOutput": {
    "additionalContext": "Format check passed. No lint errors."
  }
}

How subagents protect the main context

When a task requires extensive investigation, subagents get independent context windows. It loads its own system prompts, project rules, and tool summaries, but does not inherit the full history of the main session.

The official simulation shows a scenario where a master session lets subagents study session timeout. The large number of files and search results read by the subagent mainly consumes the subagent context, and the main session only receives the conclusions it returns.

This is why large-scale codebase surveys, risk troubleshooting, and cross-document reviews are suitable to be handed over to subagents: the main session is kept light and only key information and change plans are ultimately integrated.

Compression and loss of boundaries

Claude Code may compress the session when the context is close to the upper limit. Compression preserves summaries, but details, user boundaries, and temporary constraints in earlier messages may be weakened.

Important boundaries should be written as rules

If "don't deploy", "don't push" and "don't change payment logic" are hard constraints, don't just say them once in the chat. Should be written into CLAUDE.md, rules, permissions deny or Hooks.

Context management practices

Treat context like budget management. Give Claude precise tasks that require planning ahead, limit the read scope, use subagents to investigate, have it summarize status periodically, and put long-term rules into the correct files.

1

before task

Describe the target, related paths, ranges not to touch, and verification commands.

2

Under investigation

Let Claude first list the files it is going to read to avoid boundless scanning.

3

long task

At the end of each stage, Claude summarizes the changed files, verification results, and remaining risks.

4

large-scale research

Have subagents or independent sessions investigate and summarize conclusions back to the main thread.

Study Checklist

Put the content on this page into real tasks and use the five dimensions of entry, context, permissions, verification and team rules to check whether you have truly mastered it.

Study Checklist

After reading this page, do not just remember the concept name. You should be able to place "context window" back into a real Claude Code engineering workflow: where the task starts, what context the system loads, which actions need approval, how the result is verified, and how to roll back when it fails.

If this is a concept page, be specific about how it affects the real task: does it change context, permissions, execution paths, validation methods, or changes the team collaboration process.

  • Be able to describe in your own words the specific problem this page solves, rather than just reciting the title.
  • Able to write a minimal example task with goals, scope, prohibitions, and acceptance criteria.
  • Be able to determine which information should be put into the current prompt and which should be captured as project rules or configurations.
  • Be able to explain which long-term rules should go into CLAUDE.md, and which runtime behavior should be handled by settings, permissions, Hooks, Skills and MCP.
  • Ability to check diffs, command output, test results, screenshots or PR notes after a task is completed instead of just trusting the natural language summary.

If this page is used for team training, ask learners to complete a small task with Claude Code: read and explain first, submit a plan, make the smallest useful change, and close with real verification commands plus human diff review.