Skip to content

Conversation

@ryoppippi
Copy link
Owner

@ryoppippi ryoppippi commented Aug 22, 2025

Summary

This PR replaces environment variables with CLI options for configuring context usage color thresholds in the statusline command. This is a breaking change that improves usability and aligns with modern CLI patterns.

Breaking Changes

  • ❌ Environment variables CCUSAGE_CONTEXT_LOW_THRESHOLD and CCUSAGE_CONTEXT_MEDIUM_THRESHOLD are no longer supported
  • ✅ New CLI options: --context-low-threshold and --context-medium-threshold
  • ✅ Configuration file support maintained

Changes Made

  • Added --context-low-threshold and --context-medium-threshold options to statusline command
  • Implemented comprehensive zod validation (0-100 range, integer, LOW < MEDIUM constraint)
  • Removed getContextUsageThresholds() function and related environment variable constants
  • Updated documentation with CLI option usage examples and configuration file support
  • Removed environment variable tests and validation logic
  • Updated JSON schema to include new statusline options
  • Maintained backward compatibility through default values (50/80)

Migration Guide

Old (Environment Variables):

export CCUSAGE_CONTEXT_LOW_THRESHOLD=60
export CCUSAGE_CONTEXT_MEDIUM_THRESHOLD=90
bun x ccusage statusline

New (CLI Options):

bun x ccusage statusline --context-low-threshold 60 --context-medium-threshold 90

Configuration File (Persistent Settings):
See the Configuration Guide for details on setting these options in config files.

Validation Improvements

  • ✅ Real-time validation with clear error messages
  • ✅ Automatic type coercion and range validation (0-100)
  • ✅ Ordering constraint enforcement (LOW < MEDIUM)
  • ✅ Better developer experience with zod schema validation

Test Plan

  • Removed obsolete environment variable tests
  • Schema generation working correctly
  • Documentation updated
  • All existing functionality preserved with new option-based approach

The change maintains all existing functionality while providing a cleaner, more discoverable interface through CLI options instead of environment variables.

Summary by CodeRabbit

  • New Features
    • Configurable context usage thresholds for statusline via CLI flags and configuration/settings file. Color-coding now respects user-defined low/medium percentages with validation (0–100, low < medium). Sensible defaults included.
  • Documentation
    • Updated statusline guide with new configuration methods, examples, and validation rules. Replaced environment variable instructions with CLI and config file guidance. Expanded visual burn-rate customization details.
  • Refactor
    • Removed legacy environment variable support for threshold configuration to unify and simplify setup.

…context thresholds

BREAKING CHANGE: Environment variables `CCUSAGE_CONTEXT_LOW_THRESHOLD` and `CCUSAGE_CONTEXT_MEDIUM_THRESHOLD` are no longer supported. Use CLI options `--context-low-threshold` and `--context-medium-threshold` instead.

- Add `--context-low-threshold` and `--context-medium-threshold` options to statusline command
- Implement zod validation for threshold values (0-100 range, integer, LOW < MEDIUM constraint)
- Remove `getContextUsageThresholds()` function and related environment variable constants
- Update documentation to reflect CLI option usage and configuration file support
- Remove environment variable tests and validation logic
- Update JSON schema to include new statusline options
- Maintain backward compatibility through default values (50/80)

Migration guide:
- Old: `export CCUSAGE_CONTEXT_LOW_THRESHOLD=60`
- New: `--context-low-threshold 60`
- Configuration files also supported for persistent settings
@coderabbitai
Copy link

coderabbitai bot commented Aug 22, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

Introduces CLI/configurable context usage thresholds for the statusline command; removes environment-variable-based thresholds and related data-loader utility; updates schema and docs to reflect new configuration paths; adds Zod validation and new args in statusline; deletes env constants.

Changes

Cohort / File(s) Summary
Config schema: statusline thresholds
config-schema.json
Adds contextLowThreshold and contextMediumThreshold to statusline command overrides (string-typed, defaults 50/80, with descriptions/markdownDescription).
CLI/statusline implementation
src/commands/statusline.ts
Adds new args contextLowThreshold/contextMediumThreshold, Zod validation (0–100, LOW < MEDIUM), uses defaults from DEFAULT_CONTEXT_USAGE_THRESHOLDS, applies thresholds in color logic; refactors mappers to use validated values.
Data-loader cleanup
src/data-loader.ts
Removes getContextUsageThresholds() and related imports/usages tied to env-based thresholds.
Env constants removal
src/_consts.ts
Removes exported env constants CONTEXT_LOW_THRESHOLD_ENV and CONTEXT_MEDIUM_THRESHOLD_ENV.
Docs: statusline guide
docs/guide/statusline.md
Replaces env-var configuration with CLI flags/config file section; updates validation rules/examples; adds JSON settings example; reorganizes related sections.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant U as User
  participant CLI as statusline (CLI)
  participant Z as Zod Parser
  participant C as statuslineCommand
  participant R as Renderer

  U->>CLI: Run statusline --context-low-threshold --context-medium-threshold
  CLI->>Z: Parse & validate thresholds (0–100, LOW < MEDIUM)
  Z-->>CLI: Valid thresholds or error
  alt thresholds invalid
    CLI-->>U: Error: invalid threshold configuration
  else thresholds valid
    CLI->>C: Execute with thresholds
    C->>R: Format context usage with provided thresholds
    R-->>U: Statusline output (color-coded)
  end
