A local-first control layer for OpenCode.
ContextOS for OpenCode is a free, MIT-licensed scaffold that helps you do three things without adding any cloud dependency:
- See how you actually use OpenCode with a local
insights-report.html - Reduce context waste with a context budget audit
- Protect long sessions with a compacting guard file and rescue snapshots
This starter is designed to be dropped into a repo and then extended by OpenCode itself.
.opencode/commands//insights/optimize-context/rescue-session/guard-refresh/continue-contextos
.opencode/skills/insightscontext-routersession-guard
.opencode/plugins/contextos-guard.js- injects
.contextos/guard/SESSION_GUARD.mdinto compaction context
- injects
scripts/generate-insights.mjscontext-budget.mjsrescue-session.mjscontextos-lib.mjs
templates/report-template.htmlsession-guard-template.md
docs/- architecture, roadmap, MVP
Unzip this into the root of the project you want to work on.
Then make sure opencode is available in your shell.
Run:
opencodeInside OpenCode, try:
/insights
/optimize-context
/guard-refresh
/rescue-session
/continue-contextos
You can also run the scripts directly:
node scripts/generate-insights.mjs --days 30
node scripts/context-budget.mjs --days 14
node scripts/rescue-session.mjs --max-count 20Optional flags (for stale/slow session exports):
node scripts/generate-insights.mjs --days 30 --max-export-attempts 24 --export-timeout-ms 8000
node scripts/context-budget.mjs --days 14 --max-export-attempts 24 --export-timeout-ms 8000--max-export-attempts: maximum number of sampled sessions to attempt export.--export-timeout-ms: per-export timeout in milliseconds.
insights-report.html.contextos/analysis/insights.json.contextos/analysis/context-budget.json.contextos/rescue/*.json.contextos/rescue/index.md
This starter deliberately stays local-first.
It does not do cross-device sync, hosted storage, or account management.
This starter reads session history through the documented OpenCode CLI surface:
opencode session list --format jsonopencode export <sessionID>
OpenCode versions can change the exact JSON shape of exports over time. The parsers here are defensive, but you should treat them as a strong starter rather than a guaranteed forever-stable parser.
- Run
/insights - Review the generated AGENTS patch suggestions
- Run
/guard-refresh - Let OpenCode implement the next roadmap item with
/continue-contextos
MIT