Skip to content

OpenCode

OpenCode is a terminal-native AI coding agent with MCP support. It uses the OpenAI-compatible API and can be pointed at Candela with minimal config.

Edit your OpenCode config (~/.config/opencode/config.json or project-level .opencode.json):

{
"provider": {
"name": "openai",
"apiBase": "http://localhost:1234/v1",
"apiKey": "candela",
"model": "gemini-3.5-pro"
}
}

For cloud models routed through candela in Solo + Cloud mode:

{
"provider": {
"name": "openai",
"apiBase": "http://localhost:1234/v1",
"apiKey": "candela",
"model": "gemini-3.5-pro"
}
}

candela handles Vertex AI authentication via ADC — no API key needed.

For Ollama models running locally:

{
"provider": {
"name": "openai",
"apiBase": "http://localhost:1234/v1",
"apiKey": "candela",
"model": "llama3.2:3b"
}
}
Terminal window
# Start candela
candela start
# In another terminal, start OpenCode
opencode
# Check traces at http://localhost:8181/_local/

Every prompt and response flows through Candela with full token counting and cost tracking.


The official @candelahq/opencode plugin hooks directly into OpenCode’s execution lifecycle to provide real-time cost visibility, budget guardrails, spending intelligence, and 13 slash commands — all inside your terminal.

➡️ View on npm · 📦 GitHub

CategoryWhat you get
💰 Real-Time Cost TrackingPer-response cost deltas, session totals, and 24h spend in status bar and sidebar
📊 Budget MonitoringThreshold toasts at 80/90/100%, budget pacing forecast, reset countdown
🔀 Smart Model RoutingOpt-in suggestions to swap to cheaper models when budget is tight
📏 Context Window GaugeToken usage tracking with compaction warnings at 80%+
🎯 Daily Cost GoalsSet spending targets, track progress with visual pacing
🛑 Session Cost AlertsPer-session cost tracking with 80%/100% warning toasts
📈 Cost ForecastingExtrapolate session cost based on current call rate
🔇 Quiet ModeSuppress info toasts, keep warnings and errors
🏷️ Session TaggingTag sessions by activity (auto-detects git branch)
📂 Repo AttributionAuto-tracks costs per git repository
📜 Session HistoryBrowse past sessions with cost, duration, and tool usage
Time-of-Day PatternsDiscover when you spend the most
🛠️ Tool Cost BreakdownSee which tools cost the most per call
📝 Git Commit AnnotationPrepare cost metadata for commit messages
📦 ExportJSON + CSV export of session data
🗄️ Local AnalyticsJSONL event log with 90-day auto-rotation and 10MB cap

Beyond basic tracking, the plugin builds a spending intelligence profile:

  • Cost Streaks — Track consecutive under-budget days
  • Anomaly Detection — Alert when session cost is 2x+ your average
  • Budget Pacing — Estimate budget exhaustion time from hourly burn rate
  • Model Efficiency — Score models by cost-per-call vs effectiveness
  • Weekly Digest — Week-over-week spending comparison
  • Time Patterns — Morning vs afternoon vs evening vs night cost analysis
Terminal window
npm install @candelahq/opencode

Add to your OpenCode config (~/.config/opencode/config.json or .opencode.json):

{
"plugins": ["@candelahq/opencode"]
}
CommandAliasesDescription
/cost/spendSession cost + 24h total breakdown
/budget/remainingBudget remaining, grants, reset time
/modelsTop models by spend and call count
/dashboard/dashOpen Candela web dashboard
/export/dumpExport session data to JSON + CSV
/goalSet or view daily cost goal
/quiet/shhToggle quiet mode
/tag/labelTag session for cost attribution
/capSet per-session cost cap
/history/sessionsBrowse recent sessions
/patterns/whenTime-of-day cost analysis
/annotate/commit-costGit commit cost metadata
/tools/tool-costTool cost breakdown

The plugin renders a live sidebar with real-time metrics:

📊 $4.20 · 24h
🗄️ Cache hit rate: 72%
🏷️ feat/context-gauge
⚡ Session: $1.80 · 12 calls
📈 Forecast: ~$3.30 if 10 more calls
📏 Context: 45k tokens 🟩 ~35%
🎯 Goal: $4.20/$20 🟩 21%
⏱️ Budget exhausted by 4:30 PM
claude-sonnet: $2.10 (8 calls)
gpt-4o: $1.30 (4 calls)
VariableTypeDefaultDescription
CANDELA_PROXY_URLStringhttp://localhost:8181Candela proxy URL
CANDELA_CONFIGStringPath to Candela config YAML (for port discovery)
CANDELA_SMART_ROUTINGBooleanfalseEnable cost-conscious model routing
CANDELA_ROUTING_THRESHOLDFloat (0–1)0.7Budget fraction to trigger routing
CANDELA_ROUTING_SAVINGS_THRESHOLDFloat (0–1)0.5Min savings to suggest model swap
CANDELA_DAILY_GOALNumber (USD)Daily spending target
CANDELA_QUIETBooleanfalseSuppress info-level toasts
CANDELA_SESSION_CAPNumber (USD)Per-session cost alert threshold

Persistent settings at ~/.config/opencode/candela-settings.json. Resolution priority: env vars > settings file > defaults.


OpenCode Hangs, Shows Stale Models, or Behaves Unexpectedly

Section titled “OpenCode Hangs, Shows Stale Models, or Behaves Unexpectedly”

If OpenCode hangs, shows stale models, or behaves unexpectedly after config changes, delete the OpenCode database:

Terminal window
rm -rf ~/.local/share/opencode/opencode.db*

Then restart OpenCode. This clears cached state (model lists, provider connections, etc.) and forces a fresh sync.

Ensure the model IDs in your .opencode.json match what the provider expects. Model versions get retired (e.g. codestral-2501codestral-2). Check the Candela server logs for the exact model ID being sent.

The model needs a pricing entry in Candela. Contact your admin or add it to the cost calculator.

Make sure the Candela server is running (candela server or the Cloud Run instance).


For multi-step autonomous workflows, install the companion @candelahq/missions plugin.

This plugin provides structured mission orchestration, allowing the agent to plan, execute, and validate complex goals across multiple child sessions.

  • Breaks down large goals into discrete milestones (mission_plan).
  • Dispatches isolated child sessions for focused work (mission_next).
  • Validates milestone completion with test commands (mission_validate).
  • Tracks progress across sessions and restarts.
  • Exposes 5 core tools for the agent: mission_plan, mission_next, mission_validate, mission_status, mission_cancel.

Install the package in your project:

Terminal window
npm install @candelahq/missions

Then add it to your .opencode.json:

{
"plugins": [
"@candelahq/opencode",
"@candelahq/missions"
]
}

When run alongside @candelahq/opencode, child sessions spawned by the missions plugin automatically inject the CANDELA_MISSION_ID environment variable. This translates to the X-Mission-Id HTTP header in API requests, enabling grouped cost tracking and budget attribution for the entire multi-step mission.

➡️ View on GitHub