Skip to content

feat(importer): add Claude Code activity metrics - #8

Merged
tobilg merged 6 commits into
tobilg:mainfrom
jmelloy:claude-import-metrics
Sep 15, 2026
Merged

tobilg merged 6 commits into
tobilg:mainfrom
jmelloy:claude-import-metrics

Conversation

@jmelloy

@jmelloy jmelloy commented Jun 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Historical Claude Code imports now reconstruct activity metrics alongside token/cost usage and repository attribution. Tool activity is emitted from matching successful results, and usage deduplication remains independent of individual tool calls so split assistant responses retain their usage and all completed actions.

Behavior

  • Count successful Edit, Write, and MultiEdit changes using recorded patches or line diffs, excluding unchanged context and trailing-newline overcounts. Skip unsupported overwrites and replace-all operations when the source records cannot establish the actual changes.
  • Recognize Git commit commands with a shell parser and require successful tool results containing Git completion headers. Support Git global options such as -C and -c, multiple completed commits, and string or array tool-result content. Session commands are never executed.
  • Emit one PR metric per distinct repository/number within each file, retain each link's timestamp, and include PR events in date-filter bounds.
  • Attribute session usage to its working repository independently of linked PRs in other repositories. Codex imports prefer the repository URL recorded in session metadata.
  • Emit session-file counts and recorded turn durations in seconds with type=cli. Update the README availability table and import documentation with reconstruction limits and the full-import versus incremental-watch distinction.
  • Upgrade DuckDB's Go driver from v2.10503.1 to v2.10505.0 and its bundled bindings to v0.10505.0. This includes the upstream pointer-alignment fix for reading non-inlined strings under -race/checkptr. Add VARCHAR/BLOB boundary regression coverage.
  • Synchronize the default logger's lazy initialization, reads, and explicit reconfiguration to resolve the pre-existing race exposed by concurrent WebSocket hub logging. Preserve configured formats and levels, and release the mutex before emitting log records. Add concurrency regression tests and run the full backend race suite in macOS CI.

Scope and limitations

Activity reconstruction is available through full import; the watcher continues to import transcripts and token/cost usage. PR links are a proxy for PR activity, not proof of creation. Session counts describe imported session files, and turn durations do not include user typing/reading time. Missing or ambiguous tool results are omitted. These limits and the relevant reconstruction attributes are documented in docs/import.md.

The branch includes the repository-attribution work from #7 and has current main merged into it, preserving the existing contributor commits.

Validation

  • GitHub CI passed for 648e318: tests, Linux/macOS/Windows builds, and the full backend race suite on macOS.
  • Full backend go test ./..., go vet ./..., and go test -race ./... -timeout 120s passed with Go 1.26.8 on macOS arm64 and isolated session paths.
  • Regression coverage includes late usage, distinct tools sharing a request, failed/duplicate tool results, edits with unchanged context, overwrites, replace-all patches, multiple PRs, date-filtered imports, cross-repository attribution, and Codex Git URLs.
  • Storage, importer, and watcher packages passed with -race, including the original TestStateManager reproducer. The new VARCHAR/BLOB test crashes with the old driver at the 13-byte boundary and passes with the upgraded driver; pointer checks remain enabled.
  • The new concurrent-first-use logger test reproduces the race with the previous implementation and passes with the fix. Tests also cover reconfiguration during logging and preservation of lazy defaults, explicit formats, and minimum log levels. The WebSocket race tests and full backend race suite now pass.

@jmelloy
jmelloy marked this pull request as ready for review June 12, 2026 20:17
@tobilg

tobilg commented Jun 14, 2026

Copy link
Copy Markdown
Owner

Hey, thanks for the PR! I pushed some changes on main today, could you eventually rebase?

@jmelloy
jmelloy force-pushed the claude-import-metrics branch from a89847e to cd3ec91 Compare June 16, 2026 03:06
@tobilg

tobilg commented Jun 20, 2026

Copy link
Copy Markdown
Owner

Thanks for the work on this. The feature direction looks useful: bringing Claude Code historical imports closer to the activity metrics shown from live telemetry would make reporting and dashboards more valuable.

Before merging, I think a few correctness details should be tightened so the imported metrics do not mislead users:

  1. claude_code.pull_request.count currently emits at most one PR metric per session. collectSessionMeta keeps only the first structured pr-link, so a session that links or creates multiple PRs would be undercounted. It would be better to emit one metric per distinct PR link.

  2. claude_code.lines_of_code.count is currently based on counting all lines in each old_string and new_string. For Edit/MultiEdit, those strings can include unchanged context, so a one-line edit inside a larger replacement block can be recorded as many removed and many added lines. Either this should compute an actual diff, or the metric should be clearly labeled/documented as an approximate gross replacement size rather than lines changed.

  3. claude_code.commit.count currently checks whether a Bash command contains git commit. That can count failed commits and false positives, because it does not inspect the matching tool result/success. If this metric is shown as commits created, it should ideally be tied to a successful tool result or use stricter command detection.

  4. The new activity metrics are added to full import, but not to the Claude incremental watcher path. That may be acceptable if intentional, but the docs and metric availability table should make the import/watch difference explicit. Otherwise users may expect the same metrics from watch and import.

  5. The branch is currently behind current main, and the CI run is still in action_required state with no completed job signal. I would prefer a rebase on current main and a green CI run before merging.

Overall, I would support landing this after those points are addressed. The product value is solid, but these metrics will likely be used for reporting, so it is important that their semantics are either accurate or explicitly documented as reconstructed estimates.

@tobilg
tobilg merged commit bf6016a into tobilg:main Sep 15, 2026
8 checks passed
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