Skip to content

Add Japanese Yen (JPY) Currency Display Support#1

Closed
ml0-1337 wants to merge 4 commits intoryoppippi:mainfrom
ml0-1337:feature/add-jpy-currency-display
Closed

Add Japanese Yen (JPY) Currency Display Support#1
ml0-1337 wants to merge 4 commits intoryoppippi:mainfrom
ml0-1337:feature/add-jpy-currency-display

Conversation

@ml0-1337
Copy link

Overview

This PR adds support for displaying Claude Code usage costs in Japanese Yen (JPY) alongside the existing USD display. Users can now switch between USD and JPY with a persistent preference that is maintained across sessions.

Changes

Main Changes

  • Currency Conversion: Implemented JPY support with a fixed conversion rate of 1 USD = 150 JPY
  • Persistent Configuration: Added configuration storage using the conf library for cross-platform support
  • CLI Enhancement: Added --currency flag to all commands for easy currency switching
  • Number Formatting: Improved number formatting with comma separators for better readability

Technical Details

  • Modified Files:
    • utils.ts - Updated formatCurrency() to support multiple currencies
    • commands/daily.ts & commands/session.ts - Integrated currency-aware formatting
    • shared-args.ts - Added --currency CLI argument
    • README.md - Added currency feature documentation
  • New Files:
    • config.ts - Configuration management module
    • currency.ts - Currency conversion and formatting logic
    • config.test.ts & currency.test.ts - Comprehensive test coverage
  • Dependencies:
    • Added conf@13.1.0 for configuration storage
    • Added @types/conf@3.0.3 for TypeScript support
  • Configuration:
    • Config stored in platform-specific locations (macOS/Linux: ~/.config/ccusage/config.json, Windows: %APPDATA%\ccusage\config.json)

Impact

  • Breaking Changes: No - Existing functionality remains unchanged, USD is still the default
  • Database Changes: No
  • API Changes: No - JSON output format remains unchanged (always shows USD values)
  • Performance Impact: Negligible - Only adds configuration file read on startup

Testing

  • Unit tests pass
  • Integration tests pass
  • Manual testing completed
  • Performance testing (not applicable)

Test Details

  • Added 13 new tests covering currency conversion, formatting, and configuration persistence
  • Updated existing tests to support the new formatCurrency signature
  • All 47 tests pass successfully
  • Test coverage includes:
    • USD to JPY conversion accuracy
    • Number formatting with comma separators
    • Currency symbol display ($ vs ¥)
    • Decimal place handling (2 for USD, 0 for JPY)
    • Configuration persistence across sessions
    • Invalid currency handling

Deployment

  • Special Instructions: None - the feature is self-contained
  • Environment Variables: None required
  • Migration Steps: None - configuration is created automatically on first use

Review Focus Areas

  1. Currency Conversion Rate: Currently hardcoded at 1 USD = 150 JPY - is this acceptable or should it be configurable?
  2. Number Formatting: Using toLocaleString('en-US') for both currencies - should JPY use a different locale?
  3. Configuration Location: Using the conf library's default paths - are these appropriate for the project?

Related Information

  • Issue/Ticket: Not linked to a specific issue
  • Documentation: README.md updated with currency configuration section
  • Screenshots:

Example output with JPY display:

┌──────────────┬──────────────┬──────────────┬──────────────┬──────────────┬──────────────┬────────────┐
│ Date         │        Input │       Output │ Cache Create │   Cache Read │ Total Tokens │ Cost (JPY) │
├──────────────┼──────────────┼──────────────┼──────────────┼──────────────┼──────────────┼────────────┤
│ 2025-05-30   │        9,896 │      713,227 │    8,584,408 │   93,755,531 │  103,063,062 │    ¥49,137 │
└──────────────┴──────────────┴──────────────┴──────────────┴──────────────┴──────────────┴────────────┘

