Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

Repository files navigation

opencode context visualizer

See exactly what fills your opencode context window — token by token.

Reads your opencode SQLite database (~/.local/share/opencode/opencode.db) and shows you where your tokens go: system prompt, messages, tool calls, tool results, and patches.

Dashboard Overview

Prerequisites

  • Bun installed (curl -fsSL https://bun.sh/install | bash)
  • opencode installed and used at least once (so the DB exists)

Quick start

# Clone or navigate to the project
cd /var/www/html/opencode-context-visualizer

# Install dependencies (one time)
bun install
bun install --cwd web

# Start everything
bun run dev

Open http://localhost:5173

That's it. The backend starts on port :5174, the frontend on :5173.

Commands

Command What it does
bun install Install server dependencies
bun install --cwd web Install frontend dependencies
bun run dev Start server + frontend (dev mode with hot reload)
bun run build:web Build frontend for production
bun run start Start server only (production)

What you see

Stats bar (top)

When you select a session, the top bar shows:

  • Model — which model was used (e.g. claude-sonnet-4.6, mimo-v2.5-free)
  • Total — total tokens in the context window
  • Input — input tokens sent to the model
  • Output — output tokens generated by the model
  • Reasoning — reasoning/thinking tokens (if the model supports it)
  • Cache R — cache read tokens (tokens loaded from prompt cache, saving money)
  • Compactions — number of context compactions that happened (when opencode summarizes old messages to free up space)

Visualizations

Click the tabs in the header to switch between views:

View What it shows
Treemap Proportional rectangles — bigger = more tokens. Click a bucket to drill down.
Stacked Bar chart showing how each bucket grows across conversation turns.
Donut Pie chart with percentage breakdown by bucket. Click a slice to drill down.
Scatter Bubble chart — X = turn number, Y = total tokens, bubble size = proportion.

Drill-down

Click any bucket (in treemap, donut, or the bucket breakdown grid at the bottom) to see the individual items inside it. For example, clicking "Tool calls" shows each tool (bash, read, edit, etc.) sorted by token usage.

Session list (sidebar)

  • Search — filter sessions by title or model name
  • Favorites — star sessions to pin them to the Favorites tab
  • Session card — shows title, model, compaction badge, context bar, message count, duration

Theme toggle

Switch between Dark mode (Tokyo Night) and Light mode (Warm Cream). Your choice is saved in localStorage.

Color guide

Each bucket has a distinct color so you can instantly identify what's eating your context:

Dark mode (Tokyo Night)

Bucket Color Hex What it means
System prompt + tool schemas Grey #565f89 Static overhead — your system prompt, tool definitions, harness config. You can't reduce this much.
Messages Blue #7aa2f7 Conversation text — your prompts and the assistant's replies. The main thing you control.
Tool calls Purple #bb9af7 What the assistant asked tools to do — bash commands, file reads, edits, searches.
Tool results Green #9ece6a What tools sent back — file contents, command output, search results. Often the biggest bucket.
Patches Orange #ff9e64 File modifications — diffs and patches applied to your codebase.

Light mode (Warm Cream)

Bucket Color Hex
System prompt Warm grey #a09882
Messages Steel blue #5272b5
Tool calls Purple #8b5ec7
Tool results Forest green #4c8a3f
Patches Burnt orange #c47a2a

Why these colors matter

  • Blue (Messages) vs Purple (Tool calls) vs Green (Tool results) — the three main conversation components. If green is huge, your tools are returning too much data. If purple is huge, the assistant is calling too many tools.
  • Orange (Patches) — file edits. Large patches mean big refactors or many file changes.
  • Grey (System) — the floor. Every session has this. If it's large relative to your total, your system prompt or tool schemas are bloated.

Tips

  • 200k context model — if Total approaches 200k, you're near the limit. Compactions will trigger.
  • Cache reads — high Cache R means opencode is reusing cached context (good for cost).
  • Tool results dominate? — the assistant is reading large files. Ask it to read specific sections instead.
  • System prompt large? — check your AGENTS.md or system configuration files.

Stack

  • Backend: Bun + SQLite (direct read of opencode.db)
  • Frontend: React 19 + Vite 6 + ECharts 5 + TailwindCSS 3
  • Fonts: Inter (UI) + JetBrains Mono (code/numbers)

License

MIT

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages