GitHub Copilot Workshop · 1h 15m

Token Optimisation 101

Step 1 of 8 ~75 min left
Issues? DM me
GitHub Copilot mascot

Workshop goal

By the end of this session, you will be able to:

UNDERSTAND

How usage-based billing turns AI consumption into cost.

COMPARE

Why input, cached input, and output tokens have different costs.

CHOOSE WELL

Right-size models and divide work into research, planning, and implementation.

INSTRUCT WELL

Use explicit and persistent instructions to improve quality and reduce output tokens.

OPTIMISE

Manage context windows, recognise context rot, and compact sessions before quality degrades.

SELF-COACH

Use session history to spot missed capabilities, cost drivers, and recurring fixes.

Duration: 10 minutes

Not all tokens are equal

Biggest bucket

Input tokens

What you send:
  • Prompts and new context
  • Can grow with large files / codebases
Relative cost Moderate
Most expensive

Output tokens

What you get:
  • AI-generated responses
  • Tool use
  • Highest per-token cost
Relative cost Highest
Cheapest

Cached tokens

What's reused:
  • Context from previous interactions in a session
  • Improves speed and efficiency
  • Least expensive per token cost
Relative cost Lowest

Example:

Input Cached Output Why
AB nothing AB First request — nothing to match against
ABC AB C AB is an exact prefix of the previous request
ABCD ABC D Prefix still intact
AXCD A XCD An edit changed B to X; the match fails there
Reference: Cache Tokens · AI Coding Dictionary

How token type changes model cost

Example pricing per 1M tokens
Model Release status Category Input Cached input Output
Claude Fable 5 GA Powerful $10.00 $1.00 $50.00
GPT-5 mini GA Lightweight $0.25 $0.025 $2.00
GitHub Docs · Model pricing Compare model costs docs.github.com/en/copilot/reference/copilot-billing/models-and-pricing#pricing-tables View pricing tables
Duration: 10 minutes

Model selection misconception

Right-size the model

Copilot Auto mode selects the best model for each task and charges 10% of model costs.

Default to Auto mode

Improve quality of output with Divide & conquer: Research → Plan → Implement

“I want to change X — what files are relevant?”
/research Gemini 2.5 Pro
System
prompt
Prompt File File File File File File Plan
input
/plan Opus 4.7
System
prompt
Prompt Plan
input
File File Reasoning Precise
spec
/fleet GPT-5.4
System
prompt
Prompt Precise
spec
File File Change calls
System prompt Prompt File in context Reasoning Handoff artifact
Duration: 12 minutes

Reduce output tokens with better instructions

Sessions settings with the App instructions field highlighted.

1. Explicit app instructions

2. Persistent Instructions

./.github/copilot-instructions.md
./AGENT.MD

Put in:

  • the non-negotiables of your projects
  • log reoccurring agent misses
  • statements to trim output (“be concise”)

Keep them very small.

Don’t use AI to generate them.

Iterate, maintain and even recreate them often.

Caveman and Caveman Ultra modes returning progressively shorter technical explanations of React.

3. Caveman mode in action

GitHub repository Caveman github.com/juliusbrussee/caveman View repository
Duration: 15 minutes

Context window optimisation

Agents working with LLMs

Context Window & Tokens

1st loop
Input tokens Output tokens System
prompt
& tools
Prompt File Response
2nd loop
Cache input tokens
(not guaranteed)
Input tokens Output tokens System
prompt
Prompt File Response Prompt File Response

Context Rot When <50% Full

As an AI model processes a long context, its ability to recall information from the middle significantly degrades, while information from the beginning and end remains accessible.

Context Rot When >50% Full

The ability to recall information from the beginning of the context window degrades significantly as the window fills past the halfway mark.

Reference · Product Talk Context Rot producttalk.org/context-rot/ Read reference

Compact the window

Copilot CLI
$/compact
# write your repeated fixes into copilot-instructions.md
Copilot settings menu with Medium reasoning and a 264K context window selected.
Copilot session details showing 18 percent context usage and 2.52 AI credits spent.
Duration: 15 minutes

Coach yourself with your own history

Find what you're not using

Copilot CLI
$/chronicle tips
# map recent history to missed CLI and repo capability
Copilot CLI
Tips · 3 patterns from your recent sessions
1
Split research from productionWorkflow
You mix deep research and production edits in one thread. Run research in a parallel session, then merge findings back.
2
Make prompts measurablePrompting
Recent prompts were short or subjective. Try Goal → Scope → Constraints → Output → Done to cut revision loops.
3
Reuse setup across sessionsAutomation
You re-set the same build, test, and review steps. Move them into repo guidance or /commands so new sessions start ready.

Profile the last 30 days

Copilot CLI
$/chronicle cost-tips
# profile 30 days by agent, then drill into cost drivers
Copilot CLI
Cost tips · 3 ways to cut spend
1
Right-size the modelBiggest lever
Premium models were 83% of your input tokens — run bulk edits on a cheaper one with /model, save the reasoning model for final passes.
2
Reset long sessionsPer-turn cost
Input tokens climb every turn — one mid-session /compact or /new would've saved ~20M re-sent tokens.
3
Cut attachment churnHidden multiplier
Attachment-heavy sessions cost ~11× more — attach an image once, then reference its path instead of re-pasting.

Stop the guessing

Copilot CLI
$/chronicle improve
# write your repeated fixes into copilot-instructions.md
Without it the agent guesses
  • Runs npm install, not pnpm
  • Uses spaces, not tabs
  • Scatters tests beside the code
With it copilot-instructions.md
  • Runs pnpm install
  • Indents with tabs
  • Puts tests in __tests__/
Duration: 8 minutes

Wrap-up

Keep going after today