Fix mcp worktree setup script - #39
Merged
frenchie4111 merged 4 commits intoMay 19, 2026
Merged
Conversation
The MCP create_worktree endpoint called addWorktree directly, bypassing WorktreesFSM.finishCreate, so the configured setup/teardown scripts never ran for MCP-created worktrees. Adds runWorktreeSetup to WorktreesFSM and wires it through ControlServerDeps so the control server runs it after addWorktree succeeds, before broadcasting the externalCreate event.
- Extract resolveSetupCmd private helper to remove duplicated loadRepoConfig + getWorktreeSetupCmd logic shared between finishCreate and runWorktreeSetup - Fire setup script async in control-server so the MCP caller gets the worktree path back immediately rather than blocking on a potentially slow user-defined shell command
Collaborator
|
great catch |
Collaborator
|
Looks like we should also be doing |
Extract the symlink into WorktreesFSM.applySharedClaudeSettings and call it synchronously from the control-server POST /worktrees handler before broadcasting, so the Claude tab spawned by ensureInitialized sees shared settings on its first read. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Symlink runs synchronously before the first await, so the MCP route can fire-and-forget runWorktreeSetup and still have the symlink in place before broadcasting (and thus before the new Claude tab spawns). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The MCP
create_worktreetool calledaddWorktreedirectly incontrol-server.ts, bypassingWorktreesFSM.finishCreate. This meant the user-configured setup script (global or per-repo) never ran when Claude Code created a worktree — only worktrees created via the Harness UI sidebar ran the script.Changes
WorktreesFSM.runWorktreeSetup— new public method that runs the setup script for a worktree created outside the FSM. Resolves the command the same wayfinishCreatedoes: repo-specific.harness.jsonfirst, global setting as fallback.ControlServerDeps.runWorktreeSetup— wired through the deps interface socontrol-server.tscan call it afteraddWorktreesucceeds, before broadcastingworktrees:externalCreate.[control].resolveSetupCmdprivate helper — extracted theloadRepoConfig+getWorktreeSetupCmdfallback into a shared method used by bothfinishCreateandrunWorktreeSetup.Fixes #38