Skip to content

feat(workspace-server): import & store Claude Code CLI sessions#2877

Draft
adboio wants to merge 1 commit into
posthog-code/import-cc-1-agent-replayfrom
posthog-code/import-cc-2-backend
Draft

feat(workspace-server): import & store Claude Code CLI sessions#2877
adboio wants to merge 1 commit into
posthog-code/import-cc-1-agent-replayfrom
posthog-code/import-cc-2-backend

Conversation

@adboio

@adboio adboio commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Problem

Changes

How did you test this?

Automatic notifications

  • Publish to changelog?
  • Alert Sales and Marketing teams?

Add the server side of importing a Claude Code CLI session: a
claude_session_imports table + repository, the claude-cli-sessions
service (scan ~/.claude for a repo, snapshot a transcript into
CLAUDE_CONFIG_DIR, and track imports with content-fingerprint
divergence detection), agent loadSession support to resume the imported
session, best-effort snapshot cleanup on task delete, and the tRPC
router + DI wiring.

Part 2/3 of splitting #2873 (import Claude Code sessions).

Generated-By: PostHog Code
Task-Id: 6c93b6e8-27b6-45c8-8135-73a09076ea93

adboio commented Jun 23, 2026

Copy link
Copy Markdown
Contributor Author

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@github-actions

Copy link
Copy Markdown

React Doctor found no issues in the changed files. 🎉

Reviewed by React Doctor for commit 8cbec5f.

@greptile-apps

greptile-apps Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Comments Outside Diff (2)

  1. packages/workspace-server/src/services/claude-cli-sessions/claude-cli-sessions.ts, line 2177-2182 (link)

    P2 Files deleted before the DB row is cleared

    removeSnapshotFiles runs first, then deleteByTaskId. If anything interrupts execution between those two steps (process crash, unexpected exception after force: true actually succeeds), the import row survives while its files are gone. On the next listForRepo call the source session shows "imported" with a now-deleted importedTaskId, and there is no way to re-import without manually clearing the DB.

    Reversing the order — delete the DB row first, then the files — produces better failure semantics: if the file deletion subsequently fails, the source session already shows "new" and can be re-imported; any orphaned file wastes only disk space.

  2. packages/workspace-server/src/services/claude-cli-sessions/claude-cli-sessions.ts, line 2099 (link)

    P2 Full-file read in importSession vs chunked reads in the listing path

    fs.readFile(sourcePath, "utf-8") loads the entire transcript into a JavaScript string before any processing, while listForRepo deliberately uses bounded head/tail reads. A CLI session with thousands of turns can easily be several megabytes; this import call then allocates a second copy while building the rewritten array. Using readline (or createReadStream) would keep memory usage proportional to a single line at a time and is consistent with the chunked approach already used in scanning.

    Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Reviews (1): Last reviewed commit: "feat(workspace-server): import & store C..." | Re-trigger Greptile

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.

1 participant