Skip to content

Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows

docs(hooks): add -sTCP:LISTEN to lsof in hook examples (#952)

Andoni Alonso3950dc2e305c
diff --git a/.claude-plugin/skills/worktrunk/reference/hook.md b/.claude-plugin/skills/worktrunk/reference/hook.md
index 283a94153..65089abd4 100644
--- a/.claude-plugin/skills/worktrunk/reference/hook.md
+++ b/.claude-plugin/skills/worktrunk/reference/hook.md
@@ -94,7 +94,7 @@ Cleanup tasks after worktree removal: stopping dev servers, removing containers,
```toml
[post-remove]
-kill-server = "lsof -ti :{{ branch | hash_port }} | xargs kill 2>/dev/null || true"
+kill-server = "lsof -ti :{{ branch | hash_port }} -sTCP:LISTEN | xargs kill 2>/dev/null || true"
remove-db = "docker stop {{ repo }}-{{ branch | sanitize }}-postgres 2>/dev/null || true"
```
@@ -309,7 +309,7 @@ Run a dev server per worktree on a deterministic port using `hash_port`:
server = "npm run dev -- --port {{ branch | hash_port }}"
[post-remove]
-server = "lsof -ti :{{ branch | hash_port }} | xargs kill 2>/dev/null || true"
+server = "lsof -ti :{{ branch | hash_port }} -sTCP:LISTEN | xargs kill 2>/dev/null || true"
```
The port is stable across machines and restarts — `feature-api` always gets the same port. Show it in `wt list`:
diff --git a/.claude-plugin/skills/worktrunk/reference/tips-patterns.md b/.claude-plugin/skills/worktrunk/reference/tips-patterns.md
index 2af95aa99..0f93ca74d 100644
--- a/.claude-plugin/skills/worktrunk/reference/tips-patterns.md
+++ b/.claude-plugin/skills/worktrunk/reference/tips-patterns.md
@@ -38,7 +38,7 @@ server = "npm run dev -- --port {{ branch | hash_port }}"
url = "http://localhost:{{ branch | hash_port }}"
[pre-remove]
-server = "lsof -ti :{{ branch | hash_port }} | xargs kill 2>/dev/null || true"
+server = "lsof -ti :{{ branch | hash_port }} -sTCP:LISTEN | xargs kill 2>/dev/null || true"
```
The URL column in `wt list` shows each worktree's dev server:
diff --git a/.config/wt.toml b/.config/wt.toml
index a921c7bf4..002f8073c 100644
--- a/.config/wt.toml
+++ b/.config/wt.toml
@@ -19,4 +19,4 @@ doc = "RUSTDOCFLAGS='-Dwarnings' cargo doc --no-deps"
url = "http://127.0.0.1:{{ branch | hash_port }}"
[post-remove]
-docs = "lsof -ti :{{ branch | hash_port }} | xargs kill 2>/dev/null || true"
+docs = "lsof -ti :{{ branch | hash_port }} -sTCP:LISTEN | xargs kill 2>/dev/null || true"
diff --git a/docs/content/hook.md b/docs/content/hook.md
index e2787af73..695898afd 100644
--- a/docs/content/hook.md
+++ b/docs/content/hook.md
@@ -102,7 +102,7 @@ Cleanup tasks after worktree removal: stopping dev servers, removing containers,
```toml
[post-remove]
-kill-server = "lsof -ti :{{ branch | hash_port }} | xargs kill 2>/dev/null || true"
+kill-server = "lsof -ti :{{ branch | hash_port }} -sTCP:LISTEN | xargs kill 2>/dev/null || true"
remove-db = "docker stop {{ repo }}-{{ branch | sanitize }}-postgres 2>/dev/null || true"
```
@@ -317,7 +317,7 @@ Run a dev server per worktree on a deterministic port using `hash_port`:
server = "npm run dev -- --port {{ branch | hash_port }}"
[post-remove]
-server = "lsof -ti :{{ branch | hash_port }} | xargs kill 2>/dev/null || true"
+server = "lsof -ti :{{ branch | hash_port }} -sTCP:LISTEN | xargs kill 2>/dev/null || true"
```
The port is stable across machines and restarts — `feature-api` always gets the same port. Show it in `wt list`:
diff --git a/docs/content/tips-patterns.md b/docs/content/tips-patterns.md
index b0cb20b85..871fce795 100644
--- a/docs/content/tips-patterns.md
+++ b/docs/content/tips-patterns.md
@@ -44,7 +44,7 @@ server = "npm run dev -- --port {{ branch | hash_port }}"
url = "http://localhost:{{ branch | hash_port }}"
[pre-remove]
-server = "lsof -ti :{{ branch | hash_port }} | xargs kill 2>/dev/null || true"
+server = "lsof -ti :{{ branch | hash_port }} -sTCP:LISTEN | xargs kill 2>/dev/null || true"
```
The URL column in `wt list` shows each worktree's dev server:
diff --git a/src/cli/mod.rs b/src/cli/mod.rs
index 9b4db7646..e451d50be 100644
--- a/src/cli/mod.rs
+++ b/src/cli/mod.rs
@@ -1129,7 +1129,7 @@ Cleanup tasks after worktree removal: stopping dev servers, removing containers,
```toml
[post-remove]
-kill-server = "lsof -ti :{{ branch | hash_port }} | xargs kill 2>/dev/null || true"
+kill-server = "lsof -ti :{{ branch | hash_port }} -sTCP:LISTEN | xargs kill 2>/dev/null || true"
remove-db = "docker stop {{ repo }}-{{ branch | sanitize }}-postgres 2>/dev/null || true"
```
@@ -1344,7 +1344,7 @@ Run a dev server per worktree on a deterministic port using `hash_port`:
server = "npm run dev -- --port {{ branch | hash_port }}"
[post-remove]
-server = "lsof -ti :{{ branch | hash_port }} | xargs kill 2>/dev/null || true"
+server = "lsof -ti :{{ branch | hash_port }} -sTCP:LISTEN | xargs kill 2>/dev/null || true"
```
The port is stable across machines and restarts — `feature-api` always gets the same port. Show it in `wt list`: