

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 2
click for more info
Not enough gems
Cost: 6 gems
1: What Is Context?
incomplete
2: Context As RAM
incomplete
3: New Sessions
incomplete
4: Token Economics
incomplete
5: Ignoring Files
incomplete
6: File Watcher
incomplete
7: Lost in the Middle
incomplete
8: Compaction
incomplete
9: Configure Compaction
incomplete
10: Undo and Redo
incomplete
11: Forking
incomplete
12: Secrets in Context
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
If you've never hit a context window limit using a "raw" AI provider's API, know that it's literally a hard stop. You just get an error saying the input is too long.
To avoid this, OpenCode (like other coding agents) will automatically compact your session as you approach the context window limit. In practice, and assuming you're using a model with a reasonably large window, you'll likely never have a "hard stop" because OpenCode's auto-compaction will keep you in safe territory.
Unlike lossless compression, compaction doesn't let you reconstruct every detail from the shortened version of the context. It's lossy: some information is concretely left out.
By default, OpenCode asks the model to summarize the session's history and current state, retaining some recent context alongside the summary. Earlier messages remain saved on disk, but the model continues the session using the shorter context. The summary might contain:
While compaction happens automatically as you approach the context window limit (you'll notice the TUI telling you that it's compacting), you can also trigger it manually at any time with the /compact command. Include instructions to guide the compaction.
Compaction used to suck, but now it's pretty good at retaining relevant context.
Sometimes I manually /compact after a task is "roughly done," like where I might make a Git commit. Then I continue from there in the same session.
I used to make new sessions all the time, but now I tend to have super long-running sessions with more compaction.