Skip to content

Commit 8feb0bc

Browse files
AnnatarHeclaude
andauthored
feat: add shelltime cc backfill and shelltime codex backfill (#312)
* feat(model): add AI usage backfill API client and helpers - SendHTTPRequestJSON now returns a typed HTTPStatusError for non-2xx responses so callers can tell retryable errors from client errors. The error text is unchanged. - Wire types and senders for the server's /api/v1/cc/backfill endpoints. Backfill events use pointer fields so a failed tool call is sent as "success": false instead of being dropped by omitempty. - Shared helpers for the transcript parsers: stable "bf1:" event ids from natural keys, a JSONL reader without a line length cap, file discovery, session selection, and request packing that keeps whole sessions together and marks a session completed on its last batch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LMCwtubXzBYhQTnX44vhzF * feat(model): parse Claude Code and Codex transcripts for backfill Rebuild historical sessions from local transcripts as backfill events matching what the live OTEL pipeline records. Claude Code (~/.claude/projects, ~/.config/claude/projects or CLAUDE_CONFIG_DIR): one api_request per message id + request id, keeping the most complete usage of a streamed response; human prompts only (no meta, subagent, compaction, local-command or notification lines); tool results paired with their tool calls, keeping only file paths of the parameters. Items copied into resumed sessions are credited once, to the session that started first. Codex (~/.codex/sessions, archived_sessions or CODEX_HOME): conversation_starts, user prompts, response.completed token counts from last_token_usage or the cumulative delta (skipping null and repeated counts), and tool results with exit code and duration. Items copied into forked rollouts are dropped. Batches are also bounded by encoded size, and long prompts and tool arguments are capped, so a batch stays under the server's body limit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LMCwtubXzBYhQTnX44vhzF * feat(commands): add `shelltime cc backfill` and `shelltime codex backfill` Upload past Claude Code and Codex usage from local transcripts that live OTEL tracking missed (before `cc install` or while the daemon was down). The command asks the server which sessions it already has, skips those tracked live, archived or already uploaded, and uploads the rest in batches with retries on server errors. Sessions still running are held back. When it finishes it asks the server to refresh activity data and caches for the uploaded range. Flags: --since/--until, --dry-run (per-day preview), --no-prompts and --ai-summary (opt-in, uses AI credits). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LMCwtubXzBYhQTnX44vhzF --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 8e12ac1 commit 8feb0bc

16 files changed

Lines changed: 3193 additions & 7 deletions

‎README.md‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,10 @@ shelltime codex install
9494
| `shelltime cc install` | Install Claude Code OTEL configuration into `~/.claude/settings.json` |
9595
| `shelltime cc uninstall` | Remove Claude Code OTEL configuration from `~/.claude/settings.json` |
9696
| `shelltime cc statusline` | Emit statusline JSON for Claude Code |
97+
| `shelltime cc backfill` | Upload past Claude Code usage from local transcripts |
9798
| `shelltime codex install` | Add ShellTime OTEL config to `~/.codex/config.toml` |
9899
| `shelltime codex uninstall` | Remove ShellTime OTEL config from `~/.codex/config.toml` |
100+
| `shelltime codex backfill` | Upload past Codex usage from local session files |
99101

100102
### Environment helpers
101103

@@ -189,6 +191,22 @@ Quota sync requires both a ShellTime login (`shelltime auth`) and a ChatGPT-auth
189191

190192
Codex decides which windows are present. ShellTime displays the windows returned by Codex instead of assuming that every account has a fixed 5-hour window.
191193

194+
## Backfilling AI Usage
195+
196+
Live tracking only records sessions that run while the OTEL configuration is installed and the daemon is running. To upload earlier sessions from the transcripts Claude Code and Codex keep on disk:
197+
198+
```bash
199+
shelltime cc backfill --dry-run # show what would be uploaded
200+
shelltime cc backfill # upload Claude Code sessions
201+
shelltime codex backfill # upload Codex sessions
202+
```
203+
204+
- Claude Code transcripts are read from `~/.claude/projects` and `~/.config/claude/projects`, or the directories in `CLAUDE_CONFIG_DIR`. Codex sessions are read from `~/.codex/sessions` and `~/.codex/archived_sessions`, or `CODEX_HOME`.
205+
- Prompts, token usage, models and tool calls are uploaded as if they had been tracked live; the server adds costs. Lines of code, commits and active time are not in the transcripts.
206+
- Sessions the server already has from live tracking are skipped, as are sessions still running. Running the command again only uploads what is missing.
207+
- Flags: `--since` / `--until` (`YYYY-MM-DD`) limit the range, `--no-prompts` uploads prompt lengths without the text, and `--ai-summary` also generates AI session summaries, which use your monthly AI credits.
208+
- Claude Code deletes transcripts after 30 days by default (`cleanupPeriodDays`), so only recent history may be available.
209+
192210
## Security and Privacy
193211

194212
- **Data masking** redacts sensitive command content before it leaves your machine.

0 commit comments

Comments
 (0)