Skip to content

feat: add --full flag to disable column truncation#919

Open
BuluBulugege wants to merge 2 commits intoryoppippi:mainfrom
BuluBulugege:feat/full-no-truncate
Open

feat: add --full flag to disable column truncation#919
BuluBulugege wants to merge 2 commits intoryoppippi:mainfrom
BuluBulugege:feat/full-no-truncate

Conversation

@BuluBulugege
Copy link
Copy Markdown

@BuluBulugege BuluBulugege commented Mar 31, 2026

Summary

  • Add --full CLI flag to all report commands (daily, monthly, weekly, session)
  • When enabled: disables column width scaling, disables compact mode, disables word wrapping
  • Table may overflow horizontally but all data displays at full width without truncation
  • Useful when users want to see complete numbers (e.g., 7,669,754 instead of 7,669,7…)

Depends on #918

Test plan

  • COLUMNS=80 ccusage daily — verify normal truncation/compact behavior
  • COLUMNS=80 ccusage daily --full — verify all columns at full width, no truncation
  • ccusage daily --full — verify works on wide terminal too
  • ccusage session --full — verify session columns including Last Activity

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Added --full command-line option to display all columns at full width without truncation.
    • Added cache hit rate metric to usage reports showing the percentage of cached token reads versus total token usage.

BuluBulugege and others added 2 commits March 31, 2026 21:26
Add Hit Rate as a first-class metric alongside Input/Output/Cache columns
in daily, monthly, weekly, and session reports. The hit rate is calculated
as CacheRead / (Input + CacheCreate + CacheRead), color-coded green (>=70%),
yellow (>=40%), or red (<40%). Also included in compact mode and JSON output.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
When terminal width is insufficient, ResponsiveTable normally scales column
widths proportionally and wraps text within cells. The --full flag disables
this behavior: columns use their full content width, compact mode is
overridden, and word wrapping is disabled. The table may overflow
horizontally but all data is displayed without truncation.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 31, 2026

📝 Walkthrough

Walkthrough

This PR adds a --full CLI flag that disables table column truncation to allow horizontal overflow, implements cache hit rate calculation and display across usage reports, and adjusts table formatting to accommodate the new cache hit rate column in the daily, monthly, weekly, and session commands.

Changes

Cohort / File(s) Summary
Shared CLI Arguments
apps/ccusage/src/_shared-args.ts
Added new full boolean flag (default: false) to enable full-width table display without truncation.
Usage Report Commands
apps/ccusage/src/commands/daily.ts, apps/ccusage/src/commands/monthly.ts, apps/ccusage/src/commands/session.ts, apps/ccusage/src/commands/weekly.ts
Extended JSON output with cacheHitRate field, configured tables to respect noTruncate: ctx.values.full, and adjusted visual separator spacing (incrementing addEmptySeparatorRow argument by 1 per command to accommodate the new Hit Rate column).
Table Rendering Utilities
packages/terminal/src/table.ts
Added noTruncate option to TableOptions and UsageReportConfig; updated ResponsiveTable logic to skip truncation/wrapping when noTruncate is true; introduced calculateCacheHitRate() and formatCacheHitRate() functions; appended "Hit Rate" column to usage report tables with gray styling in breakdown rows and yellow in totals.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • ryoppippi

Poem

🐰 A rabbit hops through columns wide,
With truncation turned aside!
Cache rates bloom like clover sweet,
Tables fit the terminal's beat!
Full width tables, what a treat! 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: add --full flag to disable column truncation' clearly and directly describes the primary change—adding a new CLI flag to disable column truncation in table output.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (3)
packages/terminal/src/table.ts (1)

477-484: ⚠️ Potential issue | 🟡 Minor

Separate hit-rate value formatting from coloring.

formatCacheHitRate() now returns a pre-colored string, but the new breakdown and totals rows want the same percentage in gray/yellow row styling. As written, those cells will render with the hit-rate color instead of the row color. Return a plain percentage from the shared helper, or let callers pass the final colorizer.

Also applies to: 529-544, 669-678

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/terminal/src/table.ts` around lines 477 - 484, The hit-rate helper
formatCacheHitRate currently returns a colored string which prevents row-level
coloring (e.g. in the breakdown and totals rows around the row pushing at
table.ts lines shown); change formatCacheHitRate to return a plain percentage
string (or add an optional colorizer parameter) and then update callers (e.g.
the places that call formatCacheHitRate(breakdown) in the rows near the shown
diffs and the other regions around the 529-544 and 669-678 areas) to apply the
desired color themselves (wrap the returned plain string with pc.gray(...) or
pc.yellow(...) as appropriate) so the row coloring is preserved.
apps/ccusage/src/commands/daily.ts (1)

102-125: ⚠️ Potential issue | 🟠 Major

daily --instances --json output missing cacheHitRate field in grouped schema

The grouped JSON path (when --instances is enabled) uses groupByProject(dailyData) which returns DailyProjectOutput[] objects. This type does not include cacheHitRate, unlike the flat daily JSON branch which explicitly adds it via calculateCacheHitRate(data). Update DailyProjectOutput type in _json-output-types.ts to include cacheHitRate, and update groupByProject() in _daily-grouping.ts to calculate and include it.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/ccusage/src/commands/daily.ts` around lines 102 - 125, The grouped JSON
path when using --instances omits cacheHitRate because DailyProjectOutput (in
_json-output-types.ts) lacks that field and groupByProject (in
_daily-grouping.ts) does not compute it; update the DailyProjectOutput type to
include cacheHitRate: number (or nullable as appropriate) and modify
groupByProject(dailyData) to compute cacheHitRate for each DailyProjectOutput by
calling the existing calculateCacheHitRate(data) logic (or replicating its
calculation) for each project grouping so the grouped JSON includes cacheHitRate
alongside other fields.
apps/ccusage/src/commands/monthly.ts (1)

