feat: import Anthropic Console/Workbench session exports#46
Open
jakduch wants to merge 5 commits into
Open
Conversation
Adds 'python3 cli.py import-workbench <PATH>' which ingests JSON dumps
exported from the Anthropic Console/Workbench so prompt-engineering work
shows up alongside Claude Code sessions in the dashboard.
- Graceful parser: accepts top-level arrays, {runs|messages|data:[...]}
wrappers, snake_case and camelCase token field names, ISO 8601 and
unix-epoch timestamps. Malformed records are skipped with a count.
- Imported entries are assigned project_name='Workbench',
session_id='wb-<sha1(file)[:12]>', git_branch='', and
message_id='wb-<file>-<line>' so re-importing the same file is a no-op
(deduped via the existing unique partial index on turns.message_id).
- Reuses scanner.upsert_sessions / scanner.insert_turns so totals,
pricing, and dashboard queries work without further changes.
- Prints a summary: imported, already-present, skipped, total tokens.
The Console export format isn't officially documented; the parser is
intentionally lenient so it can adapt if Anthropic tweaks the shape.
Tests (9) cover empty input, valid records, malformed entries skipped,
object/camelCase variants, idempotency, summary output, missing file
and invalid JSON error paths.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this add and why do you believe it belongs in this dashboard?
Adds a
python3 cli.py import-workbench <PATH>command that imports an Anthropic Console / Workbench session export (the JSON you can download from console.anthropic.com after experimenting in the Workbench) into the same SQLite store the CLI scanner writes to. Imported turns land under a syntheticWorkbenchproject so they appear in the dashboard alongside Claude Code CLI usage.Most users who run this dashboard also iterate on prompts in the Console — model picks, cache strategies, and one-off experiments. Today that spend is invisible here, which makes the "personal Claude usage" picture incomplete and skews per-model totals. Pulling those exports in keeps the dashboard promise (one place to see your Claude usage) without coupling to any Anthropic API: it is a local, opt-in file import. Re-importing the same file is a no-op thanks to a deterministic
message_idand the existing unique index onturns.message_id, so it is safe to run repeatedly.Checklist
Code correctness
calcCost()calls pass 6 arguments:(model, inp, out, cache_read, cache_creation, cache_1h)`), not escaped ones (\`)Tests
python3 -m unittest discover -s tests -v— all passingpython3 -m unittest tests.test_browser -v— all passingScope
dashboard.py,scanner.py,cli.py,pricing.py,cowork.py,tests/) — or I have explained below why a new file is needed