rclaude: pre-flight remote dir existence; loud error instead of silent ssh-close

Catches typos and Claude-instruction-style aliases (@proj/@apps/@pkg) that
look like paths but only resolve in the assistant's mental model, not in any
shell. Without the check the cd inside the tmux command failed silently, the
pane died, the session closed, ssh exited — surfaced to the user as a bare
'Connection to <host> closed.'
This commit is contained in:
Natalie 2026-04-26 00:10:02 -07:00
parent 47434868e0
commit 77cd1c74b1

View file

@ -212,9 +212,27 @@ if is_local "$host"; then
echo "rclaude: tmux not installed locally — install via 'brew install tmux' (macOS) or your package manager" >&2
exit 1
fi
cd "$dir"
if ! cd "$dir" 2>/dev/null; then
echo "rclaude: local directory not found: $dir" >&2
exit 1
fi
exec tmux new-session -A -s "$session" "exec claude --continue ${flag}"
fi
# Remote: pre-flight the directory on the remote host so a typo or missing
# path fails loudly here instead of silently killing the tmux pane and
# closing the ssh transport (which looks like a generic "connection closed"
# error to the user).
if ! ssh -o BatchMode=yes -o ConnectTimeout=5 "$host" "test -d ${dir}" 2>/dev/null; then
echo "rclaude: directory not found on $host: $dir" >&2
case $dir in
*@proj/*|*@apps/*|*@pkg/*)
echo " hint: '@proj/@apps/@pkg' are Claude-instruction aliases, not real shell paths." >&2
echo " See ~/.claude/instructions/project-paths.md for the real ~/Code/<bucket>/<project> mapping." >&2
;;
esac
exit 1
fi
inner="cd ${dir} && exec claude --continue ${flag}"
exec ssh -t "$host" "tmux new-session -A -s '${session}' \"${inner}\""