Understanding Context and Session Management in GitHub Copilot CLI (original) (raw)
This is the first article in a series on context management in GitHub Copilot CLI:
When you work with GitHub Copilot CLI, every prompt you send and every response you receive becomes part of a session. As that session grows, so does the amount of information Copilot carries with it—and that information has a direct cost in tokens, performance, and clarity. Understanding how sessions work, where they live, and how to manage them is the foundation for using Copilot CLI effectively.
This article lays that foundation. You'll learn the difference between a session and the context window, where Copilot stores your sessions, and which commands let you navigate, inspect, and manage them.
Difference Between a Session and the Context Window
People often use the terms "session" and "context window" interchangeably, but they're not the same thing. In fact, the two are linked: each session maintains its own context, and that's what it sends to the model on every turn. The session is the durable thing; the context window is the slice of it the model sees each time you press enter.
The context window is everything Copilot sends to the language model on a single turn. It's measured in tokens, and every model has a fixed limit. The context window holds several things: the system prompt, the definitions of every available tool, any custom instructions, the conversation history so far, and the contents of any files you've referenced.
A session is the continuous conversation you have with Copilot, from the moment you start it until you clear it or start a new one. Unlike the context window, a session is persistent—it's saved to disk and survives after you close Copilot CLI.
Where Sessions Live on Disk
By default, Copilot CLI stores its sessions in the ~/.copilot directory—the same place it keeps your configuration, logs, and installed plugins.
$ ll ~/.copilot/session* -rw-r--r--@ agoncal 964K session-store.db -rw-r--r--@ agoncal 32K session-store.db-shm -rw-r--r--@ agoncal 0B session-store.db-wal drwx------@ agoncal 9.8K session-state/
Each session is saved as its own set of files under ~/.copilot/session-state. These hold the conversation history—every prompt and response—along with the session's metadata, such as its name and identifier, any implementation plan generated in plan mode, the compaction checkpoints created as the conversation grew, and any temporary files produced during the work.
$ tree ~/.copilot/session-state/ff99b86b-ef45-4c9c-95a3-370a8f012b/ ├── checkpoints │ └── index.md ├── files └── workspace.yaml
Navigating and Inspecting Sessions
Once you've accumulated a few sessions, you need ways to move between them and look inside them. The following commands let you resume, rename, inspect, and search your sessions.
Renaming Sessions for Easy Retrieval
New sessions are identified by a generated UUID, which is hard to recognise in a list. Giving a session a meaningful name makes it far easier to find later:
/rename books-pagination
● Session renamed to: books-pagination
The name appears in the session picker, so when you have several sessions on the go, you can tell them apart at a glance. You can also run /rename without an argument to have Copilot generate a name from the conversation. Naming sessions is a small habit that pays off the moment you start juggling more than one.
Inspecting Session State with /session
The /session command shows information about your current session, including a summary of the workspace:
/session
Sessions ❯ ● books-paginations (active)
↑↓ Navigate · Enter Switch · n New · i Info · Esc Close
It also accepts subcommands that reveal specific parts of the session. You can list the compaction checkpoints created as the conversation grew, view the temporary files produced during the work, or display the current implementation plan:
/session checkpoints
● No checkpoints yet. Checkpoints are created when context is compacted.
/session files
/session plan
Resuming a Previous Session
Because sessions persist on disk, you can return to any of them and continue where you left off. The /resume command opens a session picker, where you select the session you want to switch to:
/resume
❯ 1. books-pagination (main) 2. cds-pagination (fork) (main) 3. Initialize Project Setup (main)
If you know the session's identifier or name, you can jump straight to it:
Managing Context Size
As a session grows, so does its context window. A larger context isn't just more expensive—it can also reduce the quality of Copilot's responses. That's why it pays to preserve context mindfully: clear when you can, lean on /ask for throwaway questions, and keep each session focused on one job.
The following commands let you measure, reduce, and control the size of your context.
Recommended by LinkedIn
Visualising Usage with /context and /usage
Before you can manage context size, you need to see it. The /context command shows a visual breakdown of your current token usage:
/context
● Context Usage
○ ○ ○ ◌ ◌ ◌ ◍ · · · gpt-5.4-mini · 27k/400k tokens (7%) · · · · · · · · · · · · · · · · · · · · ○ System Prompt: 11.7k (3%) · · · · · · · · · · ◌ System Tools: 13.2k (3%) · · · · · · · · · · ◍ MCP Tools: 2.3k (1%) · · · · · · · · · · ◉ Messages: 0 (0%) · · · · · ◎ ◎ ◎ ◎ ◎ · Free Space: 231.2k (58%) ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ Buffer: 141.6k (35%) ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎
MCP servers · /mcp
Loaded in context
- context7: 2 tools
- github-mcp-server: 6 tools
System/Tools breakdown tokens % of used context System prompt 11.7k ■■■■■■■■■■ 43% Tool definitions 15.5k ■■■■■■■■■■ 57% skill 3.6k ■■■■■■■■■■ 13% task 1.6k ■■■■■■■■■■ 6% ask_user 1.4k ■■■■■■■■■■ 5% session_store_sql 1.2k ■■■■■■■■■■ 5% context7-resolve-library-… 611 ■■■■■■■■■■ 2%
It displays how many tokens are used out of the model's limit, and how that total splits across the system prompt and tools, the conversation history, file contents, and the free space that remains. This is the command you reach for whenever you want to know how full your context window is.
The /usage command takes a wider view, reporting statistics for the whole session:
/usage
● Activity · last 180 days · 317 messages
Dec Jan Feb Mar Apr May
□ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ M □ □ □ □ □ □ ▤ ▦ ▩ ▤ □ □ ▤ □ ▤ □ □ □ ▤ □ □ □ ▤ ▤ □ ▦
□ □ □ □ □ □ □ □ ▤ □ □ □ ▤ □ ▤ □ ▤ ▦ ▤ □ □ □ □ ▦ ▦ □
W □ □ □ □ □ □ ▤ ▤ □ ▦ □ □ ▦ □ ▤ □ □ □ ▤ □ □ □ ▦ □ □
□ □ □ □ □ ▤ □ ▤ ▦ □ □ □ □ □ ▤ □ ▤ □ □ □ □ □ □ □ ▤
F □ □ □ □ □ □ □ ▤ ▤ □ □ □ ▦ □ □ □ ▤ □ □ □ □ □ □ □ ▦
□ □ □ □ □ □ □ □ ▤ □ □ □ □ □ ▤ □ □ □ □ □ □ □ □ □ □
Less □ ▤ ▦ ▩ ■ More
Changes +0 -0 AI Credits 0 (10h 31m 8s)
How Automatic Compaction Works
You rarely have to manage context size by hand, because Copilot does it for you. When your conversation approaches 95% of the token limit, Copilot automatically compacts your history—summarising older parts of the conversation into a checkpoint and freeing up space in the context window.
This happens in the background, without interrupting your work, which is what makes long sessions possible. The full conversation remains on disk, but the context window stays within the model's limit. In effect, automatic compaction gives you virtually infinite sessions.
But because compaction works by summarising, some detail is inevitably lost in the process. Even with automatic compaction handling the worst of it, it's still good practice to start a new session for a logically separate task—relying on heavy compaction within one long session can degrade the quality of Copilot's responses.
Compacting Manually with /compact
Sometimes you want to compact before Copilot does it automatically—for example, when you've finished one part of a task and want to free up space before starting the next. The /compact command triggers compaction on demand:
Copilot summarises the conversation so far into a checkpoint, reducing the context size whilst preserving the essential information. If you change your mind whilst it's running, press Esc to cancel.
Rewinding and Clearing a Session
Two commands let you remove context rather than summarise it. The /rewind command—also available as /undo—rewinds the last turn and reverts any file changes it made (as a shortcut, pressing Escape twice does the same thing as /rewind.):
/rewind # equivalent to /undo
This is useful when Copilot takes a wrong turn: you undo the work and the tokens it added, then try a different approach. To reset completely, the /clear command—also available as /new—abandons the current session and starts fresh:
/clear # equivalent to /new
After clearing, your context returns to its baseline: the system prompt, tools, and instructions, with no conversation history. Use it when you're moving on to something entirely unrelated. Forking and Asking Side Questions
Two more commands help you control context, and both are experimental. The /fork command branches the current session into a new one, preserving the conversation up to that point. This lets you build context once and reuse it across several tasks, without each task carrying the others' work:
The /ask command lets you ask a quick side question without adding it—or its answer—to the conversation history. Because the exchange never enters the history, it doesn't grow your context:
Cached Input Tokens
Long sessions could, in principle, become exponentially expensive as the history grows. What keeps that in check is cached input tokens. When the context you send closely matches context sent previously, Copilot can reuse a cached version of part of it, which is far cheaper than processing it afresh.
Conclusion
Session management is the foundation for using GitHub Copilot CLI well. The key distinction is this: a session is the complete, persistent record of your conversation, whilst the context window is the bounded, live view that fits within the model's token limit.
In this article, you learnt where sessions are stored, how to resume, rename, inspect, and search them, and how to manage context size with commands like /context, /compact, /rewind, and /clear. You also met /ask and /fork, which you'll explore in the articles to come.
Thanks to Mike Rousos for reviewing this article