Checklist

  • Self-reviewed code
  • Added appropriate comments
  • Updated documentation
  • Added/updated tests
  • All tests pass
  • No lint errors
    EOF < /dev/null

ml0-1337 and others added 4 commits May 31, 2025 02:08
- Add conf dependency for cross-platform config storage
- Create config module with currency preference management
- Support USD and JPY currency options with persistence

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add currency conversion module with 1:150 exchange rate
- Update formatCurrency to support multiple currencies
- Format JPY with ¥ symbol and no decimals
- Add comma separators for better readability

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add --currency flag to all commands with persistence
- Update daily command to use currency-aware formatting
- Update session command to use currency-aware formatting
- Display appropriate currency label in table headers

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add tests for currency conversion functions
- Add tests for configuration persistence
- Update existing tests for new formatCurrency signature
- Add currency feature documentation to README

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@socket-security
Copy link

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Added@​types/​conf@​3.0.3531003583100
Addedconf@​13.1.09910010079100

View full report

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @zenmush, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

Summary of Changes

Hello team, gemini-code-assist here to provide a summary of this pull request from @zenmush. This PR introduces support for displaying Claude Code usage costs in Japanese Yen (JPY) in addition to the existing USD display. It adds a --currency flag to the CLI commands (daily and session) allowing users to switch between currencies. The chosen currency preference is persisted across sessions using a new configuration file. The changes involve adding new modules for currency handling and configuration, updating existing command files to use the new currency logic, and updating the README documentation.

Highlights

  • JPY Currency Support: Adds the ability to display usage costs in Japanese Yen (JPY) alongside the default USD.
  • Persistent Currency Preference: Introduces configuration management using the conf library to save the user's preferred currency across sessions.
  • CLI --currency Flag: Adds a new --currency flag to the daily and session commands, allowing users to specify 'USD' or 'JPY' for the output currency. Using this flag also updates the persistent preference.
  • Currency Conversion and Formatting: Implements logic for converting USD costs to JPY using a fixed rate (1 USD = 150 JPY) and formats the output with the correct currency symbol ($ or ¥) and decimal places (2 for USD, 0 for JPY).
  • Improved Number Formatting: Updates currency formatting to use locale-aware methods (toLocaleString) for better readability with comma separators.

Changelog

