Feature Request: Cross-Repo Worktree Coordination
Cross-repo worktree coordination
Hi! Love worktrunk so much, thank you for creating and maintaining it!
Problem
We run a backend + frontend stack where each repo uses worktrunk for isolated worktrees. The worktrees themselves work great — each gets unique ports, containers, and a port registry. The pain point is wiring them together.
When we need both services running locally (which is frequent — visual verification, E2E testing, coordinated feature work), the workflow today is:
- Create worktree in repo A
- Create worktree in repo B
- Read A's port registry to find its web port
- Manually write that port into B's
.env/.envrc - If B needs a dev server port too, figure out a free port that doesn't collide with other worktrees
This is tedious and error-prone, especially with multiple parallel worktrees. We've had port collisions, stale .env files pointing at the wrong worktree, and agents (AI coding assistants) failing to set up the connection correctly without extensive prompting.
Use cases
- Service-primary development: Working in backend, need the frontend running against it to verify UI changes (or vice versa). Want a throwaway worktree in the other repo wired to my ports.
- Coordinated feature work: Both repos have feature branches for the same ticket. Need to wire them together regardless of branch names.
- Testing a teammate's branch: Want to point my backend at a colleague's frontend branch (or vice versa) without modifying their worktree.
- Multiple parallel sessions: Two developers (or AI agents) each need their own paired backend+frontend, running simultaneously without port conflicts.
What we've tried
We built a bash script (pair-worktree.sh) with shell config files in each repo. It reads the port registry, resolves env vars, and writes .env files. It works, but:
- Shell config files with functions for env var generation are fragile (variable expansion timing issues)
- Parsing the JSON port registry from bash requires sed/grep hacks
- The config format is disconnected from
wt.toml— a second system to maintain - Each repo needs its own copy of the same script
What we think could help
Some form of pair/link concept in worktrunk where repos can declare how they connect to each other — what env vars they need from a partner's port registry — and wt handles the resolution. The port registry and templating infrastructure already exist ({{ branch | hash_port }}), so extending that to cross-repo references feels natural.
Rough idea for CLI
# From repo A's worktree: create and wire a worktree in repo B
wt pair web # new worktree off main
wt pair web --base feat/new-ui # off a specific branch
wt pair web --wire feat/existing # wire to existing worktree, no creation
wt pair web --remove # cleanup paired worktree
Rough idea for config
Something in wt.toml that declares partner repos and what env vars to resolve across the port registries. Maybe:
[pair.web]
repo_path = "~/Projects/web"
serve_cmd = "npx next dev -p ${partner.ports.web}"
[pair.web.partner_env]
# Written to the partner's .env, resolved from this worktree's registry
NEXT_PUBLIC_API_URL = "http://localhost:${self.ports.web}"
# In the web repo's wt.toml
[pair.backend]
repo_path = "~/Projects/backend"
serve_cmd = "make serve"
[pair.backend.self_env]
# Written to THIS repo's .env, resolved from the partner's registry
NEXT_PUBLIC_API_URL = "http://localhost:${partner.ports.web}"
NEXTAUTH_URL = "http://localhost:${self.ports.web}"
The key design insight from our implementation: each side should declare what it needs, not what it provides. The side that needs env vars owns the declaration, and the partner's port registry is just a data source. This avoids duplication and keeps each repo's config self-contained.
Things that would need to work
- Port resolution across registries:
${self.ports.*}and${partner.ports.*}tokens that resolve from the respective worktree's registry JSON - Both
.envand.envrc: Some tools (Next.js) read.env, others (direnv) read.envrc. Ideally both get written. - Branch name independence: Paired worktrees shouldn't require matching branch names
- Serve process management: Starting/stopping the partner's dev server, with the port from the registry
- Cleanup:
--removeshould handle killing serve processes and removing the worktree
What we're not sure about
- Whether this should be
wt pair(a first-class command) or something more generic like a hook phase that runs after cross-repo worktree creation - How to handle repos that don't use worktrunk — our frontend has minimal
wt.toml(justnpm ci) but needed a port registry added for this to work - Whether the config belongs in
wt.tomlor a separate file (our bash implementation uses.config/pair/<partner>.sh)
Happy to share our full bash implementation and the gotchas we hit if that's useful context for design.
Thanks for the detailed write-up and the thoughtful design ideas! The use cases are clear and the "each side declares what it needs" insight is a good one.
I searched the codebase and this functionality doesn't exist today. The closest building blocks are:
hash_portfilter — deterministic port allocation per branch, but scoped to a single repo with no cross-repo registry- Hooks (
pre-start,post-start) — can write.envfiles, but only within the current worktree list.url— dev server URL display with health checks, single-repo only
The most related open issue is #980 (multi-repo workflows: repo picker + global worktree switch/list), which tackles the broader "worktrunk across multiple repos" problem from a different angle — navigating and listing worktrees globally rather than wiring services together. Your request is complementary: #980 is about discovery/navigation, this is about runtime coordination.
I'll leave it for a maintainer to evaluate and prioritize. The bash implementation you mentioned could be valuable context if you're willing to share it on this thread.
please consolidate to #980
Sounds good — consolidating to #980. @bfranks-orbit, feel free to add your use cases and bash implementation details there so they're captured in the broader multi-repo discussion.