Token Optimization Fix
Applies the remediations surfaced by token-optimization-check. Edits files in place after explicit user confirmation per change set.
When to use
- User asks: "apply token optimization fixes", "compress copilot-instructions", "fix the audit findings", "shrink AGENTS.md", "prune MCP servers", "add output-control directive".
- Immediately after
token-optimization-check produced findings.
Inputs
One of:
- Findings report from
token-optimization-check (preferred — re-run if stale).
- User-specified target ("just compress copilot-instructions.md", "only dedupe AGENTS.md").
If neither given → invoke logic of token-optimization-check first to discover findings, then proceed.
Fix catalog
Each fix maps to a rule ID from the audit. Apply in this order (highest ROI first).
F5 — Add output-control directive (R5)
Append to .github/copilot-instructions.md (create file if missing):
Be concise. Code only for generation. No explanations unless asked.
Bullets over paragraphs.
One-line, ~12 tokens, ~40–70% output savings on code tasks.
F1 — Compress oversized always-on file (R1, R3)
Target: .github/copilot-instructions.md, AGENTS.md, CLAUDE.md.
Procedure per file:
- Read full file.
- Show user a diff preview before writing.
- Apply transforms:
- Drop articles:
the, a, an when removable.
- Drop filler:
just, really, basically, actually, simply, very.
- Drop pleasantries:
please, kindly, feel free to, I'd like you to, could you.
- Drop hedging:
maybe, perhaps, might want to, you should probably, it's important to, make sure to.
- Collapse multi-sentence prose into fragments:
[thing] [action] [reason].
- Bullets instead of paragraphs where lists fit.
- Preserve verbatim: code blocks, inline
code, URLs, file paths, technical terms, headings structure.
- Target: ≤80 lines / ~600 tokens for
copilot-instructions.md; ≤120 for AGENTS.md/CLAUDE.md.
- Write file. Report before/after line + char counts.
F4 — Strip discoverable facts (R4)
Remove lines matching:
\b(this (project|repo) (uses|is)|we use|tests? (are|live) in|main branch is)\b
- Stack declarations that any manifest reveals (
package.json, tsconfig.json, pyproject.toml, *.csproj, Cargo.toml, go.mod).
- Restatements of obvious directory structure.
Confirm each removal with user (batch: list candidates, ask "delete all? y/n/select").
F2 — Dedupe AGENTS.md ↔ copilot-instructions.md (R2)
- Diff the two files. Show overlapping lines.
- Ask user: keep in which file? (default: keep in
AGENTS.md as the cross-tool source, leave Copilot-specific rules in copilot-instructions.md).
- Remove duplicates from the non-canonical file.
F6 — Prune MCP servers (R6)
- Read
.vscode/mcp.json / .copilot/mcp-config.json.
- List each server with brief purpose.
- Ask user to mark keep/disable per server.
- For "disable" → remove from workspace config (do NOT touch user-global config).
- Report estimated savings:
removed_servers × 5 × 200 × est_steps tokens per agent task.
F9 — Add Conventional Commits hint (R9, optional)
If copilot-instructions.md lacks commit guidance and user wants it, append:
Commits: Conventional Commits. Subject ≤72 chars, imperative. Body only if "why" non-obvious.
F8 — Translate non-English always-on content (R8)
Detect CJK/Cyrillic/Hebrew blocks. Offer English equivalent. User approves before replace.
Workflow
- Confirm scope: full audit fix-up vs targeted fix.
- For each fix to apply:
- Show before/after preview (diff or summary).
- Wait for confirmation (
y / n / edit).
- Apply only on
y.
- After all fixes, run
token-optimization-check logic again. Report new score.
- Suggest
git diff --stat for the user to review.
Safety rules
- NEVER modify files outside:
.github/copilot-instructions.md, AGENTS.md, CLAUDE.md, .cursorrules, .github/instructions/**, .vscode/mcp.json, .copilot/mcp-config.json, .mcp.json.
- NEVER touch user-global config (
~/.vscode/, ~/.config/).
- NEVER delete files outright — only edit contents, or empty + leave with a header comment.
- Preserve code blocks, URLs, file paths, headings verbatim during compression.
- If a transform would change technical meaning, skip it and flag for manual review.
- Show diff preview before every write. No silent edits.
Output
After each fix:
[F<id>] <file> — <before> → <after> (Δ <n> lines, Δ ~<n> tokens)
Final summary:
## Applied fixes
- F5: added output-control directive (+12 tokens, ~50% output savings ongoing)
- F1: compressed copilot-instructions.md (142 → 68 lines, ~980 → ~520 tokens)
- F6: pruned 4 MCP servers (~3200 tokens/agent-step saved)
## New audit score
<old> → <new> / 100
## Next steps
- Review `git diff`
- Commit with: `chore: optimize copilot token usage`
Notes
- Token counts are estimates (
chars / 4).
- Never claim exact billing savings — say "estimated".
- If user says "apply all", still surface a single combined preview before writing.
- Pair skill:
token-optimization-check (read-only audit).
1---2name: token-optimization-fix3description: Applies fixes recommended by the token-optimization-check audit. Compresses always-on context files, removes discoverable facts, adds output-control directives, prunes MCP servers, and dedupes AGENTS.md vs copilot-instructions.md. Use after running the audit or when asked to fix, compress, or optimize copilot token usage in a repo.4license: MIT5---67# Token Optimization Fix89Applies the remediations surfaced by `token-optimization-check`. Edits files in place after explicit user confirmation per change set.1011## When to use1213- User asks: "apply token optimization fixes", "compress copilot-instructions", "fix the audit findings", "shrink AGENTS.md", "prune MCP servers", "add output-control directive".14- Immediately after `token-optimization-check` produced findings.1516## Inputs1718One of:191. Findings report from `token-optimization-check` (preferred — re-run if stale).202. User-specified target ("just compress copilot-instructions.md", "only dedupe AGENTS.md").2122If neither given → invoke logic of `token-optimization-check` first to discover findings, then proceed.2324## Fix catalog2526Each fix maps to a rule ID from the audit. Apply in this order (highest ROI first).2728### F5 — Add output-control directive (R5)29Append to `.github/copilot-instructions.md` (create file if missing):30```31Be concise. Code only for generation. No explanations unless asked.32Bullets over paragraphs.33```34One-line, ~12 tokens, ~40–70% output savings on code tasks.3536### F1 — Compress oversized always-on file (R1, R3)37Target: `.github/copilot-instructions.md`, `AGENTS.md`, `CLAUDE.md`.38Procedure per file:391. Read full file.402. Show user a diff preview before writing.413. Apply transforms:42 - Drop articles: `the`, `a`, `an` when removable.43 - Drop filler: `just`, `really`, `basically`, `actually`, `simply`, `very`.44 - Drop pleasantries: `please`, `kindly`, `feel free to`, `I'd like you to`, `could you`.45 - Drop hedging: `maybe`, `perhaps`, `might want to`, `you should probably`, `it's important to`, `make sure to`.46 - Collapse multi-sentence prose into fragments: `[thing] [action] [reason].`47 - Bullets instead of paragraphs where lists fit.48 - Preserve verbatim: code blocks, inline `code`, URLs, file paths, technical terms, headings structure.494. Target: ≤80 lines / ~600 tokens for `copilot-instructions.md`; ≤120 for `AGENTS.md`/`CLAUDE.md`.505. Write file. Report before/after line + char counts.5152### F4 — Strip discoverable facts (R4)53Remove lines matching:54- `\b(this (project|repo) (uses|is)|we use|tests? (are|live) in|main branch is)\b`55- Stack declarations that any manifest reveals (`package.json`, `tsconfig.json`, `pyproject.toml`, `*.csproj`, `Cargo.toml`, `go.mod`).56- Restatements of obvious directory structure.57Confirm each removal with user (batch: list candidates, ask "delete all? y/n/select").5859### F2 — Dedupe AGENTS.md ↔ copilot-instructions.md (R2)601. Diff the two files. Show overlapping lines.612. Ask user: keep in which file? (default: keep in `AGENTS.md` as the cross-tool source, leave Copilot-specific rules in `copilot-instructions.md`).623. Remove duplicates from the non-canonical file.6364### F6 — Prune MCP servers (R6)651. Read `.vscode/mcp.json` / `.copilot/mcp-config.json`.662. List each server with brief purpose.673. Ask user to mark keep/disable per server.684. For "disable" → remove from workspace config (do NOT touch user-global config).695. Report estimated savings: `removed_servers × 5 × 200 × est_steps` tokens per agent task.7071### F9 — Add Conventional Commits hint (R9, optional)72If `copilot-instructions.md` lacks commit guidance and user wants it, append:73```74Commits: Conventional Commits. Subject ≤72 chars, imperative. Body only if "why" non-obvious.75```7677### F8 — Translate non-English always-on content (R8)78Detect CJK/Cyrillic/Hebrew blocks. Offer English equivalent. User approves before replace.7980## Workflow81821. Confirm scope: full audit fix-up vs targeted fix.832. For each fix to apply:84 - Show before/after preview (diff or summary).85 - Wait for confirmation (`y` / `n` / `edit`).86 - Apply only on `y`.873. After all fixes, run `token-optimization-check` logic again. Report new score.884. Suggest `git diff --stat` for the user to review.8990## Safety rules9192- NEVER modify files outside: `.github/copilot-instructions.md`, `AGENTS.md`, `CLAUDE.md`, `.cursorrules`, `.github/instructions/**`, `.vscode/mcp.json`, `.copilot/mcp-config.json`, `.mcp.json`.93- NEVER touch user-global config (`~/.vscode/`, `~/.config/`).94- NEVER delete files outright — only edit contents, or empty + leave with a header comment.95- Preserve code blocks, URLs, file paths, headings verbatim during compression.96- If a transform would change technical meaning, skip it and flag for manual review.97- Show diff preview before every write. No silent edits.9899## Output100101After each fix:102```103[F<id>] <file> — <before> → <after> (Δ <n> lines, Δ ~<n> tokens)104```105106Final summary:107```markdown108## Applied fixes109- F5: added output-control directive (+12 tokens, ~50% output savings ongoing)110- F1: compressed copilot-instructions.md (142 → 68 lines, ~980 → ~520 tokens)111- F6: pruned 4 MCP servers (~3200 tokens/agent-step saved)112113## New audit score114<old> → <new> / 100115116## Next steps117- Review `git diff`118- Commit with: `chore: optimize copilot token usage`119```120121## Notes122123- Token counts are estimates (`chars / 4`).124- Never claim exact billing savings — say "estimated".125- If user says "apply all", still surface a single combined preview before writing.126- Pair skill: `token-optimization-check` (read-only audit).