Skip to content

Commit d951f8c

Browse files
Grok Buildclaude
andcommitted
feat: delegate -w to gemini and qwen native worktree support
The Gemini CLI (>=0.45) and Qwen Code (>=0.17) both gained a native `--worktree` flag that creates and manages an isolated git worktree for the session, just like claude/grok/droid already do. Detected by updating the installed CLIs and re-checking their --help. When `yolo -w gemini` / `yolo -w qwen` is requested, delegate worktree management to the tool instead of creating a `.yolo/` worktree: - gemini: appends `--worktree` (auto-generates a name) - qwen: appends `--worktree` (worktree under <repoRoot>/.qwen/worktrees/) The flag is appended bare and last (after the `-i` prompt) so each tool auto-generates the worktree name without consuming a following token. As with the other native-delegation agents, yolo's -c/--clean and -nc/--no-clean flags don't apply (the tool owns the lifecycle), and this applies to single-agent runs only — multi-agent mode still uses yolo's own per-agent worktrees for pane/cleanup orchestration. Updates help text, README, and adds delegation tests for both agents. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: Lars Trieloff <lars@trieloff.net>
1 parent ad41d78 commit d951f8c

3 files changed

Lines changed: 156 additions & 13 deletions

File tree

README.md

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,30 @@ yolo -w -nc claude "keep this work"
193193
- With `-nc/--no-clean`: Preserves worktree without prompting
194194
- Without flags: Prompts user whether to clean up
195195

196+
#### Native Worktree Delegation
197+
198+
Some agents create and manage git worktrees themselves. For these, `yolo -w`
199+
**delegates** to the tool's own worktree support instead of creating a `.yolo/`
200+
worktree — the tool handles creation, naming, and cleanup, so yolo's
201+
`-c/--clean` and `-nc/--no-clean` flags don't apply:
202+
203+
| Agent | Native flag | Worktree location |
204+
|-------|-------------|-------------------|
205+
| `claude` | `--worktree` | `.claude/worktrees/` |
206+
| `grok` | `-w` / `--worktree` | managed by grok |
207+
| `droid` | `-w` / `--worktree` | managed by droid |
208+
| `gemini` | `--worktree` | managed by gemini |
209+
| `qwen` | `--worktree` | `<repoRoot>/.qwen/worktrees/` |
210+
211+
```bash
212+
yolo -w gemini "implement feature" # gemini manages its own worktree
213+
yolo -w qwen "refactor the parser" # qwen creates .qwen/worktrees/<slug>/
214+
```
215+
216+
> **Note:** In multi-agent mode (comma-separated agents), yolo always creates
217+
> its own `.yolo/` worktree per agent so it can orchestrate panes and cleanup —
218+
> native delegation applies to single-agent runs only.
219+
196220
### Cleanup Mode
197221

