Skip to content

Preserve session content when switching executors#511

Merged
bborn merged 3 commits intomainfrom
task/2069-preserve-session-content-when-switching
Mar 18, 2026
Merged

Preserve session content when switching executors#511
bborn merged 3 commits intomainfrom
task/2069-preserve-session-content-when-switching

Conversation

@bborn
Copy link
Owner

@bborn bborn commented Mar 18, 2026

Summary

  • When switching executors on an existing task (e.g. Claude → Codex), the previous session's conversation history is now extracted and included as context in the new executor's prompt
  • Adds GetSessionContent(workDir) to the TaskExecutor interface, implemented for all 6 executors (Claude, Codex, Gemini, Pi, OpenClaw, OpenCode)
  • Works in both daemon (background execution) and interactive (TUI) paths
  • Large sessions are truncated to ~50K chars, keeping the most recent context

How it works

  1. When starting a new executor session, GetPreviousSessionContent() checks if any other executor has session files for the same workDir
  2. If found, it reads and formats the conversation as a "Previous Session Context" section prepended to the prompt
  3. Session file parsing supports: Claude/Pi JSONL, Codex/Gemini JSON (with generic message extraction for varying formats)
  4. Detection is automatic — if the current executor already has its own session, no handoff is needed

Test plan

  • Unit tests for JSONL parsing (Claude-style messages, empty files, system-only messages)
  • Unit tests for JSON parsing (role/content, sender/text, nested content arrays, Gemini parts, auto-discovery)
  • Unit tests for truncation behavior and handoff formatting
  • Unit tests for Claude config dir integration
  • All existing executor tests pass
  • All UI tests pass
  • go vet clean

🤖 Generated with Claude Code

bborn and others added 3 commits March 18, 2026 10:14
When switching from one executor to another on an existing task, the
previous session's conversation history is now extracted and injected
into the new executor's prompt as context. This prevents losing all
context when changing e.g. from Claude to Codex or Gemini.

Implementation:
- Add GetSessionContent(workDir) to TaskExecutor interface
- Implement for all executors: Claude/Pi read JSONL sessions,
  Codex/Gemini parse JSON sessions with generic message extraction,
  OpenClaw/OpenCode return empty (no file-based sessions)
- Add GetPreviousSessionContent() on Executor that checks other
  executors for session content when current executor has no session
- Wire into both daemon (executeTask) and interactive (TUI) paths
- Truncate large sessions to ~50K chars keeping most recent context

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Tests the 4 key branches: current executor has session (skip),
other executor has session (return handoff), no sessions found
(return empty), and other has session ID but empty content (skip
to next).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@bborn bborn merged commit 7ed6e21 into main Mar 18, 2026
3 of 4 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.

1 participant