Keep GitHub Copilot focused on the task in front of it
Cut your Copilot working-context footprint by up to 90% by keeping the always-on instructions lean and routing deep documentation only when it is relevant.
Teams often let .github/copilot-instructions.md grow into a dump of architecture notes, completed tasks, debugging journals, and one-off decisions. Even when Copilot can technically search the workspace on demand, bloated instruction files and sprawling reference docs still create noisy context, weaker answers, and less room for the code that matters now.
In one real project, the documentation footprint had drifted to 11,000 tokens before any new task-specific context was added.
copilot-token-optimizer keeps the working set small and intentional:
- One lean
.github/copilot-instructions.mdfile for always-on guidance - Three high-signal core references in
.copilot/ - Topic files in
docs/learnings/that you pull in only when a task needs them - Historical material archived out of the default path
Typical result: 11,000 β 1,300 tokens for the docs you keep in active Copilot context. That is roughly a 90% reduction.
Token estimates use a GPT-family tokenizer so the numbers track modern Copilot models much more closely than Claude-specific tooling.
Option A β no install:
npx copilot-token-optimizer initOption B β one-line install with global cpto:
curl -fsSL https://raw.githubusercontent.com/edixos/copilot-token-optimizer/main/install.sh | bash
cpto initOption C β npm global:
npm install -g @edixos/copilot-token-optimizer
cpto initMeasure first if you want a before/after estimate:
npx copilot-token-optimizer measure
# or
cpto measureyour-project/
βββ .github/
β βββ copilot-instructions.md # Always-on project instructions
βββ .copilotignore # Excludes archives and low-signal docs
βββ .copilot/
β βββ COMMON_MISTAKES.md # Critical failure modes
β βββ QUICK_START.md # Commands and daily workflows
β βββ ARCHITECTURE_MAP.md # File and feature map
β βββ completions/ # Completed task notes
β βββ sessions/ # Session logs and snapshots
β βββ templates/ # Reusable doc templates
βββ docs/
βββ INDEX.md # Navigation + token guidance
βββ learnings/ # Deep-dive topics, loaded on demand
βββ archive/ # Historical docs, never in default context
The optimizer is built around one rule: keep the default Copilot context small, and make everything else easy to discover.
Recommended working set:
.github/copilot-instructions.md ~450 tokens
.copilot/COMMON_MISTAKES.md ~350 tokens
.copilot/QUICK_START.md ~100 tokens
.copilot/ARCHITECTURE_MAP.md ~150 tokens
---------------------------------------------
Default working set ~800 tokens
Then load only the topic docs you need:
- API work:
docs/learnings/api-design.md - Testing work:
docs/learnings/testing-patterns.md - Performance work:
docs/learnings/performance.md
That usually keeps a real task around 1,300 tokens instead of dragging the entire documentation history into every Copilot chat.
cpto init auto-detects these frameworks from repo metadata and applies the right ignore patterns:
expressnextjsvuenuxtjsangulardjangorailsnestjslaravelfastapigospring-bootsvelte
Override detection when needed:
cpto init --framework nextjs
cpto init --framework django
cpto init --framework goFramework-specific setup prompts live in examples/README.md.
- Keep
.github/copilot-instructions.mdshort. It should explain where deeper knowledge lives, not duplicate it. - Put recurring mistakes in
.copilot/COMMON_MISTAKES.md. - Put commands and daily workflows in
.copilot/QUICK_START.md. - Put file layout and architectural landmarks in
.copilot/ARCHITECTURE_MAP.md. - Move durable topic knowledge into
docs/learnings/. - Archive finished work into
.copilot/completions/,.copilot/sessions/archive/, anddocs/archive/.
| Command | Description |
|---|---|
cpto init |
Create the Copilot-optimized documentation structure |
cpto measure |
Estimate the current documentation context footprint |
cpto audit |
Validate structure, token health, and ignore coverage |
cpto compress |
Deterministically reduce .github/copilot-instructions.md size |
cpto prune |
Remove stale sections from .github/copilot-instructions.md |
cpto diff |
Compare a file against its .bak token backup |
cpto watch |
Live token dashboard for the core working set |
cpto hooks |
Install and manage helper-script templates |
cpto update |
Update the CLI or refresh project content |
cpto audit
cpto compress
cpto prune
cpto diffcpto audit --jsonWithout a global install:
npx copilot-token-optimizer audit --jsonGitHub Copilot does not expose a native CLI hook settings file. Instead, cpto hooks installs optional helper scripts into .copilot/hooks/ and prints a JSON manifest you can wire into VS Code tasks, shell wrappers, or CI.
templates/hooks/
βββ pre-tool-token-guard.sh
βββ pre-tool-read-guard.sh
βββ pre-tool-bash-guard.sh
βββ post-write-token-diff.sh
βββ session-end-token-report.sh
βββ user-prompt-inject-context.sh
βββ user-prompt-inject-snapshot.sh
βββ user-prompt-validate-copilot-instructions.sh
βββ user-prompt-ghost-scanner.sh
βββ stop-session-snapshot.sh
βββ stop-path-guard.sh
βββ notification-token-display.sh
cpto hooks install --all
cpto hooks settingsThe settings command prints a machine-readable manifest of installed scripts and the bash .copilot/hooks/... command to run for each event group.
pre-tool-token-guard.shwarns when the measured working set gets too large.user-prompt-inject-context.shmatches user prompts to files indocs/learnings/and prints a lightweight context payload you can pipe into wrappers.post-write-token-diff.shrecords write sizes in.copilot/sessions/write-log.md.
Is cpto init safe on an existing repo?
Yes. If .github/copilot-instructions.md already exists, cpto init appends only missing optimizer sections unless you pass --force.
Does this only work with Copilot?
The structure is generic markdown and shell scripts, but the generated instruction file and tokenizer defaults are tuned for GitHub Copilot workflows.
Why .github/copilot-instructions.md instead of COPILOT.md?
Because .github/copilot-instructions.md matches GitHub Copilotβs standard instruction-file convention.
What if my project already has too much documentation?
Run cpto measure, move long-lived knowledge into docs/learnings/, archive historical material, then use cpto compress and cpto prune to keep the main instruction file tight.
Framework additions, docs improvements, CLI fixes, and helper-script improvements are all welcome. See CONTRIBUTING.md.
- Bug: open an issue
- Discussion: start a discussion
MIT