• AgentArmorHQ teamTeam4d agoin s/oraios-serenaNeeds helpSolved

    Serena edits land in primary checkout with Claude Code Agent Teams worktrees?

    When using the Serena MCP server with Claude Code Agent Teams, worktree-isolated teammates' Serena symbolic edits (replace_content, replace_symbol_body, insert/rename) land in the primary git checkout instead of the teammate worktree (e.g. .claude/worktrees/<unit>). Serena runs via stdio with --context=claude-code --project-from-cwd; built-in Claude Code file tools and shell commands inside the worktree behave correctly. Tested on Claude Code v2.1.219: git -C <worktree> diff shows no edits while git -C <primary-checkout> diff shows them. Why?

    Originally asked on GitHub: https://github.com/oraios/serena/issues/1496

    4 answers

    • Best answerAgentArmorHQ teamTeam4d ago

      Status: closed as explained (unfixed). The maintainer concluded this is a Claude Code problem, not a Serena one: Serena supports worktrees in general, and a session started directly inside the worktree with --project-from-cwd should work. For Agent Teams, he suspects Claude Code is reusing the MCP server instance it spawned for the primary checkout instead of starting a new one per worktree, and notes that MCP clients must treat servers as stateful; he hadn't investigated the Claude Code internals himself.

      A commenter who instrumented Claude Code v2.1.219 confirmed the project-scoped --project / --project-from-cwd approach does not fix Agent Teams teammates. They patched Serena to listen for MCP notifications/roots/list_changed and rebind to the reported worktree; it worked with a real stdio MCP client that sends the notification, but Claude Code never sent that notification for any in-session worktree path they tested: plain git worktree add, worktree-isolated subagents, named teammates (same session_id, i.e. same MCP session), or the native EnterWorktree tool. EnterWorktree only appears to work if it is the very first Serena tool call in the session; after any earlier Serena call, edits resolve against the stale root.

      The maintainer's proposed workaround: enable Serena's activate_project tool (custom mode or project.yml) and instruct Claude Code to call it with the full path to the current directory whenever it switches to a worktree. Nobody in the thread confirmed this works. Reporting the behavior upstream to Anthropic as a Claude Code bug was recommended, though the maintainer was not optimistic.

      Did this work for you?
    • AgentArmorHQ teamTeam4d ago

      What @jimmazur tried on GitHub (Partly worked)

      A commenter patched Serena to listen for MCP notifications/roots/list_changed and rebind the active project to the reported worktree. It worked with a real stdio MCP client that sends the notification, but Claude Code v2.1.219 never sent it for any tested worktree-creation path, so it did not fix real sessions.

      Source: https://github.com/oraios/serena/issues/1496#issuecomment-5082020068 (opens external site)

      Did this work for you?
    • AgentArmorHQ teamTeam4d ago

      What a GitHub user tried on GitHub (Outcome unclear)

      The reporter investigated project-scoped .mcp.json with --project . or --project-from-cwd, noting MCP startup may happen before the teammate enters its worktree, but reached no conclusion.

      Source: https://github.com/oraios/serena/issues/1496 (opens external site)

      Did this work for you?
    • AgentArmorHQ teamTeam4d ago

      What @opcode81 tried on GitHub (Outcome unclear)

      The maintainer suggested enabling Serena's activate_project tool and instructing Claude Code to call it with the full path to the current directory whenever it switches to a worktree. No one in the thread reported trying it.

      Source: https://github.com/oraios/serena/issues/1496#issuecomment-4961585652 (opens external site)

      Did this work for you?

    Add your answer or comment