What Changed#
Added always-on automatic reconciliation of external agent sessions (Claude Code, Codex) when projects become available on a connected environment.
A new useAgentSessionAutoReconcile hook is mounted in the chat layout route. When environment shells bootstrap, it calls the existing idempotent agentSessions.import RPC for every known project, surfacing agent work already on disk in the thread list — without requiring a manual "Import agent sessions…" action.
Related Ideas discussions:
Why#
When connecting to a remote environment via T3 Connect, agent sessions already on disk (e.g. Claude CLI history under ~/.claude) do not appear in the project thread list unless the user manually triggers an import. The existing AgentSessionScanner + AgentSessionImporter infrastructure (#5362) handles the heavy lifting, but is only wired into the first-run Welcome Wizard. Post-onboarding, there is no continuous visibility path.
This PR adds the minimal client-side trigger to close that gap. It reuses the existing server-side import RPC, which is fully idempotent (thread IDs are prefixed with import:, and per-source file-identity watermarks prevent re-reading unchanged transcripts).
What shipped#
useAgentSessionAutoReconcile hook: watches the project list, triggers agentSessions.import once per project per mount cycle
selectUnreconciledProjects pure function: extracted for testability
- Hook mounted in
ChatRouteLayout (_chat.tsx)
- Unit tests for the selection logic
Out of scope#
- Connect-cloud / account-wide session inbox
- Live attach to running
claude --remote-control
- Cross-environment merged thread list
- Settings toggle (import is already idempotent and silent)
Checklist#
Maintainer manual QA checklist#
- Open existing project whose
workspaceRoot matches agent session cwd on disk
- Without using the Import UI, external sessions appear (or appear shortly after open) with history
- Re-open / re-reconcile does not duplicate
import: threads
- Opening a thread does not auto-start a provider turn
- Mismatched
expectedWorkspaceRoot fails clearly / skips safely
- No claim of live remote-control attach — transcript history only
Test commands (run in repo)#
npx vp test run apps/web/src/hooks/useAgentSessionAutoReconcile.test.ts
npx vp test run apps/server/src/project/AgentSessionImporter.test.ts
npx vp test run apps/server/src/project/AgentSessionScanner.test.ts
npx vp run --filter web typecheck
Refs: #6994, #6680
Approvability#
Verdict: Not approved
Macroscope's review found this PR not approvable — This PR adds an always-on workflow that scans and imports external agent-session history for every known project when the chat experience starts, replacing a previously manual action. The new asynchronous production logic changes default runtime behavior and can create or update imported threads across projects.
Not approved because:
- Monthly spending limit reached (workspace setting). Approvability relies on correctness review in order to determine eligibility
Review your spending limits in [Billing settings](https://app.macroscope.com/pingdotgg/settings/billing). You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).