Skip to content

Conversation

@ryoppippi
Copy link
Owner

@ryoppippi ryoppippi commented Jun 17, 2025

Summary

This PR refactors the codebase to use session terminology instead of five-hour terminology, aligning with Claude Code official billing session concept. Based on Anthropic documentation, Claude Code uses 5-hour sessions for billing, so the code should reflect this semantic meaning rather than just describing the duration.

Changes Made

  • Constants: FIVE_HOURS_MS → SESSION_DURATION_MS
  • Types: FiveHourBlock → SessionBlock
  • Functions: identifyFiveHourBlocks → identifySessionBlocks, loadFiveHourBlockData → loadSessionBlockData
  • Files: five-hour-blocks.internal.ts → session-blocks.internal.ts
  • User-facing text: Updated command descriptions, error messages, and UI labels
  • Tests: Updated all test files to use new terminology

Why This Change?

After researching Claude Code billing documentation, I found that the 5-hour period represents Claude official session billing cycle. Users start a session with their first message, and it lasts for 5 hours. The term session is more semantically accurate than five-hour blocks and aligns with Anthropic official terminology.

Impact

  • ✅ All tests pass
  • ✅ TypeScript compilation successful
  • ✅ ESLint formatting applied
  • ✅ No breaking changes to functionality
  • ✅ Only terminology and naming updated
  • ✅ Documentation reflects accurate Claude Code billing concepts

Test Plan

  • Run bun test - all 155 tests pass
  • Run bun typecheck - no TypeScript errors
  • Run bun run format - code properly formatted
  • Verify functionality unchanged - session block logic works identically
  • Check user-facing text updated consistently across CLI and MCP server

Summary by CodeRabbit

  • Refactor
    • Updated all terminology and functionality from "five-hour blocks" to "session blocks" across the app, including commands, descriptions, logs, and data structures.
    • Renamed relevant constants, types, and functions to reflect the new "session block" terminology.
  • Tests
    • Updated all tests to use "session blocks" instead of "five-hour blocks," ensuring scenarios and expectations remain consistent.

Replace hardcoded FIVE_HOURS_MS constant with SESSION_DURATION_MS to better
reflect Claude Code official billing session terminology. This aligns with
Anthropic documented 5-hour session billing cycles and makes the code more
semantically clear about what the time period represents.

The constant value remains unchanged (5 * 60 * 60 * 1000 = 18000000ms) but
the name now accurately describes it as a session duration rather than just
five hours.
Rename five-hour-blocks.internal.ts to session-blocks.internal.ts and
corresponding test file to better reflect Claude Code session terminology.
Update all import statements across the codebase to reference the new
file names.

Files renamed:
- five-hour-blocks.internal.ts → session-blocks.internal.ts
- five-hour-blocks.internal.test.ts → session-blocks.internal.test.ts

Updated imports in:
- data-loader.ts
- commands/blocks.ts
- session-blocks.internal.test.ts
Update type definition from FiveHourBlock to SessionBlock throughout the
session-blocks.internal.ts file to better reflect Claude Code session
terminology. This change aligns the type name with Anthropic official
billing session concept rather than just describing the duration.

All function signatures and variable declarations within the file have
been updated to use the new SessionBlock type.
Update all imports and function calls to use new SessionBlock terminology:
- loadFiveHourBlockData → loadSessionBlockData
- FiveHourBlock → SessionBlock
- identifyFiveHourBlocks → identifySessionBlocks

Updated files:
- data-loader.ts: function name and return type
- commands/blocks.ts: import, function calls, and type annotations

This completes the transition from FiveHour terminology to Session
terminology in the core data handling logic.
Update command descriptions and user messages to use "session" terminology
instead of "5-hour" references:

- Command descriptions: "5-hour billing blocks" → "session billing blocks"
- Error messages: "No active 5-hour block found" → "No active session block found"
- UI titles: "5-Hour Block Status" → "Session Block Status"
- Report headers: "5-Hour Blocks" → "Session Blocks"

Updated in commands/blocks.ts and mcp.ts to provide consistent user-facing
terminology that aligns with Claude Code official session concept.
Update all test files to use new session terminology:
- FIVE_HOURS_MS → SESSION_DURATION_MS
- FiveHourBlock → SessionBlock
- loadFiveHourBlockData → loadSessionBlockData
- identifyFiveHourBlocks → identifySessionBlocks

This fixes compilation errors after refactoring to session-based naming
convention. All test logic remains the same, only terminology has been
updated to match the new API.
@coderabbitai
Copy link

coderabbitai bot commented Jun 17, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

This change refactors all code, types, and tests from the "five-hour blocks" terminology to "session blocks." It updates function names, constants, type annotations, imports, exports, and user-facing descriptions, while preserving the underlying logic and behavior. No changes are made to the control flow or algorithms.

Changes

