Skip to content

Import an agent session: pick any Claude Code or codex session and resume it - #278

Merged
Mpdreamz merged 2 commits into
mainfrom
feature/ability-import-claude-session
Nov 17, 2026
Merged

Mpdreamz merged 2 commits into
mainfrom
feature/ability-import-claude-session

Conversation

@akira28

@akira28 akira28 commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

Scope: only Claude Code and codex for now. The other agents (cursor, pi, opencode, gemini) can be added in follow-up PRs, one each, once their on-disk session formats are checked.

Closes #271.

What

Importing a worktree resumed only the newest Claude Code session kept for its folder. You couldn't pick an older one, resume a codex session, or import a session from a folder heed doesn't know or outside any git repo.

  • Ia (session.import.agent, also Import an agent session… in the menu bar) lists the Claude Code and codex sessions on this Mac that heed doesn't have yet, newest first, from any folder. Each row shows the first prompt, the agent, the age and the folder. Type to filter by prompt, agent or folder.
  • ↩ imports the session after a confirmation and resumes it with the agent that ran it (claude --resume <id> / codex resume <id>, with heed's hooks):
    • On a worktree heed knows: it becomes that worktree's session. If the worktree already has one, heed goes to it.
    • In a repo heed doesn't know: the repo is adopted first (as Ip does).
    • Outside any git repo: it becomes a chat in that folder (Import.chatSession).
  • Sessions already in heed (by agentSessionID), sessions where nothing was typed, and sessions whose folder is gone are left out.
  • Worktree import (Iw, Ip, ↩ in Repos) now resumes the newest session of either agent kept for the folder (Import.newestSessions). If that session's agent isn't in your config, heed starts your default agent fresh instead of resuming under another agent.

Formats

  • Claude Code: ~/.claude/projects/*/<id>.jsonl, top-level files only (subagent transcripts are in subfolders). The folder comes from the lines' cwd, never from the project folder's name, which loses _ and ..
  • codex: ~/.codex/sessions/<yyyy>/<mm>/<dd>/rollout-<time>-<id>.jsonl. The id and folder come from session_meta. The prompt is the first user input_text that isn't <…> context or # AGENTS.md. Checked against codex 0.162 rollouts (recorded in PLAN.md). heed's own codex calls run with --ephemeral and leave none.
  • Only the first 256KB of each transcript is read, and only for the newest 300. In real rollouts the prompt sits at most 84KB in.

Code

  • HeedCore/StartWork/Import.swift: allClaudeSessions, allCodexSessions, allSessions, newestSessions(for:), chatSession. Building the agent command is shared by the worktree and chat imports.
  • HeedApp/Model/AppModel+AgentImport.swift: the picker, the import, and fixture sessions for shots. commitImported is extracted from importWorktrees and shared.
  • AgentImportView in MainWindow.swift, modelled on the Iw picker.

Verified

  • mise run test: 2508 tests pass. The new ones cover the Claude scan (across folders, cwd read from the transcript, excluded, prompt-less and subagent files), the codex scan, the mixed newest-first list, newest per worktree, and resume commands for chats with either agent.
  • swiftformat --lint (the pinned 0.58) and swiftlint are clean. mise run lint picked up a global swiftformat 0.64 locally and flagged untouched files. text-check is clean.
  • A one-off scan of a real home found 116 Claude and 22 codex sessions in 0.28s, all with a folder (the throwaway test isn't committed).
  • Shot worktrees/import-agent was rendered and looked at; import-worktree* were re-rendered for the new subtitle.

Not verified live

No import was done in the running app. The codex sessions available were all from Codex Desktop, and the codex CLI wasn't installed, so codex resume <id> picking up a Desktop session is untested.

🤖 Generated with Claude Code

…sume it

`Ia` (session.import.agent, also in the menu bar) lists the Claude Code and
codex sessions on this Mac that heed does not have, newest first, from any
folder. Picking one resumes it with the agent that ran it: on its worktree,
in its repo (added if new), or as a chat in its folder. Importing a worktree
now resumes the newest session of either agent kept for it.

Closes #271

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added the enhancement New feature or request label Nov 16, 2026
@akira28
akira28 requested a review from Mpdreamz November 16, 2026 15:37
The agent session picker joins main's dialog stack (AppModel.Modal) instead of
its own stored variable, and clicksReachLists is main's !dialogOpen.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>

@Mpdreamz Mpdreamz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NICE!

@Mpdreamz
Mpdreamz merged commit ad5b86b into main Nov 17, 2026
5 checks passed
@Mpdreamz
Mpdreamz deleted the feature/ability-import-claude-session branch November 17, 2026 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Import an agent session (Claude Code, codex): pick any one and resume it

2 participants