worktrunk's hook docs are great — the pre-start + {{ branch | hash_port }} → .env.local example is a clean per-worktree port setup.
Running several agent worktrees at once, I hit two limits with the stateless approach: hash_port can collide across branches (there's no record of what's already taken), and I also wanted each worktree to get its own Postgres database + COMPOSE_PROJECT_NAME, so multiple docker compose ups don't clash.
I built a small single-binary tool for that layer — workz — that slots straight into a pre-start hook:
# .config/wt.toml
pre-start = "workz sync --isolated --quiet"
It allocates a collision-free port range from a small registry (not a hash), plus DB_NAME / COMPOSE_PROJECT_NAME / a DATABASE_URL derived from your existing one, merged idempotently into .env.local alongside any existing secrets.
Two questions:
- Would you be open to a one-line "see also" in
hook.md for people who need managed port/DB/compose isolation? Totally fine to keep the docs tool-agnostic — happy to just leave this here for anyone who searches.
- Is registry-backed (vs. stateless-hash) port allocation ever something worktrunk would want natively? If so I'm glad to share notes on the aligned-range + collision-check approach.
Either way, thanks for worktrunk — the hook design is a nice thing to build on.
worktrunk's hook docs are great — the
pre-start+{{ branch | hash_port }}→.env.localexample is a clean per-worktree port setup.Running several agent worktrees at once, I hit two limits with the stateless approach:
hash_portcan collide across branches (there's no record of what's already taken), and I also wanted each worktree to get its own Postgres database +COMPOSE_PROJECT_NAME, so multipledocker compose ups don't clash.I built a small single-binary tool for that layer — workz — that slots straight into a
pre-starthook:It allocates a collision-free port range from a small registry (not a hash), plus
DB_NAME/COMPOSE_PROJECT_NAME/ aDATABASE_URLderived from your existing one, merged idempotently into.env.localalongside any existing secrets.Two questions:
hook.mdfor people who need managed port/DB/compose isolation? Totally fine to keep the docs tool-agnostic — happy to just leave this here for anyone who searches.Either way, thanks for worktrunk — the hook design is a nice thing to build on.