Managing Context
|
This content was generated with the assistance of AI and should be verified against the official documentation of each tool and framework before being relied on in production. This section’s bibliography lists the reference material consulted while preparing these pages. |
Examples on this page target the Claude Code CLI and GitHub Copilot Chat in VS Code, checked against the
official Claude Code and GitHub/VS Code documentation as of 2026-09-28. The running example is the same
DocsAssistant API Spring Boot + Python sample used across this sub-section, with its controller at
src/main/java/com/example/docsassistant/DocsController.java.
What an assistant sees
Neither tool reads your whole repository on every turn. What actually reaches the model on a given turn is a mix of a few distinct sources, and knowing which one a piece of information comes from is what makes context manageable rather than mysterious.
-
Open files. In VS Code, Copilot Chat’s automatic context can draw on files and symbols in your workspace, and the editor’s own inline and Quick Chat scope a prompt to the file (or selection) you have open, without you naming it. Claude Code’s VS Code extension works differently: it does not silently ingest whatever tab is open; instead it lets you
@-mention a file, including a specific line range taken from your current selection, so the file only enters context when you ask for it. See VS Code — Add context to chat and Claude Code — Use Claude Code in VS Code. -
Instruction files. Both tools read a project-level Markdown file automatically at the start of a conversation and fold it into context alongside your prompt: Claude Code reads
CLAUDE.md(and, alongside or instead of it, a repository’sAGENTS.md) from the current directory and its parents, and GitHub Copilot reads.github/copilot-instructions.mdfor repository-wide instructions in supported surfaces such as Copilot Chat on github.com. Using these files this way is this page’s concern; authoring good instruction files — structure, scoping rules to specific paths, keeping them short — belongs to Instruction & Memory Files. A minimalCLAUDE.mdat a repository root:# DocsAssistant API Spring Boot 3 + Java 21 backend under `src/main/java/com/example/docsassistant/`, with a Python ingestion pipeline under `ingest/`. Run `mvn test` before proposing any change as done.and the matching minimal
.github/copilot-instructions.md:# Project Overview DocsAssistant API: a Spring Boot 3 + Java 21 backend under `src/main/java/com/example/docsassistant/`. ## Testing Run `mvn test`. Tests must pass before a change is considered complete. -
@/#references. Explicitly attaching a file, folder, symbol or MCP resource, covered in more depth below. -
Tool output. Whatever a prior tool call returned in this same conversation — a file Claude read, a command’s output, a search result — stays in context until it is cleared, compacted, or (for a subagent) never shared with the main conversation in the first place.
Managing context during a session
/clear, /compact and /context
As of 2026-09-28, Claude Code’s session commands for context itself are:
| Command | What it does |
|---|---|
|
Starts a new conversation with an empty context window; the previous one is not summarized, just left behind
(a plain named session you can still |
|
Frees up space in the current conversation by summarizing it in place; takes optional focus instructions, for
example |
|
Visualizes what is currently consuming the context window — system prompt, tools, instruction files, MCP tool listings, conversation history — so you can see why it filled up, not just that it did. |
$ claude
> /compact focus on the DocsController changes and the failing test
> /context
See Claude Code — Manage costs effectively and
Claude Code — Commands. In VS Code, Copilot chat has the same
/compact [instructions] command (also offered as Compact Conversation from the chat’s context window
control), and the Copilot CLI has /compact too — see
VS Code — Manage agent sessions.
A new chat (the New Chat action in the Chat view) is Copilot’s version of starting fresh, since a chat’s
history keeps feeding every later turn in that same conversation until you start a new one — see
VS Code — Use chat in VS Code.
Starting fresh vs. long sessions
A long-running session accumulates every file read, command output and prior turn, so a simple question late in
a multi-hour session can cost as much as re-processing the whole conversation. The practical rule from Claude
Code’s own cost guidance is to /clear between unrelated tasks — fixing the failing DocsController test is
unrelated to a later refactor of the Python ingestion script — and to reach for /compact only when you want
to keep the thread of one long task while trimming what got it there. Renaming a session with /rename before
clearing keeps it easy to find again with --resume. See
Claude Code — Manage costs effectively.
Scoping with @ / #
Naming exactly what you mean is cheaper and more reliable than letting the assistant search for it:
#DocsController.java #selection Explain why this endpoint returns 500 instead of 404
when the page id doesn't exist.
$ claude "why does @src/main/java/com/example/docsassistant/DocsController.java return 500
instead of 404 for a missing page id?"
An @ reference in Claude Code also pulls in any CLAUDE.md in that file’s directory and its parent
directories, which is one more reason a broad @-mention of a whole directory (shown as a listing, not its
contents) is a cheaper first step than reading every file in it. See
Claude Code — Common workflows and
VS Code — Add context to chat.
Subagents for research
A subagent runs in its own, separate context window: it does not see your conversation history or the files you have already read, and when it finishes it returns only a summary to the main conversation, not everything it read along the way. That makes it the right tool for a research task whose process is verbose but whose answer is short — exploring an unfamiliar module, for instance — because none of the exploration’s file reads land in the context you keep working in:
$ claude "use a subagent to investigate how DocsController's pagination and PageRepository
interact, and summarize the flow"
See Claude Code — Subagents and Claude Code — Common workflows for defining a named, reusable subagent instead of relying on this automatic, on-the-fly delegation — covered in more depth in Subagents & Custom Agents. For the deeper mechanics behind why isolating a subagent’s context works — context budgets, progressive disclosure, why "lost in the middle" makes a smaller, cleaner context perform better than a stuffed one — see Context Engineering and, for how the window itself behaves as it fills up, Context Windows & Memory.
Token and cost awareness
Every extra file, tool result and turn kept in context costs tokens, and both tools meter usage differently, so this page links to each product’s own accounting rather than restating figures that change on their own schedule:
-
GitHub Copilot moved every plan to usage-based billing on 2026-06-01: each plan includes a monthly allowance of GitHub AI Credits, and every interaction is charged in credits according to the model used and the input, output and cached tokens it consumes, so a long agent session on a large model draws far more than a quick question on a lightweight one. Unused credits do not roll over, and beyond the allowance you either set an additional budget, upgrade the plan or wait for the monthly reset. The earlier per-request premium requests model is now documented as legacy, applying only to some existing annual subscribers. As of 2026-09-28, see GitHub — Usage-based billing for individuals, GitHub — Usage-based billing for organizations and enterprises and GitHub — Plans for GitHub Copilot for the current figures.
-
Claude Code plans meter usage over rolling windows, and
/usageinside a session shows your own consumption and, on a paid plan, a breakdown of what is drawing on it (including any subagents). See Claude Code — Manage costs effectively. Fast mode (/fast), a faster, higher-priced configuration of Opus only, is billed separately: on a subscription plan it draws from usage credits rather than the plan’s included usage. See Claude Code — Speed up responses with fast mode.
Both pages are the source of truth for the actual limits; this page only points at how to watch your own usage
(/context, /usage) and the levers above (/clear, /compact, scoping with @ / #, delegating to
subagents) that keep it down.