#!/usr/bin/env bash # Launch a Claude Code Remote Control server for one project dir. # Invoked by claude-rc@.service; arg is the project path. set -euo pipefail dir="${1:?usage: claude-rc-run }" if [ ! -d "$dir" ]; then echo "claude-rc-run: no such directory: $dir" >&2 exit 78 # EX_CONFIG - systemd won't spin on Restart=on-failure fi # --spawn worktree needs a git repo; fall back to same-dir if not one spawn=worktree git -C "$dir" rev-parse --git-dir >/dev/null 2>&1 || { echo "claude-rc-run: $dir is not a git repo, using --spawn same-dir" >&2 spawn=same-dir } # Optional display name: a projects-file line may read # /path/to/repo | My Display Name # Falls back to the bare directory name. LIST="${CLAUDE_RC_LIST:-$HOME/.config/claude-rc/projects}" name=$(awk -F'|' -v t="$dir" ' { line=$0; sub(/#.*/,"",line) p=line; if (index(line,"|")) { p=substr(line,1,index(line,"|")-1) } gsub(/^[[:space:]]+|[[:space:]]+$/,"",p); sub(/\/+$/,"",p) if (p == t && index(line,"|")) { n=substr(line,index(line,"|")+1) gsub(/^[[:space:]]+|[[:space:]]+$/,"",n) if (n != "") { print n; exit } } }' "$LIST" 2>/dev/null || true) [ -n "$name" ] || name="$(basename "$dir")" cd "$dir" exec claude remote-control \ --spawn "$spawn" \ --permission-mode bypassPermissions \ --name "$name"