Skip to content

Commit 2e32d84

Browse files
lroolleclaude
andcommitted
fix: argument parsing infinite loop and duplicate handling in claude-yolo
- Fix missing shift statements for --inspect and --ps causing infinite loops - Remove duplicate argument handling between parse_args() and main case statement - Add exit 0 for --ps to prevent incorrect continuation to claude.sh - Fix claude-trace --run-with syntax (remove unnecessary "claude" argument) - Consolidate all argument parsing through single parse_args() function Closes #8 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 8dada53 commit 2e32d84

4 files changed

Lines changed: 69 additions & 29 deletions

File tree

DEV-LOGS.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,47 @@
55

66
## Issue Analysis: 2025-06-22
77

8+
### [bug-critical] Argument parsing infinite loop in claude-yolo
9+
10+
**Problem**: Cursor bot detected critical bugs in claude-yolo argument parsing.
11+
12+
**Root Cause Analysis**:
13+
14+
**Bug 1 - Infinite Loop**: Lines 84-89 in parse_args() missing `shift` statements:
15+
```bash
16+
--inspect)
17+
inspect_container # ❌ Missing shift - infinite loop
18+
;;
19+
--ps)
20+
list_containers # ❌ Missing shift - infinite loop
21+
;;
22+
```
23+
24+
**Bug 2 - Duplicate Handling**: Lines 122-137 duplicate parse_args() logic:
25+
```bash
26+
# Main script also handles --inspect/--ps directly
27+
case "$1" in
28+
--inspect) inspect_container ;; # ❌ Duplicate of parse_args
29+
--ps) list_containers ;; # ❌ Duplicate + no exit
30+
```
31+
32+
**Impact**:
33+
- Infinite loop when using `--inspect` or `--ps`
34+
- `--ps` shows containers but continues to exec claude.sh
35+
- Mixed options like `claude-yolo --inspect -v ~/foo:/bar` silently ignore -v
36+
- Inconsistent behavior between direct calls and mixed arguments
37+
38+
**Technical Details**:
39+
- **Flow Issue**: parse_args() calls inspect_container() → exits, but missing shift causes loop
40+
- **Design Flaw**: Two separate parsing paths with different behaviors
41+
- **Silent Failures**: Some argument combinations work, others don't
42+
43+
**Status**: Critical - requires immediate fix
44+
45+
---
46+
47+
## Issue Analysis: 2025-06-22
48+
849
### [problem-discovered] GitHub CLI auth fails in containers
950
1051
**Problem**: Mounting `~/.config/gh/` doesn't work for GitHub CLI authentication in containers.

claude-yolo

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,12 @@ parse_args() {
8383
;;
8484
--inspect)
8585
inspect_container
86+
# inspect_container calls exec, but add shift for safety
87+
shift
8688
;;
8789
--ps)
8890
list_containers
91+
exit 0
8992
;;
9093
--help | -h)
9194
echo "Claude YOLO - Container Shortcuts"
@@ -119,19 +122,5 @@ parse_args() {
119122
exec "$CLAUDE_SH" --yolo "${claude_args[@]}"
120123
}
121124

122-
# Handle special shortcuts first
123-
case "$1" in
124-
--inspect)
125-
inspect_container
126-
;;
127-
--ps)
128-
list_containers
129-
;;
130-
--help | -h)
131-
# Will be handled by parse_args
132-
parse_args "$@"
133-
;;
134-
*)
135-
parse_args "$@"
136-
;;
137-
esac
125+
# All argument parsing handled by parse_args
126+
parse_args "$@"

claude.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ if [ "$OPEN_SHELL" = true ]; then
645645
DOCKER_ARGS+=("/bin/zsh")
646646
elif [ "$USE_TRACE" = true ]; then
647647
echo "Using claude-trace for logging"
648-
DOCKER_ARGS+=("claude-trace" "--include-all-requests" "--run-with" "claude" "${CLAUDE_ARGS[@]}")
648+
DOCKER_ARGS+=("claude-trace" "--include-all-requests" "--run-with" "${CLAUDE_ARGS[@]}")
649649
else
650650
DOCKER_ARGS+=("claude" "${CLAUDE_ARGS[@]}")
651651
fi

docker-entrypoint.sh

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -224,19 +224,24 @@ main() {
224224
build_gosu_env_cmd "$CLAUDE_USER" "$cmd" "$@" --dangerously-skip-permissions
225225
elif [ "$cmd" = "claude-trace" ]; then
226226
echo "Executing Claude-trace as $CLAUDE_USER with YOLO powers: $cmd $@"
227-
# claude-trace --include-all-requests --run-with claude [args]
228-
# We need to inject --dangerously-skip-permissions into the claude command
227+
# claude-trace --include-all-requests --run-with [args]
228+
# We need to inject --dangerously-skip-permissions into the claude arguments
229229
args=("$@")
230230
new_args=()
231231
i=0
232+
inject_next=false
232233
while [ $i -lt ${#args[@]} ]; do
233-
if [ "${args[$i]}" = "--run-with" ] && [ $((i + 1)) -lt ${#args[@]} ] && [ "${args[$((i + 1))]}" = "claude" ]; then
234-
new_args+=("--run-with" "claude" "--dangerously-skip-permissions")
235-
i=$((i + 2))
234+
if [ "${args[$i]}" = "--run-with" ]; then
235+
new_args+=("--run-with")
236+
inject_next=true
237+
elif [ "$inject_next" = true ]; then
238+
# First argument after --run-with gets --dangerously-skip-permissions added
239+
new_args+=("${args[$i]}" "--dangerously-skip-permissions")
240+
inject_next=false
236241
else
237242
new_args+=("${args[$i]}")
238-
i=$((i + 1))
239243
fi
244+
i=$((i + 1))
240245
done
241246
build_gosu_env_cmd "$CLAUDE_USER" "$cmd" "${new_args[@]}"
242247
else
@@ -255,19 +260,24 @@ main() {
255260
exec "$@" --dangerously-skip-permissions
256261
elif [ "$cmd" = "claude-trace" ]; then
257262
echo "Executing Claude-trace in root mode with YOLO powers: $@"
258-
# claude-trace --include-all-requests --run-with claude [args]
259-
# We need to inject --dangerously-skip-permissions into the claude command
263+
# claude-trace --include-all-requests --run-with [args]
264+
# We need to inject --dangerously-skip-permissions into the claude arguments
260265
args=("$@")
261266
new_args=()
262267
i=1 # Skip first arg (claude-trace)
268+
inject_next=false
263269
while [ $i -lt ${#args[@]} ]; do
264-
if [ "${args[$i]}" = "--run-with" ] && [ $((i + 1)) -lt ${#args[@]} ] && [ "${args[$((i + 1))]}" = "claude" ]; then
265-
new_args+=("--run-with" "claude" "--dangerously-skip-permissions")
266-
i=$((i + 2))
270+
if [ "${args[$i]}" = "--run-with" ]; then
271+
new_args+=("--run-with")
272+
inject_next=true
273+
elif [ "$inject_next" = true ]; then
274+
# First argument after --run-with gets --dangerously-skip-permissions added
275+
new_args+=("${args[$i]}" "--dangerously-skip-permissions")
276+
inject_next=false
267277
else
268278
new_args+=("${args[$i]}")
269-
i=$((i + 1))
270279
fi
280+
i=$((i + 1))
271281
done
272282
exec "$cmd" "${new_args[@]}"
273283
else

0 commit comments

Comments
 (0)