anomalyco / anomalyco/opencode
[FEATURE]: Display token usage information in the TUI
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 209k
- Forks
- 27.5k
- Avg merge
- 7h 2m
- Merged PRs (30d)
- 384
Description
Feature hasn't been suggested before.
- I have verified this feature I'm about to request hasn't been suggested before.
Describe the enhancement you want to request
Problem
Currently, token usage information (input tokens, output tokens, remaining budget) is tracked internally but not visible to users in the OpenCode TUI. This makes it difficult for users to:
- Monitor costs in real-time during conversations
- Understand context window consumption
- Track usage against budget limits
- Make informed decisions about when to compact sessions
Proposed Solution
Display token usage information in the OpenCode TUI interface. Possible implementation approaches:
Option 1: Status Bar Display
Add token usage to the bottom status bar (similar to how file path or mode is displayed):
┌─────────────────────────────────────────────────┐
│ [Build Mode] Tokens: 19.9K/1M (980K remaining) │
└─────────────────────────────────────────────────┘
Option 2: New /usage or /tokens Command
Add a slash command that displays detailed token usage:
/usage
Current Session:
Input tokens: 12,450
Output tokens: 7,477
Cached tokens: 5,200
Total: 19,927 / 1,000,000
Remaining: 980,073 (98%)
Estimated cost: $0.05 (using claude-sonnet-4-5)
Option 3: Toggle-able Detail View
Add a keybind (e.g., ctrl+x t for tokens) to toggle token usage display in the conversation view, showing per-message token counts.
Option 4: Combination Approach
- Lightweight display in status bar for at-a-glance monitoring
- Detailed
/usagecommand for comprehensive breakdown - Optional per-message display via toggle
Benefits
- Cost Awareness: Users can monitor spending in real-time, especially important for pay-as-you-go models
- Budget Management: Helps users stay within monthly limits (especially relevant for OpenCode Zen users with spending caps)
- Context Window Management: Users can see when they're approaching token limits and need to compact
- Transparency: Makes the AI interaction more transparent and understandable
- Educational: Helps users learn which operations consume more tokens
Additional Context
The token usage data is already being tracked (visible in system messages on the backend), so this feature would primarily involve exposing existing data to the UI rather than implementing new tracking logic.
Related Features
- Ties into the existing
/compactcommand by helping users understand when compaction is needed - Complements OpenCode Zen's monthly usage limits feature
- Could integrate with the auto-compaction feature (
compaction.autoconfig)
Suggested Configuration
Allow users to customize this via config:
{
"tui": {
"show_token_usage": true,
"token_display_format": "compact"
}
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.