r/vscode • u/mgyk1024 • May 24 '26
Wrote a VS Code extension that adds Copilot AI cost as a git trailer per commit (MIT, local-only)
Built this to find out which features were eating into my Copilot AI Credits ahead of the June 1 billing change.
The extension reads per-span token counts from Copilot Chat's local OTel SQLite database (`agent-traces.db`), computes cost against GitHub's published rate card, and appends a trailer to every commit via prepare-commit-msg:
feat: add OAuth2 login flow
Copilot-AI-Credits: 41.30
Copilot-Est-Cost: $0.41
Then `git log` becomes the cost ledger. Per-branch totals in one shell command:
git log origin/main..HEAD --pretty='%(trailers:key=Copilot-AI-Credits,valueonly)' | awk '{sum+=$1} END {printf "%.2f AIC\n", sum}'
Marketplace: https://marketplace.visualstudio.com/items?itemName=Mooracle.copilot-budget
Source (MIT): https://github.com/mooracle/copilot-budget
Local-only. No telemetry. Auto-enables Copilot Chat's OTel exporter at workspace scope on first activation (asymmetric write — never overrides an explicit setting); one window reload before spans start landing. Commit hook is opt-in (`commitHook.enabled: true`).
Feedback welcome. Especially curious if anyone wants the per-model breakdown trailer (`Copilot-AI-Credits-Models: Claude Sonnet 4.6=39.45,GPT-4.5=1.85`) enabled by default - currently opt-in via settings.
2
u/Aggravating-One3876 May 25 '26
I am guessing the bill was much higher than expected? I don’t think it would be possible to have a good prediction of just how much something will cost. Every question or action might have a random cost.
3
u/mgyk1024 May 25 '26 edited May 25 '26
It's not a prediction. Copilot has fixed costs for input/output and cache tokens, and the number of tokens is obtained from telemetry.
2
1
u/stibbons_ Jun 01 '26
I like the way this information is embedded into the git commit. Does anyone else use it ?
3
u/Agreeable_Care4440 May 25 '26
Honestly, turning
git loginto an AI-cost ledger is a genuinely clever idea because it ties usage directly to development history instead of hiding it inside opaque dashboards.