Copilot Token Optimizer
A VS Code extension that scans your workspace, MCP tools, and Copilot settings to identify token waste and suggest fixes — reducing GitHub Copilot cost and improving completion quality.
What it scans
| Category |
What it checks |
| Workspace |
.copilotignore presence, large generated files, test snapshots, missing copilot-instructions.md |
| MCP / Tools |
Always-on servers, redundant tool schemas, cold servers (< 10 calls/30d) |
| Settings |
Implicit context scope, chat history retention, model selection, debounce |
| Code patterns |
Large Vue SFCs, verbose Python docstrings, heavy Javadoc, CDK assets in context |
Installation
# Clone and build
git clone https://github.com/your-org/copilot-token-optimizer
cd copilot-token-optimizer
npm install
npm run compile
# Install the VSIX
npx vsce package
code --install-extension copilot-token-optimizer-0.1.0.vsix
Or press F5 in VS Code to launch the Extension Development Host directly.
Commands
| Command |
Description |
Copilot Token Optimizer: Open Dashboard |
Opens the scanner panel |
Copilot Token Optimizer: Run Full Scan |
Re-runs all scanners |
Copilot Token Optimizer: Generate .copilotignore |
Auto-generates exclusion file for your stack |
Copilot Token Optimizer: Generate copilot-instructions.md |
Scaffolds .github/copilot-instructions.md |
Configuration
Add to your VS Code settings.json:
{
"copilotOptimizer.githubOrg": "your-org",
"copilotOptimizer.githubToken": "ghp_...",
"copilotOptimizer.autoScanOnOpen": true,
"copilotOptimizer.largeFileThreshold": 500,
"copilotOptimizer.awsCloudWatchRegion": "us-east-1"
}
GitHub PAT scopes required
To enable the Copilot Metrics API (per-seat usage data):
read:org
copilot (or manage_billing:copilot)
Generated files
.copilotignore
Auto-detects your stack (Python, Java, VueJS, AWS CDK, Playwright) and generates
exclusion patterns. Inherits from .gitignore. Review and commit.
.github/copilot-instructions.md
Pre-loads project conventions into every Copilot session — stack, naming rules, patterns.
A well-crafted file saves 20–30% of prompt tokens by eliminating re-explanation.
AWS CloudWatch integration
Set copilotOptimizer.awsCloudWatchRegion to export metrics to namespace
CopilotTokenOptimizer:
EstimatedMonthlyTokens
ActiveUsers
Ensure your environment has AWS credentials (AWS_PROFILE or IAM role) with
cloudwatch:PutMetricData permission.
Development
npm run watch # incremental build
F5 in VS Code # launch extension dev host
npm run lint # ESLint
Adding a new scanner rule
- Add a
PatternCheck entry in src/scanner/patternDetector.ts
- Define file extensions and the
run() function returning a Finding | null
- The finding is automatically displayed in the Code Patterns tab
Adding a new settings rule
Add a SettingRule entry in src/scanner/settingsAnalyzer.ts with the VS Code
setting key, bad values, and recommended value.
Roadmap
- [ ] Per-developer token leaderboard (from Metrics API)
- [ ] Prompt template library generator
- [ ] Multi-root workspace splitter
- [ ] GitHub Actions workflow for CI token budget enforcement
- [ ] Slack/Teams notification when monthly token budget exceeded