-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Open
Description
Prerequisites
- I will write this issue in English
- I have searched existing issues and discussions to avoid duplicates
- This feature request is specific to oh-my-opencode (not OpenCode core)
- I have read the documentation and couldn't find this feature
Problem Description
LLM token costs are significant when passing structured data between agents, formatting tool outputs, and constructing prompts. Large arrays (session lists, task lists, MCP responses, file listings) consume unnecessary tokens when formatted as verbose JSON.
Proposed Solution
Integrate @toon-format/toon - a compact encoding format designed for LLM input that achieves ~40% token reduction on uniform arrays.
Repository Health: 22.8k stars, MIT license, TypeScript, zero runtime deps, actively maintained.
Key Integration Points (55 identified):
| Category | Points | Priority | Savings |
|---|---|---|---|
| Tool Output Formatting | 12 | HIGH | ~40% |
| Hook Transformation | 7 | HIGH | ~30% |
| LLM Prompt Construction | 9 | MEDIUM | ~20% |
| Inter-Agent Transfer | 8 | MEDIUM | ~15% |
| MCP Response Formatting | 5 | LOW | ~35% |
Top Targets (Phase 1):
session-formatter.ts- session lists (tabular, perfect for TOON)task-list.ts- task arraysskill-mcp/tools.ts- MCP tool/resource/prompt responsesglob/result-formatter.ts- file listingstool-execute-after.tshook - catch all tool outputs
Example transformation:
// Before: ~200 tokens
[{"id":"ses_1","messages":45,"agents":["sisyphus"]},{"id":"ses_2","messages":12,"agents":["oracle"]}]
// After: ~80 tokens
sessions[2]{id,messages,agents}:
ses_1,45,[sisyphus]
ses_2,12,[oracle]
Config schema:
Alternatives Considered
- JSON-compact: Works for deeply nested data but TOON excels on uniform arrays
- Custom compression: Reinventing the wheel; TOON is battle-tested (22k+ stars)
- No compression: Current state, but token costs are significant
Feature Type
- New MCP Integration (technically a library integration)
- Configuration Option
- Other (data serialization optimization)
Additional Context
Implementation effort: ~11 hours total (phased approach)
Existing patterns in codebase:
hash-computation.tsalready uses AsyncGenerator for streamingtool-output-truncator.tshandles large outputs (50k token limit)dynamic-truncator.tsprovides line-by-line truncation
Scope boundaries:
- ✅ Include: Uniform arrays, tool outputs, MCP responses
- ❌ Exclude: Config files (JSONC), deeply nested data, single objects
Contribution
- I'm willing to submit a PR for this feature
- I can help with testing
- I can help with documentation
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
{ "features": { "toonCompression": { "enable": true, "threshold": 5000 } } }