File(s) Change Summary
src/commands/blocks.ts, src/mcp.ts Updated imports, command/tool descriptions, and logic to use "session blocks" instead of "five-hour blocks."
src/data-loader.ts Renamed function, types, and logic from "FiveHourBlock" to "SessionBlock"; updated export accordingly.
src/data-loader.test.ts Replaced all test references to "five-hour blocks" with "session blocks"; updated imports and test names.
src/session-blocks.internal.ts Renamed all types, constants, and functions from "FiveHourBlock" to "SessionBlock" and related terminology.
src/session-blocks.internal.test.ts Updated all test imports, types, and function calls to use "SessionBlock" terminology.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CLI
    participant DataLoader
    participant SessionBlockLogic

    User->>CLI: Run "blocks" command
    CLI->>DataLoader: loadSessionBlockData(options)
    DataLoader->>SessionBlockLogic: identifySessionBlocks(entries)
    SessionBlockLogic-->>DataLoader: SessionBlock[]
    DataLoader-->>CLI: SessionBlock[]
    CLI-->>User: Display session block usage report
Loading

Possibly related PRs

Poem

A session block by any name,
Still tracks our work, all just the same.
Five hours gone, a rabbit hops,
Now session blocks, no need for stops!
With code and tests all fresh and neat,
This bunny’s work is now complete. 🐇


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ee7d7b6 and 2d67512.

📒 Files selected for processing (6)
  • src/commands/blocks.ts (8 hunks)
  • src/data-loader.test.ts (8 hunks)
  • src/data-loader.ts (3 hunks)
  • src/mcp.ts (2 hunks)
  • src/session-blocks.internal.test.ts (23 hunks)
  • src/session-blocks.internal.ts (9 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings

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.
    • Explain this complex logic.
    • 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. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • 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 src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

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

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

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

Documentation and Community

  • 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.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jun 17, 2025

Open in StackBlitz

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

commit: 2d67512

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 implements a comprehensive terminology refactor across the codebase, replacing all instances of 'five-hour' with 'session' to accurately reflect Claude Code's official billing model. This change improves semantic clarity and aligns the application's language with Anthropic's documentation, without introducing any functional changes or breaking existing behavior. The refactor includes renaming constants, types, functions, and files, along with updating all user-facing text and ensuring test coverage remains intact.

Highlights

  • Terminology Refactor: All instances of 'five-hour' terminology, including constants (FIVE_HOURS_MS to SESSION_DURATION_MS), types (FiveHourBlock to SessionBlock), and function names (identifyFiveHourBlocks to identifySessionBlocks, loadFiveHourBlockData to loadSessionBlockData), have been renamed to 'session' terminology.
  • File Renaming: The core logic file five-hour-blocks.internal.ts and its corresponding test file five-hour-blocks.internal.test.ts have been renamed to session-blocks.internal.ts and session-blocks.internal.test.ts respectively, reflecting the new terminology.
  • User Experience Alignment: User-facing text, such as command descriptions, error messages, and UI labels, has been updated to consistently use 'session' terminology, ensuring clarity and alignment with Claude Code's official billing concepts.
  • Codebase Consistency: All affected files, including command handlers, data loaders, and their respective tests, have been updated to use the new 'session' naming conventions, maintaining full functionality and passing all existing tests.
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.

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.

@ryoppippi ryoppippi merged commit 7e17c77 into main Jun 17, 2025
9 of 10 checks passed
@ryoppippi ryoppippi deleted the refactor branch June 17, 2025 16:07
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 refactors the codebase to replace 'five-hour' terminology with 'session' terminology, aligning with Claude Code's billing session concept. The changes include renaming constants, types, functions, and files, as well as updating user-facing text and tests. The changes improve the semantic accuracy of the code and align it with Anthropic's official terminology. I have provided feedback to improve the descriptions and logging.

export const blocksCommand = define({
name: 'blocks',
description: 'Show usage report grouped by 5-hour billing blocks',
description: 'Show usage report grouped by session billing blocks',
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Consider adding a more detailed description to clarify what constitutes a 'session billing block'.

description: 'Show usage report grouped by session billing blocks, which represent a 5-hour period of activity'

const projection = projectBlockUsage(block);

logger.box('Current 5-Hour Block Status');
logger.box('Current Session Block Status');
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Consider adding a brief explanation of what a 'Session Block' represents in the logger box.

logger.box('Current Session Block Status (5-hour billing cycle)')

else {
// Table view for multiple blocks
logger.box('Claude Code Token Usage Report - 5-Hour Blocks');
logger.box('Claude Code Token Usage Report - Session Blocks');
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Consider adding a brief explanation of what 'Session Blocks' represents in the logger box.

logger.box('Claude Code Token Usage Report - Session Blocks (5-hour billing cycles)')

server.addTool({
name: 'blocks',
description: 'Show usage report grouped by 5-hour billing blocks',
description: 'Show usage report grouped by session billing blocks',
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Consider adding a more detailed description to clarify what constitutes a 'session billing block'.

description: 'Show usage report grouped by session billing blocks, representing a 5-hour period of activity'

ryoppippi added a commit that referenced this pull request Jun 22, 2025
refactor: rename five-hour terminology to session terminology
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