02. Context, snapshots, warming and network¶
🎯 Objective¶
Control the context lifecycle (compaction, snapshots), the provider state (warming) and the network (proxy).
🧠 Compaction (context)¶
Automatic context compaction; there is also native compaction per provider/model.
{
"compaction": {
"auto": true,
"keep": { "tokens": 15000 },
"buffer": 20000
}
}
keep.tokensretains a tail of recent context- A model can override the provider:
providers.openai.models."gpt-4.1".settings.compaction.type = "summary"
↩️ Snapshots (file + conversation undo/redo)¶
Enabled by default. Each model step captures snapshots before and after, allowing /undo//redo to restore files.
{ "snapshots": false }
- Cover tracked and untracked files (≤ 2 MiB) in the active directory, inside a Git worktree
- Do not revert shell effects (processes, networks, commits, ignored files)
- They are a convenience, not a backup: commit important work before
/undo
🌡️ Warming (keeping caches warm)¶
Sends periodic requests to preserve provider caches between prompts. Disabled by default.
{
"warming": {
"prompt": "Do no work. Answer exactly: OK",
"interval": "5 minutes",
"duration": "1 hour"
}
}
- Warming requests are real: they consume tokens, cost money and count toward the rate limit
- Use it only when the cache benefit outweighs the cost
🌐 Network and proxy¶
export HTTP_PROXY=http://proxy.example.com:8080
export HTTPS_PROXY=http://proxy.example.com:8080
export NO_PROXY=localhost,127.0.0.1,::1
opencode
NO_PROXYwith loopback is mandatory: the CLI talks to the local service over HTTP- Persist it for the background service:
opencode service set env HTTPS_PROXY ... - Private CA:
NODE_EXTRA_CA_CERTS=/etc/company/ca.pem - Verify:
opencode api get /api/info
🧹 Other output controls¶
{
"tool_output": { "max_lines": 2000, "max_bytes": 51200 },
"media": { "image": { "auto_resize": true, "max_width": 2000 } }
}
❓ Hands-on challenge¶
- Enable
compactionand run a long session; then use/undo - Turn off
snapshotsand confirm that/undodoes not restore files - Configure
warmingwith a short interval and watchopencode stats --cost - Configure a proxy with a loopback
NO_PROXYand validate the health check
📚 Official source¶
- Compaction · Snapshots · Warming · Network
Next step: Lesson 03 — Cost and statistics · Back to module