Claude plugin: the /wt-diff tool.call hook keeps Claude Code's Code Mode from starting
Claude Code's experimental Code Mode (CLAUDE_CODE_EXPERIMENTAL_CODE_MODE=1, v2.1.323+) doesn't start while an installed mod handles tool calls. With the worktrunk plugin enabled, a new session shows:
⚠ Code Mode (experimental) isn't available: it doesn't yet work with an installed mod (a plugin with JavaScript hooks) that checks tool calls. Starting with the ordinary tools.
/plugin lists 1 mod active · worktrunk. The hook is the tool.call handler in plugins/worktrunk/hooks/register.tsx. It only notes which directories a call changed so /wt-diff can list them, and never blocks or rewrites a call. Today the only workaround is disabling the plugin, which also drops the activity markers and the WorktreeCreate/WorktreeRemove hooks.
What I tested on Claude Code 2.1.325, loading the plugin with --plugin-dir:
register.tsx variant |
Code Mode |
|---|---|
Current main |
Doesn't start |
tool.call registered behind if (options?.track_tool_calls !== false), with a userConfig option set to false |
Doesn't start |
tool.call handler removed |
Starts |
So gating the hook behind a userConfig option isn't enough. claude plugin validate still lists tool.call among the module's hooks when it's behind the if, which suggests Claude Code decides from a static scan of the module's source. I haven't confirmed that the scan is what Code Mode uses.
Possible directions; which one fits is your call:
- Note changed directories from a settings hook instead of the mod. A
PostToolUsehook forEdit|Write|NotebookEdit|Bashrunningwt config plugins claude hook, as the other events already do, would record the directories somewhere the mod reads them atturn.completeor refresh. That keeps/wt-diffcomplete and Code Mode compatible for everyone, with no option. - Drop per-call tracking.
/wt-diffwould list the session's own worktree, noted at session start and after each turn, plus worktreeswt listreports as changed when the pane opens. - Ship the tracking as a separate plugin that Code Mode users leave disabled.
Happy to send a PR for whichever direction you prefer.
🤖 Co-authored with Claude Code
I haven't opened a PR for this. I can't run Code Mode from CI, so I can't check a fix against it. Which of your three directions to take is a product call for a maintainer. I'm not ruling on it here. Here is what each direction would cost, judging by the tool.call handler:
The handler does two jobs, and turn.complete already covers part of both:
- It notes directories. It records the parent directory of each file that Edit, Write or NotebookEdit wrote, the directory a Bash call ran in, and the files a Bash call changed. That last list comes from the engine's
bashEditDiffon the call's result. It also notes directories from subagents' calls.turn.completenotes only the session's own directory. - It refreshes the open pane during a turn. The refresh runs about 400ms after a burst of calls goes quiet.
turn.completerefreshes only once the turn ends.
What each direction would change:
- A
PostToolUsesettings hook. The hook payload includes the tool input andcwd, so it can recover the Edit, Write and NotebookEdit directories and where Bash ran. I haven't confirmed that the payload includes the list of files a Bash call changed, so a Bash call that writes into another worktree could go unnoted. This direction also starts onewtprocess per tool call, and today the module starts none until the pane opens. It also needs a file thatwtwrites and the module reads. Live refresh during a turn would end, and the pane would update only at turn end. - Dropping per-call tracking. The pane would miss edits made outside the session's own worktree, including a subagent working in its own worktree. Adding the worktrees that
wt listreports as changed would also change what the pane means. It currently shows the worktrees this session worked in, andwt listwould add worktrees that other sessions or the user changed. - A separate plugin. This keeps today's behavior for everyone who doesn't use Code Mode. The cost is splitting the Claude plugin's files and keeping a second install path in sync.
Your test results suggest Claude Code decides from the module's static list of hooks, so a runtime switch can't help. A fix has to remove tool.call from the module that Code Mode users load.
do we have any indication whether this is a temporary or permanent thing?
I'd be surprised if we can't use mods with code mode in the end state. if we can't then we should reduce the scope of the plugin.
but I'm also hesitant to make a big change and then CC starts supporting it (or at least working around it) in a couple days
one option would be to disable these features in wt-diff while we wait to find out: how much would we lose if we disabled / worked around having this hook?
Temporary or permanent: Anthropic hasn't published a timeline. The only hint is wording. The startup reason says mods "doesn't yet work", the same "yet" as "can't be used together with agent teams yet". The Code Mode page gives only the fix "Turn off the mod that checks tool calls" and says Code Mode itself "may change or be removed in any release." So it looks like an interim limitation, but nothing commits to lifting it.
What we'd lose by removing the tool.call handler (register.tsx#L105-L133), based on reading the code. session.start and turn.complete would still note the session's own directory and refresh the pane, so:
- Typical session, working in its own worktree: the list is unchanged. The only difference is that the pane refreshes at the end of each turn, not about 400ms after each burst of edits.
- Lost: worktrees the session touches without being in them. That covers Edit or Write on an absolute path in another worktree, a Bash command that changes files elsewhere, and subagents working in their own worktrees. It also covers a worktree the session
cds through mid-turn and leaves before the turn ends, sinceturn.completeonly sees where the session ended up. - Still reachable:
/wt-diff <branch>opens any worktree explicitly and adds it to the list, so a missed worktree is one command away.
The change is small and easy to revert: delete the handler and the now-unused changedFiles helper, then trim one sentence in the docs ("or when the session or one of its subagents edits a file there…"). Restoring it later is a revert. I can open that PR if you want to go this way while we wait.
I have worked around it with a temporary local fork for now.
thanks @MattMencel. this is fixed upstream: Claude Code 2.1.327 stopped Code Mode refusing to start when a mod hooks tool calls, so updating should let you drop the fork. closing, but reopen if it still blocks you.
This was written by Claude Code on behalf of max-sixty