From e18b09ffa6523ffbb45884e4cb18225dd0963690 Mon Sep 17 00:00:00 2001 From: Zack Spellman Date: Fri, 27 Feb 2026 22:03:33 -0800 Subject: [PATCH] Add -- passthrough args to cmux new and cmux start Allows passing arbitrary flags to the claude invocation by placing them after a -- separator, e.g.: cmux start my-branch -- --dangerously-skip-permissions cmux new my-branch -p "do the thing" -- --dangerously-skip-permissions Co-Authored-By: Claude Sonnet 4.6 --- cmux.sh | 62 +++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 40 insertions(+), 22 deletions(-) diff --git a/cmux.sh b/cmux.sh index ef658cc..52559a8 100644 --- a/cmux.sh +++ b/cmux.sh @@ -4,8 +4,8 @@ # Each agent gets its own worktree — no conflicts, one command each. # # Commands: -# cmux new [-p ] — New worktree + branch, run setup hook, launch Claude -# cmux start [-p ] — Continue where you left off in an existing worktree +# cmux new [-p ] [-- ] — New worktree + branch, run setup hook, launch Claude +# cmux start [-p ] [-- ] — Continue where you left off in an existing worktree # cmux cd [branch] — cd into worktree (no args = repo root) # cmux ls — List worktrees # cmux merge [branch] — Merge worktree branch into primary checkout @@ -40,8 +40,8 @@ cmux() { --help|-h|"") echo "Usage: cmux [branch]" echo "" - echo " new [-p ] New worktree + branch, run setup hook, launch Claude" - echo " start [-p ] Continue where you left off in an existing worktree" + echo " new [-p ] [-- ] New worktree + branch, run setup hook, launch Claude" + echo " start [-p ] [-- ] Continue where you left off in an existing worktree" echo " cd [branch] cd into worktree (no args = repo root)" echo " ls List worktrees" echo " merge [branch] Merge worktree branch into primary checkout" @@ -232,29 +232,38 @@ _cmux_check_update() { _cmux_new() { if [[ "$1" == "--help" || "$1" == "-h" ]]; then - echo "Usage: cmux new [-p ]" + echo "Usage: cmux new [-p ] [-- ]" echo "" echo " Create a new worktree and branch, run setup hook, and launch Claude Code." echo " Use -p to pass an initial prompt to Claude." + echo " Use -- to pass additional arguments directly to the claude invocation." + echo " Example: cmux new my-branch -- --dangerously-skip-permissions" return 0 fi if [[ -z "$1" ]]; then - echo "Usage: cmux new [-p ]" + echo "Usage: cmux new [-p ] [-- ]" return 1 fi local prompt="" + local claude_args=() local branch_words=() + local found_dashdash=false while [[ $# -gt 0 ]]; do - case "$1" in - -p) prompt="$2"; shift 2 ;; - *) branch_words+=("$1"); shift ;; - esac + if [[ "$found_dashdash" == true ]]; then + claude_args+=("$1"); shift + else + case "$1" in + --) found_dashdash=true; shift ;; + -p) prompt="$2"; shift 2 ;; + *) branch_words+=("$1"); shift ;; + esac + fi done local branch="${branch_words[*]// /-}" if [[ -z "$branch" ]]; then - echo "Usage: cmux new [-p ]" + echo "Usage: cmux new [-p ] [-- ]" return 1 fi local repo_root @@ -303,36 +312,45 @@ _cmux_new() { echo "Worktree ready: $worktree_dir" if [[ -n "$prompt" ]]; then - claude "$prompt" + claude "${claude_args[@]}" "$prompt" else - claude + claude "${claude_args[@]}" fi } _cmux_start() { if [[ "$1" == "--help" || "$1" == "-h" ]]; then - echo "Usage: cmux start [-p ]" + echo "Usage: cmux start [-p ] [-- ]" echo "" echo " Resume work in an existing worktree by launching Claude Code with --continue." echo " Use -p to pass an initial prompt to Claude." + echo " Use -- to pass additional arguments directly to the claude invocation." + echo " Example: cmux start my-branch -- --dangerously-skip-permissions" return 0 fi if [[ -z "$1" ]]; then - echo "Usage: cmux start [-p ]" + echo "Usage: cmux start [-p ] [-- ]" return 1 fi local prompt="" + local claude_args=() local branch="" + local found_dashdash=false while [[ $# -gt 0 ]]; do - case "$1" in - -p) prompt="$2"; shift 2 ;; - *) branch="$1"; shift ;; - esac + if [[ "$found_dashdash" == true ]]; then + claude_args+=("$1"); shift + else + case "$1" in + --) found_dashdash=true; shift ;; + -p) prompt="$2"; shift 2 ;; + *) branch="$1"; shift ;; + esac + fi done if [[ -z "$branch" ]]; then - echo "Usage: cmux start [-p ]" + echo "Usage: cmux start [-p ] [-- ]" return 1 fi local repo_root @@ -349,9 +367,9 @@ _cmux_start() { cd "$worktree_dir" if [[ -n "$prompt" ]]; then - claude -c "$prompt" + claude -c "${claude_args[@]}" "$prompt" else - claude -c + claude -c "${claude_args[@]}" fi }