Complete system for running OpenCode efficiently: persistent state, adaptive routing, token savings, interruption survival.
Human
↓
Laptop (orchestrator)
↓
SYSTEM/ (persistent memory)
↓
Adaptive routing engine
↓
Agents (specialized)
↓
SSH
↓
PC (heavy compute)
↓
Verification
↓
Compression
↓
Savepoint
↓
Resume
- Runtime first - prove stability before adding features
- Persistent state - never restart from zero
- Adaptive routing - cheapest model that solves the task
- Token efficiency - track and minimize every session
- Interruption survival - resume > restart
- Evidence over reasoning - test before thinking longer
SYSTEM/
├── STATE.md # Current status, blockers, next action
├── QUEUE.md # Task queue with priorities
├── BLOCKERS.md # Active failures and workarounds
├── DECISIONS.md # Architectural choices with rationale
├── TEST_RESULTS.md # Runtime stability proofs
├── ARCHITECTURE.md # System design and component map
├── TOKEN_SAVINGS.md # Token optimization tracking
├── SAVEPOINTS/ # Session checkpoints
│ └── YYYYMMDD_HHMM.md
└── MEMORY/
├── PERMANENT_MEMORY.md # Improvement principles
├── LEARNED_PATTERNS.md # Successful patterns
└── FAILURES.md # Failure records
- Read SYSTEM/STATE.md
- Check SYSTEM/BLOCKERS.md
- Resume from last savepoint
- Execute next queued task
- Use tools before reasoning (grep > logs > tests > think)
- Mark outputs: VERIFIED / ASSUMED / SPECULATIVE
- Append token savings after each optimization
- Create savepoint at milestones
- Update STATE.md with final status
- Compress if context grew large
- Create savepoint
- Update QUEUE.md
Task
↓
Can tools solve it? → Yes → Use tools
↓ No
Cheapest model? → Yes → Use cheap model
↓ No
Verified? → Yes → Done
↓ No
Escalate → medium → strong → human
Decision output per task:
VERIFIED:
ASSUMED:
RISK:
CHEAPEST_MODEL:
NEXT_ACTION:
SAVEPOINT:
- No preamble, no postamble
- Code > prose
- Batch edits
- Read only what's needed
- Compress periodically
- Track savings in TOKEN_SAVINGS.md
Format: Date | Action | ~Tokens saved | Method
Track:
- One-time savings
- Per-session recurring savings
- Cumulative total
- Model: opencode/qwen3.6-plus-free (free)
- Auto-compaction: enabled
- Prune: enabled
- Tail turns: 2
- Format: --format json for non-interactive
- Behavior constraints
- Token tracking requirements
- Context handling rules
Tests:
- Cold start
- Long session (>1h)
- Interruption recovery
- SSH reconnect
- Model failover
- Multiple agents
- Context compaction
- Memory file update/reload
Output: SYSTEM/TEST_RESULTS.md
- SYSTEM/ directory structure
- All persistent files
- Savepoint system
- Replace hardcoded model mapping
- Decision engine per task
- Escalation logic
- Laptop = orchestrator
- PC = heavy compute
- SSH connection
- Explorer, Builder, Verifier, Compressor, Archivist, Coordinator
- Periodic review of waste
- Compression
- Deletion of obsolete
- Crash recovery
- Disconnect handling
- Config corruption protection
- Runtime: 6 OpenCode instances running
- Model: qwen3.6-plus-free (free)
- Cost: 0
- Phase: 0 (Runtime Proof)
- Blockers: B001-B004 active
- Token savings: ~2800 + ~300/session
- B001:
opencode runwithout--format jsonhangs (HIGH) - WORKAROUND: use --format json - B002:
opencode debug configtimes out (MEDIUM) - WORKAROUND: use debug startup/paths - B003: Snap package TTY confinement (MEDIUM) - INVESTIGATING
- B004: Runtime reliability not conclusively verified (CRITICAL) - ACTIVE
- Clone this repo
- Copy SYSTEM/ to your project root
- Copy AGENTS.md to project root
- Copy opencode.jsonc to ~/.config/opencode/
- Start OpenCode
- Read SYSTEM/STATE.md before each session
- Follow the workflow
- This is a living system - update files as you learn
- Compression is required - don't let files grow unbounded
- Failures are information - record them in MEMORY/FAILURES.md
- Improvement includes subtraction - remove what doesn't work
- Assume interruptions occur - maintain resume capability