Overview
The session timer displays how much time remains until your Claude Code usage limit resets, helping you plan your work around usage windows.What You See
- ⌛ Hourglass emoji
- Hours and minutes until reset
- Reset time (HH:MM format)
- Session progress percentage
- Visual progress bar
How It Works
Data Source
Unlike other features, session timer data comes from ccusage (not Claude Code’s JSON):Implementation
Fromfeatures/usage.ts:89-123:
Session calculation breakdown
Session calculation breakdown
Step-by-step process:
- Find active block: Filter ccusage output for
isActive: true - Extract timestamps: Get start time and reset time
- Convert to epochs: Transform ISO timestamps to Unix epochs
- Calculate totals:
total= end_sec - start_sec (total session duration)elapsed= now_sec - start_sec (time already used)remaining= end_sec - now_sec (time left)
- Format output:
- Convert remaining seconds to hours and minutes
- Calculate percentage: (elapsed / total) × 100
- Format reset time as HH:MM
- Generate progress bar: Use
progress_bar()function with session percentage
Time Conversion Utilities
Fromfeatures/usage.ts:127-151:
Epoch Conversion
The function tries multiple methods for maximum compatibility:
- GNU date (gdate on macOS via brew)
- BSD date (native macOS date)
- Python fallback (if date commands fail)
Time Formatting
HH:MM format using either BSD or GNU date syntax.
Color-Coded Progress
Session colors change based on how much time has elapsed: Fromfeatures/usage.ts:18-24:
| Remaining % | Color | ANSI Code | Status |
|---|---|---|---|
| 0-10% | Light pink | 38;5;210 | ⏰ Almost reset time |
| 11-25% | Light yellow | 38;5;228 | ⚡ Getting close to reset |
| 26-100% | Light green | 38;5;194 | ✅ Plenty of time remaining |
Display Implementation
Fromfeatures/usage.ts:159-167:
Configuration
Fromcli/prompts.ts:31:
Session timer is disabled by default because it requires ccusage installation.
Installing ccusage
ccusage doesn’t need to be installed globally—it works via npx:How ccusage integration works
How ccusage integration works
The statusline script checks for ccusage in this order:
- Check if available:
command -v ccusage - Run with timeout: Prevents hanging if ccusage is slow
- Tries
timeout(Linux) - Falls back to
gtimeout(macOS brew) - Runs without timeout if neither available
- Tries
- Parse JSON output: Uses jq to extract active block
- Calculate remaining time: Based on current time and reset time
Example Outputs
- Early in Session
- Mid Session
- Approaching Reset
- Almost Reset
Performance Considerations
Timeout Protection
The ccusage call is wrapped in a timeout to prevent hanging:- Default timeout: 5 seconds
- Fallback: No timeout if
timeoutcommand unavailable - Error handling: Silently fails if ccusage times out
Performance Metrics
| Metric | Value | Notes |
|---|---|---|
| Execution time | 50-150ms | Depends on ccusage speed |
| Network calls | 1 per statusline render | ccusage checks Claude API |
| Overhead | ~100ms added | Only when session feature enabled |
| Failure impact | None | Gracefully omits timer if ccusage fails |
Requirements
| Requirement | Purpose | Installation |
|---|---|---|
| jq | JSON parsing | brew install jq (macOS)apt-get install jq (Linux) |
| ccusage | Usage block data | npm install -g ccusageor works via npx |
| timeout/gtimeout | Prevent hanging | Usually pre-installed |
Troubleshooting
Session timer not showing
Session timer not showing
Check requirements:Solutions:
- Install jq if missing
- Install ccusage:
npm install -g ccusage - Re-run init and enable session feature
ccusage is slow or times out
ccusage is slow or times out
Causes:
- Slow network connection
- Claude API rate limiting
- ccusage checking multiple projects
- Increase timeout in the generated script (edit
.claude/statusline.sh) - Install ccusage globally for faster startup
- Disable session feature if not needed
Incorrect time showing
Incorrect time showing
Timezone issues:The time shown is in your local timezone, but calculations use UTC:If times look wrong, it may be a timezone mismatch in ccusage data.
Progress bar stuck at 0% or 100%
Progress bar stuck at 0% or 100%
Causes:
- Start time or end time not parsed correctly
- Date conversion utilities failing
- Enable logging: Re-run init with debug logging enabled
- Check
.claude/statusline.logfor session calculation values - Test date conversion:
date -d "2024-01-15T22:00:00Z" +%s - Ensure Python 3 is available (fallback for date parsing)
Why Session Timer Requires ccusage
Unlike other features that extract data from Claude Code’s native JSON:Claude Code JSON
Includes:
- Current directory
- Model info
- Context usage
- Token stats
- Cost data
ccusage Required
Only source for:
- Usage block info
- Session start time
- Usage limit reset time
- Active block detection
Next Steps
Cost Monitoring
Track costs alongside session time
Customization
Customize display format and colors