Loading
sequenceDiagram
  rect rgb(245,248,255)
  note over U,Env: Previous flow (removed)
  participant U as User
  participant Env as Environment
  participant DL as DataLoader.getContextUsageThresholds
  participant C as statuslineCommand
  U->>C: Run statusline
  C->>DL: Read thresholds
  DL->>Env: Read env vars
  Env-->>DL: Values/undefined
  DL-->>C: Thresholds (clamped/ordered)
  C-->>U: Statusline output
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

A hop, a skip, new flags take flight,
No envs to chase in dawn’s first light.
Zod sniffs carrots: LOW then MED—
Green to yellow, lines are wed.
I thump approval, whiskers keen—
Status sings in colors seen.
🥕✨

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.


📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 55947da and 5f01d55.

📒 Files selected for processing (5)
  • config-schema.json (1 hunks)
  • docs/guide/statusline.md (1 hunks)
  • src/_consts.ts (0 hunks)
  • src/commands/statusline.ts (4 hunks)
  • src/data-loader.ts (1 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/replace-env-vars-with-statusline-options

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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.

Summary of Changes

Hello @ryoppippi, 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!

This pull request introduces a breaking change by migrating the configuration of context usage color thresholds for the statusline command from environment variables to dedicated command-line interface (CLI) options. This enhances usability and aligns with modern CLI practices, while maintaining configuration file support.

Highlights

  • CLI Option Integration: Replaced CCUSAGE_CONTEXT_LOW_THRESHOLD and CCUSAGE_CONTEXT_MEDIUM_THRESHOLD environment variables with new --context-low-threshold and --context-medium-threshold CLI options for the statusline command.
  • Robust Validation: Implemented comprehensive Zod validation for the new CLI options, ensuring values are integers within the 0-100 range and enforcing the constraint that the low threshold must be less than the medium threshold.
  • Codebase Refinement: Removed obsolete environment variable constants and the getContextUsageThresholds() utility function, simplifying the codebase.
  • Documentation & Schema Updates: Updated the config-schema.json to include the new options and revised the docs/guide/statusline.md to reflect the new CLI-first configuration approach with usage examples.
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 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. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

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.

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.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Aug 22, 2025

Open in StackBlitz

npm i https://pkg.pr.new/ryoppippi/ccusage@578

commit: 5f01d55

@ryoppippi ryoppippi merged commit 2d055c8 into main Aug 22, 2025
14 of 16 checks passed
@ryoppippi ryoppippi deleted the feat/replace-env-vars-with-statusline-options branch August 22, 2025 13:09
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 pull request is a great improvement, replacing environment variables with more discoverable CLI options for context thresholds. The use of Zod for validation is also a good addition. My review focuses on a couple of issues related to how these new options interact with configuration files. Specifically, the validation logic seems to be misplaced, and the options from config files are not being used. I've also pointed out a minor inconsistency in the JSON schema. Addressing these points will make the new feature more robust.

Comment on lines +134 to +137
// Validate threshold ordering constraint: LOW must be less than MEDIUM
if (ctx.values.contextLowThreshold >= ctx.values.contextMediumThreshold) {
throw new Error(`Context low threshold (${ctx.values.contextLowThreshold}) must be less than medium threshold (${ctx.values.contextMediumThreshold})`);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

high

There are a couple of related issues with how the new context threshold options are handled with respect to configuration files.

  1. Misplaced Validation: This validation block runs on ctx.values before options from a configuration file are loaded and merged. This means any thresholds set in a config file will bypass this validation, potentially allowing an invalid state (e.g., low_threshold >= medium_threshold).

  2. Ignoring Config Values: Later in the code (lines 421-425), ctx.values is used again to get the thresholds. This means any values for these options set in a configuration file will be completely ignored, as they are loaded into mergedOptions but never used.

To fix this, the validation should be moved to after mergeConfigWithArgs, and the final merged options should be used for both validation and for determining the color logic. Also, since values from a config file might be strings, they should be coerced to numbers before comparison.

Comment on lines +748 to +759
"contextLowThreshold": {
"type": "string",
"description": "Context usage percentage below which status is shown in green (0-100)",
"markdownDescription": "Context usage percentage below which status is shown in green (0-100)",
"default": 50
},
"contextMediumThreshold": {
"type": "string",
"description": "Context usage percentage below which status is shown in yellow (0-100)",
"markdownDescription": "Context usage percentage below which status is shown in yellow (0-100)",
"default": 80
},
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 type for contextLowThreshold and contextMediumThreshold is set to "string", but their default values are numbers. This is inconsistent with other numeric options in the schema (like refreshInterval) and can be confusing for users editing the config file. It's better to define the type as "number" to ensure consistency and correct type handling by editors and validators.

Suggested change
"contextLowThreshold": {
"type": "string",
"description": "Context usage percentage below which status is shown in green (0-100)",
"markdownDescription": "Context usage percentage below which status is shown in green (0-100)",
"default": 50
},
"contextMediumThreshold": {
"type": "string",
"description": "Context usage percentage below which status is shown in yellow (0-100)",
"markdownDescription": "Context usage percentage below which status is shown in yellow (0-100)",
"default": 80
},
"contextLowThreshold": {
"type": "number",
"description": "Context usage percentage below which status is shown in green (0-100)",
"markdownDescription": "Context usage percentage below which status is shown in green (0-100)",
"default": 50
},
"contextMediumThreshold": {
"type": "number",
"description": "Context usage percentage below which status is shown in yellow (0-100)",
"markdownDescription": "Context usage percentage below which status is shown in yellow (0-100)",
"default": 80
},

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