July 30, 2026
How to Read and Control Agent Costs in Visual Studio Code
Session-level cost tracking, debug logs, and a small ledger for turning credit data into decisions

By Pierre DeBois
7 min read
Imagine yourself closing a three-hour debugging session, feeling good about the work. Later that week the monthly sessions indicate lower metrics than it should. The resulting question: Which session was expensive, and what made it expensive, are questions your tooling could not answer.
Visual Studio Code changed that across its June and July 2026 releases. Version 1.126 added session-level cost, so you see the total for an entire chat session rather than the cost of individual turns. Version 1.127 extended that to delegated work, where hovering over a subagent section shows the AI Credits that piece consumed.
The visibility is useful on its own. It becomes far more useful once you record what it tells you, which is why I wrote this article. Let's take a look at the process.
The Unit You Are Actually Spending
GitHub Copilot measures chargeable interactions in AI Credits. Each Copilot plan includes a monthly allowance, and different actions consume credits at different rates based on the model and the number of tokens processed.
The different rates receive the closest attention when you are examining model costs. Cost is a function of model choice and token volume, which means the same task can cost wildly different amounts depending on how you set it up. An agentic task spanning prompts, edits, reviews, tests, and documentation accumulates across every one of those steps.
The model picker shows cost details in its hover menu, including cost per token type and a generic cost tier label of Low, Medium, or High. Reading that label before you start is the cheapest optimization available.
Three Places to Look
Cost information lives in three separate surfaces, and each answers a different question.
The Copilot status dashboard, reachable from the Status Bar, shows the percentage of your monthly allowance consumed. This is your budget question, answered at the account level.
Session-level cost in the chat session answers which conversation was expensive. Subagent sections carry their own credit figures, so delegated work is attributable rather than buried in a session total.
Agent Debug Logs answer why. The Summary view shows aggregate token usage for the session, including total tool calls and overall duration. The Cache Explorer view shows prompt cache hit rates and how many input tokens were reused, since providers can reuse a request prefix that matches a previous one and reduce both latency and token cost.
A session with a high tool-call count and a low cache hit rate is the profile you are hunting for. That combination means the agent repeatedly rebuilt context it could have reused.
Getting Recommendations From Your Own Activity
VS Code exposes a command that analyzes what you have actually been doing rather than offering generic advice.
## Run inside any chat session
/chronicle:cost-tips
## Related context-management commands
/compact
/compact focus on the API design decisions
/fork## Run inside any chat session
/chronicle:cost-tips
## Related context-management commands
/compact
/compact focus on the API design decisions
/forkLet's look at each command listed in the example to highlight the definition and purpose behind each.
The /chronicle:cost-tips command produces personalized recommendations for optimizing credit usage based on your recent activity. It is worth running after a week of normal work rather than on day one, since it needs activity to analyze.
/compact summarizes older parts of a conversation and reclaims context window space, and it accepts an optional instruction to steer what the summary preserves. That optional argument matters more than it appears. A generic compaction can discard the reasoning you most need, so naming the thread you care about keeps the useful part and drops the rest.
/fork creates a new session that inherits the existing conversation history, which avoids re-establishing context from scratch when you want to explore an alternative. Forking is a cost technique as much as a workflow technique, because re-prompting a fresh session to rebuild context you already paid for is pure waste.
Routing Work to Cheaper Models
The largest single lever is matching model capability to task complexity. Lighter models handle quick edits, boilerplate, and straightforward questions. Reasoning models earn their cost on complex refactoring, architectural decisions, and multi-step debugging.
Automating that routing beats remembering to do it manually. Custom agents accept a preferred model, and when you invoke a custom agent as a subagent it uses its own configured model instead of the chat session's model.
---
name: docstring-writer
description: Adds and standardizes function documentation across R and Python files
model: <a lighter model available in your model picker>
tools:
- edit
- search
---
Write and standardize documentation for the functions you are given.
Follow roxygen2 conventions for R files and numpy-style docstrings for Python files.
Do not modify function logic, argument names, or return values.
Ask before changing any function signature.---
name: docstring-writer
description: Adds and standardizes function documentation across R and Python files
model: <a lighter model available in your model picker>
tools:
- edit
- search
---
Write and standardize documentation for the functions you are given.
Follow roxygen2 conventions for R files and numpy-style docstrings for Python files.
Do not modify function logic, argument names, or return values.
Ask before changing any function signature.The model field is the cost control. A documentation pass is mechanical work that a light model handles well, and pinning it to that model means the routing happens whether or not you remember to think about it.
The tools property is the second lever, and it is easy to overlook. Every tool call produces output that consumes context window space and contributes to credit consumption. Restricting an agent to only the tools its workflow needs prevents calls that were never going to help. A documentation agent has no business running a terminal.
Verify the frontmatter fields against your VS Code version before relying on this, since the custom agent format has moved across recent releases. The Configure Tools button in the chat input handles the same restriction for a single request when you do not want a permanent agent definition.
Separating Planning From Implementation
Jumping straight to code generation means running a reasoning model through the entire process, including the mechanical parts that never needed it.
The documented pattern splits the work. Use the Plan agent to research the task and produce a structured implementation plan. Review and refine that plan before any code gets written. Then hand the approved plan to an implementation agent running a faster model.
The savings come from two directions. You pay reasoning-model rates only for the phase that benefits from reasoning, and a reviewed plan reduces the rework cycles that quietly consume more credits than the original attempt.
Two habits support this. Start a new chat session when you change topics, since an accumulated conversation makes the model process irrelevant history on every subsequent turn. Exclude generated files, build outputs, and irrelevant directories from context, using .gitignore for the workspace index and the files.exclude setting to hide files from VS Code entirely.
Building a Cost Ledger
Session cost is visible while you are in the session and gone once you move on. Turning that into a spending pattern requires writing it down. A script for a small ledger can do that job well.
The log_session function keeps the recording step short enough that you will actually do it. The append = TRUE branch in write_csv means the ledger grows without a database, and the file.exists check writes headers only on the first call. Every field maps to something the editor already showed you, so logging a session is transcription rather than estimation.
The shipped column is the one that turns cost data into decision data. Credits spent on work that reached production and credits spent on abandoned exploration are different categories, and separating them is the difference between a spending report and a return calculation.
The next step after the logging syntax is creating the ledger object which will contain the supporting cost metrics.
group_by across month and task type produces the comparison that matters, which is how the same category of work trends over time. median_credits sits alongside the total deliberately, because one runaway session distorts a mean and hides the typical case.
ship_rate and the derived credits_per_shipped carry the real finding. A task type consuming heavy credits with a high ship rate is working as intended. The same spend with a low ship rate points at a task you are handing to an agent that the agent is not suited to, and no amount of model tuning fixes that.
mean_cache_hit flags the mechanical problem separately. A task type with consistently low cache reuse usually means sessions are being restarted when they should be forked, or context is being rebuilt on every run.
The ledger code will lead to a tibble that shows sessions, credits, and downstream metrics like credits per shipped.
The Value of Cost Visibility
Cost visibility only pays off when it changes operational behavior. Behavior changes on evidence rather than on a number you glanced at once. The editor now shows you what a session costs. Recording session activity is what turns that cost into an answer about which work belongs with an agent.
Your best bet is to start with crafting the ledger before the optimizations. Two weeks of honest logging will tell you which task types justify their spend, and that answer is specific to how you work rather than borrowed from a general guide.
The optimizations then apply themselves in order. Route mechanical work to lighter models through custom agents, fork instead of restarting, compact long conversations with a stated focus, and strip tools an agent has no reason to call. Each of those is small. Together they change the shape of a monthly bill.
You can learn more about AI credit usage in Visual Studio Code at the main documentation, which you can view at the following link:
Optimize AI credit usage in VS Code Tips to optimize your AI credit usage in VS Code by choosing efficient models, managing context, and monitoring…
There is also a documentation page for AI credit usage in GitHub Copilot, which you can access at the following link:
Usage-based billing for organizations and enterprises - GitHub Docs Under usage-based billing, Copilot usage in organizations and enterprises is measured in AI credits.
Here is also the gist for the ledger code.
[Embedded content: a05d9f7ef334ea09a4ab58a0641d86d8]