Click here to see the changelog
  • README.md
    • Updated the features list to mention JPY currency support (line 43-44).
    • Added examples for using the --currency JPY flag with daily (line 112-113) and session (line 135-136) commands.
    • Added the --currency flag to the list of shared options, including its description and default/persistence behavior (line 149).
    • Added a new 'Currency Configuration' section explaining the feature, conversion rate, formatting details, and configuration file location (line 194-206).
  • bun.lock
    • Added conf and @types/conf dependencies to the lock file (line 7, 11).
    • Added various transitive dependencies required by conf (e.g., ajv, atomically, debounce-fn, dot-prop, env-paths, json-schema-traverse, json-schema-typed, require-from-string, stubborn-fs, when-exit, type-fest, uint8array-extras) (lines 127, 129, 145, 177, 185, 195, 217, 219, 253, 255, 313, 347, 359, 363, 379).
  • commands/daily.ts
    • Imported getCurrencyLabel from ./currency.ts (line 10).
    • Retrieved the selected currency from command context (line 21).
    • Updated the table header for the cost column to use getCurrencyLabel based on the selected currency (line 69).
    • Updated calls to formatCurrency to pass the selected currency (line 94, 117).
  • commands/session.ts
    • Imported getCurrencyLabel from ./currency.ts (line 10).
    • Retrieved the selected currency from command context (line 21).
    • Updated the table header for the cost column to use getCurrencyLabel based on the selected currency (line 72).
    • Updated calls to formatCurrency to pass the selected currency (line 111, 138).
  • config.test.ts
    • New file adding unit tests for the configuration module (config.ts).
    • Tests cover getting and setting currency preferences ('USD' and 'JPY'), handling invalid currency input, and verifying configuration path (lines 1-62).
  • config.ts
    • New file defining the configuration module.
    • Defines Currency type and ConfigSchema for storing the currency preference (lines 4-8).
    • Initializes Conf with project name 'ccusage', schema validation, and default currency 'USD' (lines 18-24).
    • Exports getCurrency, setCurrency, and getConfigPath functions for managing the currency setting (lines 26-39).
  • currency.test.ts
    • New file adding unit tests for the currency module (currency.ts).
    • Tests cover convertFromUSD for USD and JPY conversion (1:150 rate) (lines 8-20).
    • Tests cover formatCurrencyAmount for formatting USD (2 decimals, '$') and JPY (0 decimals, '¥'), including handling negative numbers and rounding (lines 23-41).
    • Tests cover getCurrencyLabel for generating table headers (lines 44-48).
  • currency.ts
    • New file defining currency conversion and formatting logic.
    • Defines constant maps for conversion rates, currency symbols, and decimal places for USD and JPY (lines 3-16).
    • Exports convertFromUSD function to convert a USD amount to a target currency (lines 18-24).
    • Exports formatCurrencyAmount function to format a numeric amount with the correct symbol and decimal places using toLocaleString (lines 26-40).
    • Exports getCurrencyLabel function to generate the table header string for a given currency (lines 42-44).
  • package.json
    • Added conf as a production dependency (line 57).
    • Added @types/conf as a dev dependency (line 39).
    • Updated trustedDependencies list (line 55).
  • shared-args.ts
    • Imported Currency, getCurrency, and setCurrency from ./config.ts (line 3).
    • Added parseCurrencyArg function to validate the input currency string, convert it to uppercase, set the persistent configuration, and return the validated currency type (lines 15-21).
    • Added the --currency argument definition to sharedArgs, using the new parseCurrencyArg function and defaulting to the value retrieved from the configuration (lines 49-55).
  • utils.test.ts
    • Updated formatCurrency tests to accept the currency parameter.
    • Added tests specifically for formatting amounts in JPY, including conversion and rounding (lines 68-84).
    • Updated existing USD tests to pass 'USD' and adjusted expected values to include comma separators due to the change from toFixed to toLocaleString (e.g., line 39, 64, 65).
  • utils.ts
    • Imported Currency from ./config.ts and convertFromUSD, formatCurrencyAmount from ./currency.ts (lines 1-2).
    • Modified the formatCurrency function signature to accept the target currency (line 8).
    • Updated formatCurrency implementation to first convert the USD amount using convertFromUSD and then format the result using formatCurrencyAmount (lines 12-13).
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.


Costs in Yen now show,
From dollars, they will grow,
Config remembers.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This is a well-executed PR that successfully adds JPY currency support, persistent configuration, and related CLI enhancements. The code is clearly structured, with good separation of concerns in the new config.ts and currency.ts modules. The addition of 13 new tests, covering currency conversion, formatting, and configuration persistence, is excellent and significantly boosts confidence in the changes. The README updates are also clear and helpful.

Regarding the review focus areas you raised:

  1. Currency Conversion Rate: The hardcoded rate is simple. My comment on currency.ts (L3-6) offers thoughts on future configurability if precision becomes more critical.
  2. Number Formatting: Using en-US locale for JPY is acceptable for consistency. My comment on currency.ts (L34) includes a note on ja-JP as an alternative for consideration.
  3. Configuration Location: The conf library's default paths are standard and appropriate for this type of application.

Overall, great work on this feature! The code quality is high, and the new functionality is well-integrated.

