Skip to content

Fix mcp worktree setup script - #39

Merged
frenchie4111 merged 4 commits into
ness-dev:mainfrom
ljacomet:fix-mcp-worktree-setup-script
May 19, 2026
Merged

Fix mcp worktree setup script#39
frenchie4111 merged 4 commits into
ness-dev:mainfrom
ljacomet:fix-mcp-worktree-setup-script

Conversation

@ljacomet

@ljacomet ljacomet commented May 19, 2026

Copy link
Copy Markdown
Contributor

Problem

The MCP create_worktree tool called addWorktree directly in control-server.ts, bypassing WorktreesFSM.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 way finishCreate does: repo-specific .harness.json first, global setting as fallback.
  • ControlServerDeps.runWorktreeSetup — wired through the deps interface so control-server.ts can call it after addWorktree succeeds, before broadcasting worktrees:externalCreate.
  • Async execution — unlike the UI path (which blocks with a live progress screen), the control server fires setup asynchronously and responds to the MCP caller immediately. Errors are logged to [control].
  • resolveSetupCmd private helper — extracted the loadRepoConfig + getWorktreeSetupCmd fallback into a shared method used by both finishCreate and runWorktreeSetup.

Fixes #38

ljacomet added 2 commits May 19, 2026 18:11
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
@frenchie4111

Copy link
Copy Markdown
Collaborator

great catch

@frenchie4111

Copy link
Copy Markdown
Collaborator

Looks like we should also be doing shareClaudeSettings in the new standardized setup (WorktreesFSM.runWorktreeSetup). I am going to have my claude update the PR accordingly

frenchie4111 and others added 2 commits May 19, 2026 12:02
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>
@frenchie4111 frenchie4111 mentioned this pull request May 19, 2026
12 tasks
@frenchie4111
frenchie4111 merged commit 47a61d9 into ness-dev:main May 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Worktree creation is not consistent

2 participants