69-85: ⚠️ Potential issue | 🟡 Minor

Add cacheHitRate to totals JSON to match per-row entries.

Per-month JSON entries now expose cacheHitRate, but the totals object does not. This creates schema inconsistency across the same JSON response. Update both the hardcoded empty-output totals (lines 44–51) and the call to createTotalsObject() (line 84) to include the aggregate cache hit rate.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/ccusage/src/commands/monthly.ts` around lines 69 - 85, The totals JSON
is missing cacheHitRate causing schema mismatch; update the hardcoded empty
totals object (the one returned when no data) to include cacheHitRate (e.g., 0
or null) and modify createTotalsObject so its returned totals include an
aggregate cacheHitRate computed consistently (use calculateCacheHitRate or
compute from totals.inputTokens/ totals.outputTokens/ cache read/creation counts
as your existing logic does) so the totals key in the JSON matches the per-month
entries; ensure the call that builds jsonOutput.totals still uses
createTotalsObject(totals) but that createTotalsObject and the empty totals
value both produce a cacheHitRate field.
🧹 Nitpick comments (1)
apps/ccusage/src/_shared-args.ts (1)

113-116: Mention the --compact override in --full help text.

--full also disables compact mode, but the description only talks about truncation. Calling that out in --help makes --compact --full behavior discoverable.

✏️ Suggested wording
-		description: 'Show all columns at full width without truncation (allows horizontal overflow)',
+		description:
+			'Show all columns at full width without truncation (allows horizontal overflow and overrides --compact)',
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/ccusage/src/_shared-args.ts` around lines 113 - 116, Update the
description for the "full" option in the options object (the property named full
in _shared-args.ts) to mention that it disables compact mode (i.e., it overrides
--compact). Edit the description string to combine the existing text about
showing all columns/full width with a short clause like "This also disables
compact mode and overrides --compact" so the behavior is discoverable in --help
output.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@apps/ccusage/src/commands/daily.ts`:
- Around line 102-125: The grouped JSON path when using --instances omits
cacheHitRate because DailyProjectOutput (in _json-output-types.ts) lacks that
field and groupByProject (in _daily-grouping.ts) does not compute it; update the
DailyProjectOutput type to include cacheHitRate: number (or nullable as
appropriate) and modify groupByProject(dailyData) to compute cacheHitRate for
each DailyProjectOutput by calling the existing calculateCacheHitRate(data)
logic (or replicating its calculation) for each project grouping so the grouped
JSON includes cacheHitRate alongside other fields.

In `@apps/ccusage/src/commands/monthly.ts`:
- Around line 69-85: The totals JSON is missing cacheHitRate causing schema
mismatch; update the hardcoded empty totals object (the one returned when no
data) to include cacheHitRate (e.g., 0 or null) and modify createTotalsObject so
its returned totals include an aggregate cacheHitRate computed consistently (use
calculateCacheHitRate or compute from totals.inputTokens/ totals.outputTokens/
cache read/creation counts as your existing logic does) so the totals key in the
JSON matches the per-month entries; ensure the call that builds
jsonOutput.totals still uses createTotalsObject(totals) but that
createTotalsObject and the empty totals value both produce a cacheHitRate field.

In `@packages/terminal/src/table.ts`:
- Around line 477-484: The hit-rate helper formatCacheHitRate currently returns
a colored string which prevents row-level coloring (e.g. in the breakdown and
totals rows around the row pushing at table.ts lines shown); change
formatCacheHitRate to return a plain percentage string (or add an optional
colorizer parameter) and then update callers (e.g. the places that call
formatCacheHitRate(breakdown) in the rows near the shown diffs and the other
regions around the 529-544 and 669-678 areas) to apply the desired color
themselves (wrap the returned plain string with pc.gray(...) or pc.yellow(...)
as appropriate) so the row coloring is preserved.

---

Nitpick comments:
In `@apps/ccusage/src/_shared-args.ts`:
- Around line 113-116: Update the description for the "full" option in the
options object (the property named full in _shared-args.ts) to mention that it
disables compact mode (i.e., it overrides --compact). Edit the description
string to combine the existing text about showing all columns/full width with a
short clause like "This also disables compact mode and overrides --compact" so
the behavior is discoverable in --help output.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 604e66d3-6746-4d1f-bcd3-08a5c4ac143a

📥 Commits

Reviewing files that changed from the base of the PR and between 61ee04d and 37d883d.

📒 Files selected for processing (6)
  • apps/ccusage/src/_shared-args.ts
  • apps/ccusage/src/commands/daily.ts
  • apps/ccusage/src/commands/monthly.ts
  • apps/ccusage/src/commands/session.ts
  • apps/ccusage/src/commands/weekly.ts
  • packages/terminal/src/table.ts

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.

1 participant