working-with-worktrees
Skill127 starsChanged 11 days agoMITView on GitHub
Use when creating a git worktree, running the Docker stack or tests from more than one checkout at once, or debugging port, database, or backend image conflicts between checkouts - covers per-worktree slots, the generated env file, per-worktree backend images, shared caches, the shared stash, and the commands that report and release a stack
- Reads credentials
In this repository21 other files it gives its agents.
- AGENTS.mdAGENTS.md
- docs/AGENTS.mdAGENTS.md
- .github/workflows/AGENTS.mdAGENTS.md
- nix/AGENTS.mdAGENTS.md
- proto/AGENTS.mdAGENTS.md
- sdks/AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- .github/workflows/CLAUDE.mdCLAUDE.md
- nix/CLAUDE.mdCLAUDE.md
- proto/CLAUDE.mdCLAUDE.md
- sdks/CLAUDE.mdCLAUDE.md
- authoring-specsSkill
- check-ciSkill
- checking-spec-complianceSkill
- reviewing-specsSkill
- smoke-checkSkill
- working-with-nixSkill
- writing-agent-docsSkill
- writing-rustSkill
- writing-rust-testsSkill
- writing-typescriptSkill
The file
We split this skill into the rules it gives an agent
4 rules. About 0 are common, 0 are distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 10
Every port in docs/ and AGENTS.md is a slot-0 value.
- Very specific: line 36
Never pass a port by hand: Every just recipe that needs the stack (just test, just backend *, the SDK test recipes) sources dev/docker/.env …
- Very specific: line 48
Do not share a mutable target/ directory across worktrees.
- Very specific: line 73
All 40 slots claimed: run just backend release in worktrees you are done with.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Working with worktrees in libxmtp
Each worktree gets its own Compose project, host ports, and backend image tag,
so several can run the stack at once. Never assume port 5050: that is only the main checkout.
Every port in docs/ and AGENTS.md is a slot-0 value.
Start work in a new worktree
git worktree add ../<name>/libxmtp -b <branch> origin/main
cd ../<name>/libxmtp
dev/nix-shell 'just backend up' # this worktree's own stack
dev/nix-shell 'just backend status' # project, slot, image, ports, URLsdev/worktree-env claims a slot for the checkout and writes dev/docker/.env
(gitignored). Ports are base + slot * 100. The main checkout and any plain
clone, so CI, are slot 0.
The file also sets XMTP_BACKEND_IMAGE to xmtp-backend:<project>. Every Nix
image build has the tag ghcr.io/xmtp/backend:self-hosted, so
just backend up loads the build under the worktree's tag instead
(dev/docker/load-backend-image). Compose runs that tag, so a recreated backend
never runs another worktree's build. Do not docker load the archive for the
stack by hand. To run a different image, such as a published release, set
XMTP_BACKEND_IMAGE and start with dev/docker/up. just backend up would
still build this worktree's image, but it does not load the build under that tag.
Run in parallel without conflicts
- Never pass a port by hand. Every
justrecipe that needs the stack (just test,just backend *, the SDK test recipes) sourcesdev/docker/.envfirst. A variable already set in your environment wins, so setXMTP_BACKEND_URLorDATABASE_URLonly to point at a different backend. - Read addresses from the environment in code. Rust:
xmtp_configuration::backend_test_url(),backend_test_toxic_url(),DockerUrls::anvil(); Toxiproxy:xmtp_common::toxiproxy()(the upstreamTOXIPROXYstatic hardcodes its port). Scripts and SDK tests:XMTP_BACKEND_URL,DATABASE_URL. - Share the compile cache. Each worktree has its own
target/. Rust-capable Nix shells enable Kache. They keep Cargo's local incremental defaults and cache eligible non-incremental dependencies. The local default cap is 50 GiB. Do not share a mutabletarget/directory across worktrees. Seedocs/nix-setup.mdfor cache limits and how to disable the wrapper. - The stash stack is shared across worktrees. Never bare
git stash/git stash pop; another session can pop your entry. Park work in a WIP commit instead. - Flakes see only tracked files.
git adda new file in the worktree beforenix buildorjust backend buildcan see it.
Fix a conflict
just backend up refuses to start when another project holds one of this
worktree's ports, and names both:
worktree-env: port 5150 is held by Compose project 'libxmtp-old-branch-1'.
worktree-env: this worktree is 'libxmtp-agent-efficiency-1' (slot 1). Stop the other stack, or set XMTP_WORKTREE_SLOT to a free slot.- A stack from a deleted worktree keeps running. Find it with
docker psand stop it withdocker compose -p <project> down. - A backend runs code from another checkout: compare the
image:line ofjust backend statuswith the image indocker ps, then runjust backend upagain. - A port held by a non-Compose process is an unrelated local service. Stop it
or override with
XMTP_WORKTREE_SLOT=<n>. - All 40 slots claimed: run
just backend releasein worktrees you are done with. Claims for deleted worktrees are pruned on the next run.
Finish
dev/nix-shell 'just backend release' # stop the stack, free the slot, remove the image tag
git worktree remove ../<name>/libxmtpA worktree removed without release keeps its image tag. List the tags with
docker images xmtp-backend and remove one with
docker image rm xmtp-backend:<project>.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

