Skip to content

feat: support configurable cost display currency - #51631

Closed
Meinianda-L wants to merge 3 commits into
anomalyco:devfrom
Meinianda-L:feat/usage-display-currency
Closed

Meinianda-L wants to merge 3 commits into
anomalyco:devfrom
Meinianda-L:feat/usage-display-currency

Conversation

@Meinianda-L

@Meinianda-L Meinianda-L commented Sep 27, 2026 •

Copy link
Copy Markdown

Issue for this PR

Closes #32485

Type of change

  • New feature
  • Refactor / code improvement

What does this PR do?

Usage cost is hardcoded to USD. This adds display.currency (and optional display.exchangeRates) so it can be shown in another currency, e.g. CNY:

{ "display": { "currency": "CNY" } }

Costs are still tracked in the provider's currency and are only converted where they're displayed (TUI sidebar/footers, app context views, ACP usage_update). There are approximate, display-only rates for the 7 most-traded currencies (USD, EUR, GBP, JPY, CNY, CAD, AUD); anything else can be added via exchangeRates (units per 1 USD). If no rate exists, the original amount and currency are shown, never relabeled.

The first commit is from #39425 (kagura-agent, authorship kept, fixes #38667): it passes the provider's currency through so CNY-priced providers aren't double-converted.

This continues #41208, which was auto-closed by the stale-PR bot.

How did you verify your code works?

  • bun test test/currency.test.ts (core): 15 pass
  • bun test test/acp (opencode): 146 pass
  • bun typecheck: 30/30
  • Built with script/build.ts --single and used it as my own opencode against a real DeepSeek session: default → $0.00, CNY → CN¥0.03, EUR → €0.00, HKD + custom rate → HK$0.03, HKD without a rate → stays $0.00.

Screenshots / recordings

Before: the footer always shows $.

After, "display": { "currency": "CNY" } (footer: CN¥0.03):

After, "display": { "currency": "EUR" }, same session (footer: €0.00; the cost is only about €0.004):

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

🤖 Generated with Claude Code

kagura-chen and others added 3 commits September 27, 2026 17:21
…ding USD

The usage_update ACP event hardcodes currency: "USD" regardless of the
provider's actual currency configuration. This causes non-USD providers
(e.g. EUR-priced custom providers) to report incorrect currency labels.

Add an optional `currency` field to the ProviderCost schema (defaults to
"USD" when omitted for backward compatibility). Thread the configured
currency through to both usage_update call sites (usage.ts layer and
service.ts ACP client) using a cached lookup pattern matching the
existing contextLimit implementation.

Fixes anomalyco#38667

Signed-off-by: kagura-agent <[email protected]>
Add a display.currency config option that converts usage costs to the
user's preferred currency at presentation boundaries (ACP usage_update,
TUI, and app). The provider/model currency remains the source currency:
when no display currency is configured, costs are shown unchanged in
the source currency, and amounts are never relabeled when conversion is
impossible (unknown rate).

- Add Currency core module: approximate USD-based display rate table,
  convert() with user rate overrides, and locale-aware format()
- Add display.currency and display.rates to the config schema
- Convert in both ACP usage_update paths (Effect layer and ACP client)
- Replace hardcoded USD formatters in TUI (sidebar, prompt, subagent
  footer) and app (context usage, context tab) with the shared utility
- Regenerate SDK types and document the new options

Relates to anomalyco#32485. Supersedes the approach explored in anomalyco#32487 and
builds on provider-currency propagation from anomalyco#39425.
…encies

Other currencies can be added via display.exchangeRates.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

@github-actions

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ACP usage_update mislabels non-USD costs as USD [FEATURE]: Configure usage cost display currency

2 participants