Summary of Findings

  • Hardcoded Currency Conversion Rate: The JPY conversion rate is hardcoded (1 USD = 150 JPY). While simple, this may not reflect real-time values. This was a point of discussion raised by the author and is acceptable for the current scope but could be a future enhancement area if more precision is needed.
  • Number Formatting Locale for JPY: JPY amounts are formatted using the 'en-US' locale for number separation and then the '¥' symbol is prepended. This is consistent but differs from native 'ja-JP' currency formatting. This was a point of discussion raised by the author and the current approach is acceptable for consistency.
  • Currency Validation: The currency validation logic is present in parseCurrencyArg and setCurrency. Consider centralizing it in setCurrency for better maintainability.

Merge Readiness

The pull request is in excellent shape and implements the described features effectively. The new tests and clear code structure are commendable. The comments provided are intended for consideration rather than as blockers. I believe this PR is ready for merging. As an AI, I am not authorized to approve pull requests; please ensure it undergoes any further required human review and approval processes.

Comment on lines +3 to +6
const CONVERSION_RATES: Record<Currency, number> = {
USD: 1,
JPY: 150,
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

You asked in the PR description if the hardcoded conversion rate (1 USD = 150 JPY) is acceptable. For a utility tool like this, a fixed rate offers simplicity in implementation and usage.

However, as exchange rates fluctuate, this fixed rate might lead to discrepancies over time if precise, up-to-date cost tracking is a key requirement for users.

Would it be beneficial to consider any of the following for future enhancements if higher accuracy becomes necessary?

  • Making the conversion rate configurable in config.json?
  • Implementing a mechanism to fetch the current rate dynamically (e.g., from an API, with this hardcoded value as a fallback)?

For the current scope, this fixed rate is clearly defined and implemented as described, which is fine. It's good to acknowledge this limitation or design choice in the documentation (as you've done in the README).

Comment on lines +34 to +37
const formattedAmount = amount.toLocaleString("en-US", {
minimumFractionDigits: decimals,
maximumFractionDigits: decimals,
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The PR description asks about using toLocaleString('en-US') for formatting both USD and JPY. This approach is perfectly acceptable and ensures a consistent number formatting style (e.g., comma as a thousands separator, period as a decimal separator) across all currency displays, which can be preferable for users accustomed to en-US conventions.

For context, if catering specifically to users who expect idiomatic Japanese number formatting, an alternative for JPY would be to use the ja-JP locale combined with the currency style. For example:

// Example for consideration if ja-JP specific formatting were a requirement
if (currency === 'JPY') {
  return amount.toLocaleString('ja-JP', {
    style: 'currency',
    currency: 'JPY', // ISO currency code for Yen
    minimumFractionDigits: decimals, // Would be 0 for JPY
    maximumFractionDigits: decimals, // Would be 0 for JPY
  });
}
// ... then handle USD or other currencies, or the current en-US based formatting

This would automatically handle the Yen symbol (often - the full-width version in some ja-JP contexts, though ¥ is also common) and any other locale-specific nuances for JPY.

However, the current implementation is clear, provides good readability with comma separators, and is consistent. It's a sound choice for this tool.

Comment on lines +15 to +22
const parseCurrencyArg = (value: string): Currency => {
const upperValue = value.toUpperCase() as Currency;
if (upperValue !== "USD" && upperValue !== "JPY") {
throw new TypeError(`Invalid currency: ${value}. Must be USD or JPY.`);
}
setCurrency(upperValue);
return upperValue;
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The parseCurrencyArg function could be improved by moving the currency validation logic into the setCurrency function. This would centralize the validation and ensure that only valid currency values are stored in the configuration.

const parseCurrencyArg = (value: string): Currency => {
	const upperValue = value.toUpperCase() as Currency;
	setCurrency(upperValue);
	return upperValue;
};

@ryoppippi
Copy link
Owner

I don't want to support other currencies because of maintenance cost

@ryoppippi ryoppippi closed this May 31, 2025
@ryoppippi
Copy link
Owner

@zenmush I recommend to fork this repo and modify by yourseld.
Or maybe I'll create a plugin feature for this cli(create config file and user can define the cols process. it is more extendable)

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants