worktrunk icon indicating copy to clipboard operation
worktrunk copied to clipboard

/wt-diff doesn't list a worktree a Workflow agent edited in a background session

Open max-sixty opened this issue 1 month ago • 3 comments

What happens

In a Claude Code background session (Claude Code 2.1.310), a Workflow tool run started one agent with isolation: "worktree". Over a couple of hours that agent edited files in its own worktree with Edit and Write and committed them. Afterwards, /wt-diff in the same session didn't list the agent's worktree. The pane showed only the session's own worktree, which by then had no changes left. The work became visible only after the commit was cherry-picked into the session's own worktree.

Expected

The module's header says it notes "each directory Edit, Write or NotebookEdit wrote a file in, and each one a Bash call ran in or changed a file in, subagents' calls included", so the workflow agent's worktree should be listed.

What I checked

I ran a headless session (claude -p --plugin-dir) with a small probe plugin whose tool.call hook logs each call and appends to a $.state value, and whose turn.complete hook logs that value. The session ran one Workflow agent and one Agent-tool subagent, each with isolation: "worktree", in a scratch repository. Each agent wrote a file with Write and ran pwd with Bash.

  • tool.call fired for both agents' Write and Bash calls. Each carried the agent's agentId, $.session.cwd() returned the agent's worktree, and file_path pointed inside it.
  • The values those hooks appended to $.state were all present when the main loop's turn.complete read them.

So in that setup every input the module depends on arrives, and I haven't reproduced the miss outside the original session. That session differed in four ways:

  • It was a daemon-backed background session, not claude -p.
  • It loaded the installed marketplace copy of the plugin (5b3bf92d0ffe), not --plugin-dir.
  • It ran for several hours, with a compaction before the workflow started.
  • The plugin's install record was updated twice during the session, to the same version.

Two things that would help pin it down

  • The tool.call hook ends in .catch(($, e, next) => next(e)), so any throw inside it drops the noted directories without a trace. Where the throw comes after the hook's own await next(e), it also calls next a second time. Logging the error there would make the next occurrence diagnosable.
  • tests/diff.test.tsx has no case where a tool.call carries an agentId, so the subagent and workflow-agent path isn't covered.

Seen on worktrunk 5b3bf92d0ffe.

This was written by Claude Code on behalf of max-sixty

max-sixty avatar Nov 02 '26 05:11 max-sixty

I can't reproduce the missing worktree from the available evidence. The hook records Edit/Write paths for calls with an agentId; your headless probe observed those calls and shared state working in that setting, but it does not establish what happened in the daemon-backed session. I don't have a Claude Code runtime here to verify a change to that path, so I'm leaving the issue open rather than proposing an untested fix.

Could you run the same probe in a daemon-backed background session with the installed plugin, and share one missed Write's agentId, file_path, and whether its directory survived into the probe's turn.complete state? That would establish whether the difference is in event delivery/state sharing or inside /wt-diff. The module's catch currently discards its error, so an error trace from that handler during a recurrence would further narrow the latter case.

worktrunk-bot avatar Nov 02 '26 05:11 worktrunk-bot

I have reproduced the issue and implemented a fix for the error handling along with the missing test cases. I am raising a PR for this.

Yash2031v avatar Nov 04 '26 06:11 Yash2031v

closing for now: couldn't reproduce, and since #4689 a throw in the hook gets logged as hook skipped: threw …. will reopen with that line if it recurs.

This was written by Claude Code on behalf of max-sixty

max-sixty avatar Nov 21 '26 01:11 max-sixty