Token Consumption Optimization
With usage-based billing, every token you send and receive costs money. This page covers practical strategies to reduce token consumption without sacrificing output quality โ ordered by impact so you can focus on what matters most.
Choose the Right Model for the Taskโ
Impact: High ยท Effort: Low
The single biggest cost lever is not defaulting to the most powerful (and expensive) model for every interaction.
| Task type | Recommended tier | Typical families |
|---|---|---|
| Quick questions, boilerplate, explanations, codebase search | Fast / small | Claude Haiku, GPT mini variants, Gemini Flash |
| Everyday coding and agent sessions | Balanced | Claude Sonnet, GPT general-purpose models |
| Complex reasoning, large refactors, architecture | Frontier | Claude Opus, top-end GPT and Gemini Pro models |
In Copilot, model costs are based on token usage and converted into GitHub AI Credits. Check the current model pricing when estimating costs. Premium-request multipliers apply only to existing annual Copilot Pro/Pro+ subscribers who remain on legacy billing.
In VS Code Copilot, use the model picker in the chat panel to switch models per-conversation. Default to a cheaper model and escalate only when you need stronger reasoning.
For a detailed model selection breakdown, see the model comparison table in Prompt Engineering.
Set Thinking Effort Appropriatelyโ
Impact: High ยท Effort: Low
Reasoning models (Claude, GPT reasoning models, Gemini) consume tokens on internal reasoning. You can control how much they think.
- High effort: architecture decisions, complex debugging, multi-step refactors
- Low effort: code generation, formatting, boilerplate, simple explanations
Claude Codeโ
Claude Code controls this with an effort level (low, medium, high, and higher levels on models that support them). Effort affects how much the model thinks and how thorough it is with tool calls.
# In a session: set the level, or run /effort alone to open a picker
/effort low
# For a single session from the command line
claude --effort low
You can also set a default with the effortLevel key in settings.json or the CLAUDE_CODE_EFFORT_LEVEL environment variable. Available levels depend on the model โ some add xhigh and max above high โ see the Claude Code model configuration docs.
VS Code Copilotโ
Some models expose a reasoning effort option in the model picker or in VS Code settings. Availability varies by model; check the VS Code language models docs.
Lower thinking effort doesn't mean worse output for routine tasks. The model still has its full training โ you're just limiting the "scratch paper" it uses before answering.
Use Different Models for Subagentsโ
Impact: High ยท Effort: Medium
In multi-agent setups, not every agent needs frontier-level intelligence. Use an expensive orchestrator for planning and cheap workers for execution.
Pattern:
- Orchestrator (strong reasoning model): decomposes the task, makes architectural decisions
- Workers (cheaper model): execute file edits, formatting, simple transformations
A particularly effective application of this pattern is delegating broad file search and reading to a small, fast model. Frontier models consume expensive tokens every time they read or search through files โ offloading a wide search to a cheap subagent ("find the files that handle authentication and summarize how they connect") keeps those tokens out of the main conversation. Only the subagent's summary comes back.
Delegate broad exploration, not every read. Spinning up a subagent has its own overhead, so for reading one known file the main agent is cheaper. Both VS Code Copilot and Claude Code include a built-in Explore subagent for exactly this โ try it before writing your own, but check which model it runs on.
VS Code Copilotโ
Define a custom agent with a small model and read-only tools, hidden from the picker so it only runs as a subagent:
---
name: Explorer
description: Searches and reads the codebase and returns a concise summary. Use for broad, multi-file exploration.
model: "<a small, fast model from the picker>"
tools: ["read", "search"]
user-invocable: false
---
Find the files relevant to the task, read only what you need, and return a short
summary with file paths and line references. Do not edit files.
Avoid hard-coding model names in instruction files that apply to every request (applyTo: "**") โ when a model is retired, the instruction silently stops working.
Claude Codeโ
Subagents are defined as Markdown files in .claude/agents/, and the model field picks the model for each one:
---
name: explorer
description: Searches and reads the codebase and returns a concise summary. Use for broad, multi-file exploration.
tools: Read, Grep, Glob
model: haiku
---
Find the files relevant to the task, read only what you need, and return a short
summary with file paths and line references. Do not edit files.
Claude Code's built-in Explore subagent keeps noise out of the main context, but it runs on the main conversation's model โ so it only saves context, not model cost. A custom explorer with model: haiku is what actually moves the work to the cheaper model. See Claude Code Customization.
For more on the orchestrator + subagent pattern, see Multi-Agent Orchestration.
Manage Context Window Sizeโ
Impact: Medium-High ยท Effort: Low
Every token in the context window costs money โ both the input you send and the output generated in response. Bloated context is the most common source of waste.
Do:
- Reference specific files with
#fileor#codebasewith targeted queries - Close irrelevant files/tabs before starting agent sessions
- Use
.gitignore-style patterns in tool configs to exclude irrelevant directories from indexing - Configure content exclusions (org-level Copilot setting) to prevent large or sensitive files from being sent
Don't:
- Add entire directories to context when asking about one function
- Leave 30 open tabs during an agent session โ some tools include open files as context
- Include
node_modules, build output, or generated files in indexed content
Some tools silently include open editor tabs, recent files, or entire directory trees as context. Audit what your tool is actually sending โ the token count in your billing may surprise you.
Compact Long Conversationsโ
Impact: Medium ยท Effort: Low
Each new turn in a conversation re-sends the entire conversation history as input tokens. A 50-turn conversation means turn 50 includes all previous turns as input.
Claude Codeโ
Use /compact to summarize and compress conversation history:
/compact
This replaces the full history with a condensed summary, dramatically reducing input tokens for subsequent turns. Add a focus to keep what matters: /compact keep the API decisions. Claude Code also compacts automatically when the context window fills up, but compacting yourself at a natural break gives a better summary. Use /clear to start fresh when switching to an unrelated task.
VS Code Copilotโ
Copilot Chat summarizes older conversation history automatically when the context window fills up, keeping recent turns verbatim. Automatic summaries lose detail, though, so when you switch to a new task, start a new chat thread instead of extending the old one.
Rule of thumb: if your conversation exceeds ~20 turns, compact or start fresh. The accumulated context from early turns is usually no longer relevant and is burning tokens every turn.
Use Context Files to Reduce Repetitive Promptingโ
Impact: Medium ยท Effort: Medium (one-time setup)
Instead of re-explaining your architecture, conventions, or feature requirements in every prompt, document them in context files that the agent reads once at session start.
Agent Context Filesโ
Feature work may have a curated context folder at .agents/contexts/<feature-name>/. If one exists for the feature you're working on:
- Read all files in the folder before writing any code. Start with
README.mdif present. Distinguish source-of-truth files (requirements, architecture) from current-state files (assessments, known issues). - Ground your work in the documented decisions โ don't contradict them without flagging it.
- Keep context files in sync โ when your work changes scope, resolves a known issue, or introduces a new architectural decision, update the relevant context files proactively.
- Never delete or overwrite context files without explicit instruction.
If the user mentions a feature but the context path is unclear, list the available subdirectories in .agents/contexts/ and ask which context applies.
Why This Saves Tokensโ
- Context files are read once at session start โ no re-pasting every turn
- The agent produces better output with proper context, reducing regeneration
- Shared context files mean the same information works across team members and sessions
Write Better Promptsโ
Impact: Medium ยท Effort: Low
Concise, specific prompts use fewer input tokens and produce more focused (shorter) output.
- State constraints upfront โ "return only the function, no explanation" avoids a 200-token explanation you'll ignore
- Reference specific line ranges or functions instead of pasting entire files
- Be explicit about format: "respond with a code block only" vs. leaving it ambiguous
- Vague prompts produce longer, less useful outputs that you'll regenerate โ costing 2x or more
See Prompt Engineering for detailed techniques.
Avoid Regeneration Loopsโ
Impact: Medium ยท Effort: Low
Each regeneration is a full new request โ all context re-sent plus a new generation. Three regenerations cost 3x one well-crafted prompt.
Instead of hitting regenerate:
- Identify what's wrong with the output
- Edit your prompt to add the missing constraint
- Submit the refined prompt
This produces better results and costs less than hoping the next random sample will be correct.
If you find yourself regenerating more than once, the problem is almost always the prompt โ not bad luck. Add specificity rather than retrying.
Analyze Your Usageโ
Impact: Medium ยท Effort: Low
The VS Code Chronicle extension tracks session data locally and can surface optimization opportunities.
/chronicle:cost-tips
This analyzes your usage patterns and reports:
- Model overuse (using frontier models for simple tasks)
- Context bloat (sessions with unnecessarily large context)
- Retry patterns (repeated regenerations)
- Outlier sessions (unusually expensive interactions)
Setupโ
{
"github.copilot.chat.localIndex.enabled": true
}
Let it collect data for 5โ7 days before running /chronicle:cost-tips for useful recommendations.
For more details, see the Chronicle cost tips blog post.
Chronicle only covers VS Code Copilot sessions. If you also use Claude Code or other tools, you'll need to track those separately.
Batch Related Workโ
Impact: Low-Medium ยท Effort: Low
Each conversational turn has overhead: system prompt, conversation history, and tool context are all re-sent. Combine related small requests into one prompt.
Expensive (3 turns):
Turn 1: "Fix the type error on line 42 of auth.ts"
Turn 2: "Fix the type error on line 87 of auth.ts"
Turn 3: "Fix the type error on line 103 of auth.ts"
Cheaper (1 turn):
"Fix the type errors on lines 42, 87, and 103 of auth.ts"
Balance batching with clarity. If a prompt gets so complex that the model struggles, you'll end up regenerating โ which defeats the purpose. Group related items; don't create mega-prompts.
Leverage Cachingโ
Impact: Low (mostly automatic) ยท Effort: Low
Provider-side caching reduces costs for repeated context โ but it's largely automatic.
What providers do:
- Anthropic's API caches repeated system prompts and prefix content
- GitHub Copilot handles caching server-side โ you benefit automatically
What you can do to help:
- Keep instruction files (
.github/copilot-instructions.md,CLAUDE.md) stable โ don't edit them every session - Use consistent system prompts across sessions so cache hits are more likely
- Avoid unnecessarily reordering context between turns
Quick Referenceโ
| Strategy | Impact | Effort | Applies to |
|---|---|---|---|
| Choose the right model | High | Low | All tools |
| Set thinking effort | High | Low | Claude Code, o-series models |
| Different models for subagents | High | Medium | Claude Code, multi-agent setups |
| Manage context window size | Medium-High | Low | All tools |
| Compact long conversations | Medium | Low | Claude Code, VS Code Copilot |
| Context files for reuse | Medium | Medium | All tools |
| Write better prompts | Medium | Low | All tools |
| Avoid regeneration loops | Medium | Low | All tools |
| Analyze usage with Chronicle | Medium | Low | VS Code Copilot |
| Batch related work | Low-Medium | Low | All tools |
| Leverage caching | Low | Low | Anthropic API, Copilot |
Resourcesโ
- Chronicle Cost Tips Blog Post โ detailed walkthrough of the
/chronicle:cost-tipscommand - Prompt Engineering โ techniques that also reduce token waste
- Multi-Agent Orchestration โ the orchestrator + subagent pattern
- AI Coding Agents โ how agents consume context and tokens
- GitHub Copilot Billing Documentation
- Anthropic Token Counting