1. Context Window: 1M Auto-Detection
- Root cause: context_limit hardcoded to 200k, Opus 4.6 [1m] has 1M window
- Fix: detect
[1m]in model.id (matches CLI'sNO()function) - Before: 104k tokens showed 77% (against 200k). After: 10% (against 1M)
2. Context Calculation: Match CLI's /context
- Formula:
percentage = round(totalTokens / contextWindow * 100) - Removed erroneous
system_overhead=24500— cache_read + input already includes system prompt - Changed denominator from
window - output_reserveto fullwindow(matches CLI) - Fixed max_output_tokens: 16000 -> 32000
3. Cost Formatting Bug
$10.00displayed as$1due tosed 's/0$//'eating integer digits- Fix:
sed 's/\.00$//'— only strip.00, keep$10.50as$10.50
4. Model Detection Updated
- Added opus-4-6, sonnet-4-6 pattern matching
- Strip
[1m]suffix from settings.json model before case-matching (preventsopus[1m][1m])
5. Adaptive Quota TTL
- 5h utilization <20%: poll every 5min
- 20-50%: every 2min
- 50-80%: every 1min
- 80%+: every 30s
- Previously: fixed 60s regardless of utilization
6. Error Backoff
- 120s cooldown after failed API call (was: retry every tick)
- Error state tracked in
${session_id}.errfile
7. OAuth Gate
- Skip quota/user fetch when
ANTHROPIC_API_KEY,ANTHROPIC_AUTH_TOKEN, orANTHROPIC_BASE_URLset - Skip when credentials file exists but contains no OAuth token
- Eliminates "no token found" log noise for API key users
8. Dynamic User-Agent
- Uses CLI version from input JSON (was: hardcoded
claude-code/2.1.22)
9. Atomic Cache Writes
- Write to
${cache_file}.tmp.$$thenmv -fto prevent truncated JSON from race conditions
10. JSON Injection Prevention
detect_session_boundary()now usesjq -n --arginstead of raw string interpolation
11. Profile Parsing Consolidation
- 10 separate
echo | jqcalls replaced with singleeval "$(jq -r @sh ...)"call
12. Progress Bar Extraction
render_bar()function replaces 70+ lines of copy-paste across 7 bar styles- C-style
for ((i=0; ...))loops replaceseqsubshells
13. Deduplicated Logic
get_user_tier(): single function for tier detection (was: 3 copies)get_adaptive_ttl(): single function for TTL calculation (was: 2 copies)
14. Portability
printf '%b'replacesecho -efor ANSI stripping (portable across shells)sed 's/\.00$//'replacessed -E 's/0+$//'(GNU/BSD compatible)
15. Input Parsing
- Single
eval "$(jq -r @sh ...)"call replaces 12 separate subshells
| Variable | Default | Description |
|---|---|---|
CLAUDE_CONTEXT_LIMIT |
auto | Context token limit override (auto-detected from model.id) |
CLAUDE_CODE_MAX_OUTPUT_TOKENS |
32000 |
Output token reserve |
CLAUDE_DATA_DIR |
script dir | Data directory (usage.jsonl) |
CLAUDE_CACHE_DIR |
$CLAUDE_DATA_DIR/sessions |
Session cache directory |
Initial release with float-to-integer conversion fixes, macOS Keychain support, OrbStack home directory resolution, profile API alignment, per-model quotas, BSD compatibility, user/quota components, and dependency checking.