198222
Clean up all YOLO worktrees, branches, and processes at once:
@@ -229,9 +253,9 @@ Use `--mop` to clean up orphaned worktrees from interrupted sessions or when you
229253
| `amp` | `--dangerously-allow-all` |
230254
| `aider` | `--yes-always` |
231255
| `cursor-agent` | `--force` |
232-
| `gemini` | `--yolo` (+ `-i` when prompt present) |
256+
| `gemini` | `--yolo` (+ `-i` when prompt present; `-w` delegates to gemini's native `--worktree`) |
233257
| `opencode` | *(no flags)* |
234-
| `qwen` | `--yolo` (+ `-i` when prompt present) |
258+
| `qwen` | `--yolo` (+ `-i` when prompt present; `-w` delegates to qwen's native `--worktree`) |
235259
| `kimi` | `--yolo` (+ `--command` when prompt present) |
236260
| `crush` | `--yolo` (+ Ghostty injection when prompt present) |
237261
| `goose` | *(no flags - prompts passed via stdin)* |

executable_yolo

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,11 @@ Usage: yolo [OPTIONS] [command] [args...]
8585
8686
Options:
8787
-w, --worktree Create a git worktree in .yolo/ before running command
88-
(exceptions: 'claude', 'grok', and 'droid' delegate to their
89-
built-in worktree support: claude uses .claude/worktrees/,
90-
grok uses its native -w/--worktree mode, droid uses its
91-
native -w/--worktree mode)
88+
(exceptions: 'claude', 'grok', 'droid', 'gemini', and 'qwen'
89+
delegate to their built-in worktree support: claude uses
90+
.claude/worktrees/, grok and droid use their native
91+
-w/--worktree mode, gemini and qwen use their native
92+
--worktree mode (qwen under .qwen/worktrees/))
9293
-c, --clean Automatically clean up worktree after command completes
9394
-nc, --no-clean Preserve worktree after command completes (no prompt)
9495
-e, --editor Launch \$EDITOR to compose prompt (works in all modes)
@@ -106,8 +107,10 @@ Supported Commands:
106107
droid No extra flags added (prompt allowed positionally)
107108
amp Adds --dangerously-allow-all
108109
cursor-agent Adds --force
109-
gemini Uses --yolo; adds -i when prompt present
110-
qwen Uses --yolo; adds -i when prompt present
110+
gemini Uses --yolo; adds -i when prompt present; -w delegates to
111+
gemini's native --worktree
112+
qwen Uses --yolo; adds -i when prompt present; -w delegates to
113+
qwen's native --worktree
111114
kimi Uses --yolo (requires Ghostty for interactive prompts)
112115
opencode No extra flags added
113116
crush Uses --yolo (requires Ghostty for interactive prompts)
@@ -147,23 +150,28 @@ Examples:
147150
yolo -w -nc claude "keep this" # Use claude's built-in --worktree (claude manages it)
148151
yolo -w grok "implement feature" # Use grok's native -w/--worktree (grok manages it)
149152
yolo -w droid "implement feature" # Use droid's native -w/--worktree (droid manages it)
153+
yolo -w gemini "implement feature" # Use gemini's native --worktree (gemini manages it)
154+
yolo -w qwen "implement feature" # Use qwen's native --worktree (qwen manages it)
150155
yolo -e codex,claude,gemini # Compose prompt in editor, run 3 agents in parallel
151156
yolo copilot chat # Run copilot chat with safety flags disabled
152157
yolo aider "add auth" # Run aider with auto-approval
153158
yolo -w aider "implement feature" # Create worktree, run aider with prompt
154159
155160
Worktree Mode:
156-
When using -w/--worktree flag (for commands other than claude, grok, or droid):
161+
When using -w/--worktree flag (for commands other than claude, grok, droid,
162+
gemini, or qwen):
157163
- Creates .yolo/ directory in repository root
158164
- Creates branch: <command>-N (where N is the lowest available number)
159165
- Creates worktree: .yolo/<command>-N
160166
- Changes to worktree directory before running command
161167
162-
When using -w/--worktree flag with 'claude', 'grok', or 'droid':
168+
When using -w/--worktree flag with 'claude', 'grok', 'droid', 'gemini', or 'qwen':
163169
- Delegates worktree management to the tool's native support
164170
- claude: uses --worktree (managed under .claude/worktrees/)
165171
- grok: uses -w/--worktree (managed by grok's native worktree system)
166172
- droid: uses -w/--worktree (managed by droid's native worktree system)
173+
- gemini: uses --worktree (managed by gemini's native worktree system)
174+
- qwen: uses --worktree (managed under <repoRoot>/.qwen/worktrees/)
167175
- The tool handles worktree creation, naming, and cleanup
168176
- yolo's -c/--clean and -nc/--no-clean flags are ignored in this mode
169177
@@ -1592,11 +1600,12 @@ main() {
15921600
fi
15931601

15941602
# Track whether yolo is managing the worktree itself
1595-
# claude, grok, and droid have built-in --worktree / -w support, so we
1596-
# delegate to them rather than creating our own worktree under .yolo/
1603+
# claude, grok, droid, gemini, and qwen have built-in --worktree / -w
1604+
# support, so we delegate to them rather than creating our own worktree
1605+
# under .yolo/
15971606
local yolo_managed_worktree=false
15981607
if [[ "$use_worktree" == "true" ]]; then
1599-
if [[ "$command_name" == "claude" || "$command_name" == "grok" || "$command_name" == "droid" ]]; then
1608+
if [[ "$command_name" == "claude" || "$command_name" == "grok" || "$command_name" == "droid" || "$command_name" == "gemini" || "$command_name" == "qwen" ]]; then
16001609
print_info "Delegating worktree management to $command_name's built-in worktree support"
16011610
# These tools handle their own worktree lifecycle, so yolo's -c/-nc
16021611
# cleanup flags do not apply in this mode.
@@ -1701,6 +1710,16 @@ main() {
17011710
prompt_joined=$(printf '%s ' "${command_args[@]}"); prompt_joined=${prompt_joined%% }
17021711
full_command+=("-i" "$prompt_joined")
17031712
fi
1713+
# gemini and qwen have native git worktree support; delegate to it
1714+
# when -w is requested rather than creating one with yolo's own logic.
1715+
# gemini: --worktree [name] (worktree under git's worktree dir)
1716+
# qwen: --worktree [slug] (worktree under <repoRoot>/.qwen/worktrees/)
1717+
# The flag takes an optional name/slug; appending it bare and last
1718+
# (after the -i prompt) lets each tool auto-generate the name without
1719+
# consuming a following token as that name.
1720+
if [[ "$use_worktree" == "true" ]]; then
1721+
full_command+=("--worktree")
1722+
fi
17041723
;;
17051724
droid)
17061725
# droid has native -w/--worktree support; delegate to it when requested

test.sh

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,104 @@ EOF
608608
rm -f "$droid_cmd"
609609
}
610610

611+
# Shared assertions for agents that delegate to a native --worktree and pass
612+
# their prompt via -i (gemini, qwen). For these, yolo appends --worktree LAST
613+
# (after the -i prompt) and must not create its own .yolo/ worktree.
614+
_assert_native_worktree_via_i() {
615+
local agent="$1"
616+
617+
# Create a temporary git repository for testing
618+
local test_repo="/tmp/yolo_test_${agent}_$$"
619+
mkdir -p "$test_repo"
620+
cd "$test_repo"
621+
622+
# Initialize git repo
623+
git init -q
624+
git config user.email "test@example.com"
625+
git config user.name "Test User"
626+
echo "test" > README.md
627+
git add README.md
628+
git commit -q -m "Initial commit"
629+
630+
# Create a dummy agent command that echoes args (so we can assert pass-through)
631+
local agent_cmd="/tmp/$agent"
632+
cat > "$agent_cmd" << 'EOF'
633+
#!/bin/bash
634+
echo "Running in: $PWD"
635+
echo "Args: $@"
636+
EOF
637+
chmod +x "$agent_cmd"
638+
639+
# Assertion 1: --worktree is passed through when -w is set
640+
run_test
641+
local output
642+
if output=$(PATH="/tmp:$PATH" run_with_timeout "$YOLO_TEST_TIMEOUT" "$YOLO_CMD" -w "$agent" "fix the bug" 2>&1); then
643+
if echo "$output" | grep -F -q -- "--worktree"; then
644+
print_pass "yolo -w $agent passes through --worktree flag"
645+
else
646+
print_fail "yolo -w $agent should pass --worktree (got: $output)"
647+
fi
648+
else
649+
print_fail "yolo -w $agent failed to run"
650+
fi
651+
652+
# Assertion 2: --worktree is appended after the -i prompt (bare, last) so the
653+
# tool auto-generates the worktree name instead of eating the prompt
654+
run_test
655+
if echo "$output" | grep -F -q -- "-i fix the bug --worktree"; then
656+
print_pass "yolo -w $agent appends --worktree after the -i prompt"
657+
else
658+
print_fail "yolo -w $agent should append --worktree after -i prompt (got: $output)"
659+
fi
660+
661+
# Assertion 3: yolo did NOT create a .yolo/ directory
662+
run_test
663+
if [[ ! -d "$test_repo/.yolo" ]]; then
664+
print_pass "yolo -w $agent does not create .yolo/ worktree directory"
665+
else
666+
print_fail "yolo -w $agent should not create .yolo/ directory"
667+
fi
668+
669+
# Assertion 4: yolo did NOT create a git worktree
670+
run_test
671+
local wt_count
672+
wt_count=$(git worktree list | wc -l | tr -d ' ')
673+
if [[ "$wt_count" == "1" ]]; then
674+
print_pass "yolo -w $agent does not invoke git worktree add"
675+
else
676+
print_fail "yolo -w $agent should not create a git worktree (found $wt_count)"
677+
fi
678+
679+
# Assertion 5: yolo <agent> (without -w) does NOT pass --worktree
680+
run_test
681+
if output=$(PATH="/tmp:$PATH" run_with_timeout "$YOLO_TEST_TIMEOUT" "$YOLO_CMD" "$agent" "hello" 2>&1); then
682+
if ! echo "$output" | grep -F -q -- "--worktree"; then
683+
print_pass "yolo $agent (no -w) does not pass --worktree"
684+
else
685+
print_fail "yolo $agent should not pass --worktree without -w (got: $output)"
686+
fi
687+
else
688+
print_fail "yolo $agent failed to run"
689+
fi
690+
691+
# Cleanup
692+
cd /tmp
693+
rm -rf "$test_repo"
694+
rm -f "$agent_cmd"
695+
}
696+
697+
# Test 11: Test yolo -w gemini delegates to gemini's native --worktree
698+
test_gemini_builtin_worktree() {
699+
print_test_header "Test 11: Gemini Built-in Worktree Delegation"
700+
_assert_native_worktree_via_i "gemini"
701+
}
702+
703+
# Test 12: Test yolo -w qwen delegates to qwen's native --worktree
704+
test_qwen_builtin_worktree() {
705+
print_test_header "Test 12: Qwen Built-in Worktree Delegation"
706+
_assert_native_worktree_via_i "qwen"
707+
}
708+
611709
# Print summary
612710
print_summary() {
613711
echo ""
@@ -651,6 +749,8 @@ main() {
651749
test_argument_preservation
652750
test_claude_builtin_worktree
653751
test_droid_builtin_worktree
752+
test_gemini_builtin_worktree
753+
test_qwen_builtin_worktree
654754

655755
print_summary
656756
}

0 commit comments

Comments
 (0)