Skip to content

Commit 0cae50c

Browse files
rubenfiszelclaude
andcommitted
feat: add --existing flag to wm add for resuming work on remote branches
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent d570881 commit 0cae50c

2 files changed

Lines changed: 52 additions & 1 deletion

File tree

bin/src/worktree-commands.test.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,20 @@ describe("parseAddCommandArgs", () => {
8989
} satisfies ParsedAddCommand);
9090
});
9191

92+
it("parses --existing flag", () => {
93+
expect(parseAddCommandArgs(["feature/search", "--existing"])).toEqual({
94+
input: { branch: "feature/search", mode: "existing" },
95+
detach: false,
96+
});
97+
});
98+
99+
it("parses --existing with other flags", () => {
100+
expect(parseAddCommandArgs(["feature/search", "--existing", "--agent", "claude", "--detach"])).toEqual({
101+
input: { branch: "feature/search", mode: "existing", agent: "claude" },
102+
detach: true,
103+
});
104+
});
105+
92106
it("parses --detach flag", () => {
93107
expect(parseAddCommandArgs(["feature/search", "--detach"])).toEqual({
94108
input: { branch: "feature/search" },
@@ -205,6 +219,37 @@ describe("runWorktreeCommand", () => {
205219
expect(switchCalls).toEqual([{ projectDir: "/repo", branch: "feature/search" }]);
206220
});
207221

222+
it("dispatches add --existing with mode existing", async () => {
223+
const { runtime, calls } = makeRuntime();
224+
const stdout: string[] = [];
225+
226+
const exitCode = await runWorktreeCommand(
227+
{
228+
command: "add",
229+
args: ["feature/remote-branch", "--existing"],
230+
projectDir: "/repo",
231+
port: 5111,
232+
},
233+
{
234+
createRuntime: () => runtime,
235+
stdout: (message) => stdout.push(message),
236+
switchToTmuxWindow: () => {},
237+
},
238+
);
239+
240+
expect(exitCode).toBe(0);
241+
expect(calls).toEqual([
242+
{
243+
method: "createWorktree",
244+
value: {
245+
branch: "feature/remote-branch",
246+
mode: "existing",
247+
},
248+
},
249+
]);
250+
expect(stdout).toEqual(["Created worktree feature/remote-branch"]);
251+
});
252+
208253
it("skips tmux switch when --detach is passed to add", async () => {
209254
const { runtime } = makeRuntime();
210255
const stdout: string[] = [];

bin/src/worktree-commands.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,10 @@ export function getWorktreeCommandUsage(command: WorktreeSubcommand): string {
7070
case "add":
7171
return [
7272
"Usage:",
73-
" webmux add [branch] [--base <branch>] [--profile <name>] [--agent <claude|codex>] [--prompt <text>] [--env KEY=VALUE] [--detach]",
73+
" webmux add [branch] [--existing] [--base <branch>] [--profile <name>] [--agent <claude|codex>] [--prompt <text>] [--env KEY=VALUE] [--detach]",
7474
"",
7575
"Options:",
76+
" --existing Use an existing local or remote branch instead of creating a new one",
7677
" --base <branch> Base branch for a new worktree (defaults to config)",
7778
" --profile <name> Worktree profile from .webmux.yaml",
7879
" --agent <claude|codex> Agent to launch in the worktree",
@@ -159,6 +160,11 @@ export function parseAddCommandArgs(args: string[]): ParsedAddCommand | null {
159160
return null;
160161
}
161162

163+
if (arg === "--existing") {
164+
input.mode = "existing";
165+
continue;
166+
}
167+
162168
if (arg === "--detach" || arg === "-d") {
163169
detach = true;
164170
continue;

0 commit comments

Comments
 (0)