Repository navigation
Open a forked agent session in its own tab (and background sessions bind the wrong pane) #5884
daniele-casciani
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
What I'd like
Claude Code's
/forkcopies the conversation into a new background session, and the original keeps running in the current pane. The copy then exists only inclaude agents. To work with both, I open a tab by hand and runclaude attach <id>.I'd like Herdr to do that for me. When an agent in a pane forks, open the copy in a new tab of the same workspace, next to the source tab, with the agent's attach command.
What works today, as a user hook
A Claude Code
SessionStarthook with matcherforkdoes most of it:Tested on Herdr 0.9.5 with Claude Code
/fork. The hook fires withsource=fork, the tab opens, and the copy is attached.Where the hook falls short
SessionStart.sleep 3is a guess.agent_resume.rs), so it could do this for any agent that forks.Background sessions bind the wrong pane (related to #5557)
Edit: I first wrote this section from the code alone. I then tested it: the problem exists today, and it affects every background session, not only forks. Below is the tested version.
#5557 asks to add
forkto theherdr:claudearm ofsession_report_allows_session_replacement(src/terminal/state.rs). For--fork-sessionin the same pane, that is right. Background sessions are a different case: their reports go to a pane they do not run in, and today they already get through.How the report reaches a pane:
claude bg-pty-hostprocesses. On my machine every one of them carries the sameHERDR_ENV=1andHERDR_PANE_ID, which looks like the pane the daemon first started in. Foreground sessions carry their own pane, as expected.assets/claude/herdr-agent-state.sh) reports toHERDR_PANE_ID.handle_pane_report_agent_session(src/app/api/panes.rs) resolves the pane from that value alone and does not check that the reporter is the pane's process.What I tested (Herdr 0.9.5, Claude integration v11 installed for the test):
/fork, P was bound toherdr:claudewith the fork's session id.claude attach) hadagent_session: null.herdr-server.log.pane.report_agent_sessionis a routine method, logged only when it fails, so these reports succeeded. Because of that, I could not see whichsourcethe second report used.So P is bound to whichever background session reported last. None of them runs in P.
Why the gate did not stop the first report: the replacement gate acts only when the pane already holds a different
herdr:claudeid, and P held none. The second replacement got through the gate too, so its source must have been one the gate allows (clear,resumeorcompact). Withforkadded, as #5557 proposes, every background fork would replace the id as well.A possible guard: accept a report only when the reporter's process descends from the pane's process. Or give background sessions no pane binding at all.
Questions
All reactions