Skip to content
Back to skills

Mac Mirror

FSecurity

Mirror the current git dir/worktree/branch onto a Mac and continue the work session there instead of locally. Pushes the branch, checks it out remotely via SSH, and drops into a tmux session. Falls back to Slack if SSH is unreachable. Use when asked to move/continue work on a Mac, hand off to it, or mirror this session to Mac from Linux or elsewhere.

  • 6 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added November 26, 2026
toolsrustgoshellbashreactnodetestingdebugginggit

Works with

  • claude code
  • cursor
  • cli

Security analysis

F25/100
  • criticalAccesses sensitive system or user directories
  • criticalReads or references SSH private keys
  • criticalModifies startup scripts or system services for persistence
  • criticalModifies startup scripts or system services for persistence
  • criticalSends environment variables or credentials to an external URL

Pro shows the line behind each finding and how to fix it

Scanned November 26, 2026

npx -y skills add jleechanorg/jleechan-skills --skill mac-mirror --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Mac Mirror?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Mac Mirror
[![Security: F — Skills Directory](https://www.skillsdirectory.com/api/skills/jleechanorg-mac-mirror/badge)](https://www.skillsdirectory.com/skills/jleechanorg-mac-mirror)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: mac-mirror
description: "Mirror the current git dir/worktree/branch onto a Mac and continue the work session there instead of locally. Pushes the branch, checks it out remotely via SSH, and drops into a tmux session. Falls back to Slack if SSH is unreachable. Use when asked to move/continue work on a Mac, hand off to it, or mirror this session to Mac from Linux or elsewhere."
---

# Mac Mirror — hand this branch off to a Mac

Companion to [linux-mirror](../linux-mirror/SKILL.md) (same flow, opposite direction). Unlike a plain SSH-steering skill, this mirrors the **current repo's committed state** onto the target Mac and resumes work there in a persistent tmux session.

Before every handoff, follow
[host load balancing](../parallelize-to-ceiling/references/host-load-balancing.md)
for fresh resource checks on both hosts, host selection and task ownership; this
skill owns Mac transport and response proof. Record the measurements and
decision before starting the remote checkout or agent.

If you're already running locally on the target Mac, there's nothing to mirror — say so and stop.

If the Linux host is blocked (disk full, CPU/memory admission gate, missing
tool, host-local auth), use this skill to move the work to the Mac and keep
working there; do not stop or wait.

Follow the [lightweight caller contract](../linux-remote/SKILL.md#lightweight-caller-remote-execution-owner): the caller drives transport and verifies receipts; the target agent owns execution.

## Setup (once, per pair of machines)

This skill assumes you've already got:
- An SSH host alias for the Mac in `~/.ssh/config` (LAN), e.g.:
  ```
  Host mymac
      HostName 192.0.2.11
      User myusername
      IdentityFile ~/.ssh/id_ed25519
  ```
  (`ssh_config` does not expand environment variables — write your actual username literally, not `$USER`.)
- SSH enabled on the Mac (System Settings → General → Sharing → Remote Login), with the other machine's public key added.
- Your repo lives under `$HOME` on the source machine (any relative path). This skill resolves a writable target root with the target host's canonical `diskm scratch-dir` command, then mirrors the checkout under that Scratch root. Agent output and disposable tool files use a separate Scratch output directory. If the configured Scratch volume is unavailable, the resolver failure is fatal; do not fall back to `/tmp` or `$HOME/mirror`. A repo outside `$HOME` on the source side isn't supported — step 1 below checks for this and stops rather than silently producing a wrong path.
- (Optional, for off-LAN/travel use) Both machines joined to the same Tailscale tailnet — same caveat as linux-mirror: the bare alias won't fail over to Tailscale automatically, target the Tailscale IP + explicit `-i` when off-LAN.
- (Optional, for SSH-fully-down fallback) A messaging-gateway agent running on the Mac, watching a Slack channel (or similar) you can post to.

Substitute your own host alias / IP / key path / username everywhere `mymac` / `myusername` appears below.

## What this carries over

Only **committed and pushed** state — the current branch's HEAD. Uncommitted/staged local edits are NOT transferred; commit or stash first if you need them.

## Steps

### 1. Detect local state

```bash
REPO_ROOT=$(git rev-parse --show-toplevel)
BRANCH=$(git -C "$REPO_ROOT" branch --show-current)
REMOTE_URL=$(git -C "$REPO_ROOT" remote get-url origin)
INTENDED_SHA=$(git -C "$REPO_ROOT" rev-parse HEAD)
DIRTY=$(git -C "$REPO_ROOT" status --porcelain)

case "$REPO_ROOT" in
  "$HOME"/*) REL_PATH=${REPO_ROOT#"$HOME/"} ;;
  *) echo "ERROR: repo root ($REPO_ROOT) is not under \$HOME ($HOME) — this skill mirrors by \$HOME-relative path on both machines. Move or symlink the repo under \$HOME first." >&2; exit 1 ;;
esac
```

Also prepare `$CONTEXT`: a short, self-contained summary (1-3 sentences) of what should actually continue on the Mac — the real next action, not just "resume work." This isn't optional bookkeeping: step 4 types it as the first message to a freshly-launched coding agent on the target machine, which has no access to this conversation. Write it as if briefing a colleague who just walked in cold.

If `$CONTEXT` is empty, stop here before pushing or opening SSH. The remote launcher checks it again before validating the CLI.

Also resolve `$AGENT_CLI`: the CLI **that is calling this skill**, i.e. the operator's live runtime (Claude Code → `claude`, pi → `pi`, Codex → `codex`, Antigravity → `agy`). This skill deliberately has no default CLI — launching a CLI the operator is not using hands the work to an agent with different tools, skills, model and quota, so any substitution is stated explicitly, never a silent default. Only set a different `$AGENT_CLI` when the calling CLI is genuinely unusable on the target host (for example a quota wall), and say why. Implementation reference: the identical block in [../linux-mirror/SKILL.md](../linux-mirror/SKILL.md) step 4.

If `$BRANCH` is empty (detached HEAD) or `$DIRTY` is non-empty, stop and tell the user — commit/name the branch first.

If `$REMOTE_URL` is an HTTPS URL with an embedded credential (`https://<token>@host/...`), warn the user before continuing: that URL gets written verbatim into the remote clone's `.git/config` in step 4, so the credential ends up live on the target Mac too. Prefer an SSH remote, or a credential helper that doesn't embed the token in the URL. (Step 4's base64 encoding is not a confidentiality measure for this value — it only prevents argv re-tokenization/injection. A trivially-decodable token is still visible in the remote host's `ps` output during the mirror.)

### 2. Push the branch

```bash
if [ -n "$CONTEXT" ]; then
  git -C "$REPO_ROOT" push -u origin "$BRANCH"
else
  echo "ERROR: CONTEXT is required before pushing or opening SSH" >&2
fi
```

Confirm with the user first if the branch has no upstream yet or diverges from origin.

### 3. Pick a connectivity tier — try in order, stop at first success. Carry the resolved connection forward into `SSH_ARGS`/`SSH_TARGET` for step 4 — don't just check reachability and then reconnect a different way.

See [cross-machine-ssh-tier](../cross-machine-ssh-tier/SKILL.md) for the Tier 1→2→3 connectivity ladder (LAN SSH → SSH over Tailscale → messaging-gateway fallback), its debugging caveats, and the key-naming convention. Run that skill's ladder block with `PEER_LAN_ALIAS="mymac"` (and the matching `PEER_TS_PATTERN`/`PEER_KEY`/`PEER_USER`) to resolve `SSH_ARGS`/`SSH_TARGET` before continuing to step 4. If `$SSH_TARGET` comes back empty, both Tier 1 and Tier 2 failed — fall through to that skill's Tier 3 (messaging-gateway handoff): post the exact repo/branch/commit and the steps from §4 to a channel a reactive gateway agent on the Mac is watching, asking it to execute them locally and reply when the tmux session is ready.

### 4. Remote checkout + tmux (Tier 1/2 only — skip if `$SSH_TARGET` is empty, that means Tier 3 applies instead)

Arguments are base64-encoded before crossing the wire — `ssh host command args...` does not preserve argv separation, the remote shell re-tokenizes the command line, so an unencoded branch name with a space or shell metacharacter (`;`, `` ` ``, `$()`, `&&`, `|` — all valid in a git branch name) can misdirect arguments or execute commands on the remote host. Base64 output contains none of those characters.

```bash
REL_PATH_B64=$(printf '%s' "$REL_PATH" | base64 | tr -d '\n')
BRANCH_B64=$(printf '%s' "$BRANCH" | base64 | tr -d '\n')
REMOTE_URL_B64=$(printf '%s' "$REMOTE_URL" | base64 | tr -d '\n')
CONTEXT_B64=$(printf 'x%s' "$CONTEXT" | base64 | tr -d '\n')
AGENT_CLI_B64=$(printf '%s' "$AGENT_CLI" | base64 | tr -d '\n')
INTENDED_SHA_B64=$(printf '%s' "$INTENDED_SHA" | base64 | tr -d '\n')

ssh "${SSH_ARGS[@]}" "$SSH_TARGET" bash -s -- "$REL_PATH_B64" "$BRANCH_B64" "$REMOTE_URL_B64" "$CONTEXT_B64" "$AGENT_CLI_B64" "$INTENDED_SHA_B64" << 'EOF'
set -e
REL_PATH=$(printf '%s' "$1" | base64 -d)
BRANCH=$(printf '%s' "$2" | base64 -d)
REMOTE_URL=$(printf '%s' "$3" | base64 -d)
TARGET=""
CONTEXT_PAYLOAD=$(printf '%s' "$4" | base64 -d)
case "$CONTEXT_PAYLOAD" in
  x*) CONTEXT=${CONTEXT_PAYLOAD#x} ;;
  *) echo "FAILED:$TARGET — invalid CONTEXT payload" >&2; exit 1 ;;
esac
AGENT_CLI=$(printf '%s' "$5" | base64 -d)
INTENDED_SHA=$(printf '%s' "$6" | base64 -d)
if [[ ! "$INTENDED_SHA" =~ ^[0-9a-f]{40}$ ]]; then
  echo "FAILED:$REL_PATH — invalid intended source SHA" >&2
  exit 75
fi

if [ -z "$CONTEXT" ]; then
  echo "FAILED:$TARGET — CONTEXT is empty; refusing to start a bare shell" >&2
  exit 1
fi

# Scratch is the only mirror destination. `diskm scratch-dir` performs the
# host-specific volume, availability, and admission checks. Keep the checkout
# and the agent's generated output in separate paths. A resolver failure is
# fatal; do not fall back to HOME or /tmp.
SCRATCH_ROOT="$(diskm scratch-dir 2>/dev/null)" || {
  echo "FAILED:$REL_PATH — canonical Scratch resolver failed; refusing HOME/tmp fallback" >&2
  exit 75
}
[ -n "$SCRATCH_ROOT" ] && [ -d "$SCRATCH_ROOT" ] || {
  echo "FAILED:$REL_PATH — canonical Scratch resolver returned no usable root" >&2
  exit 75
}
[ "$SCRATCH_ROOT" != "/tmp" ] || {
  echo "FAILED:$REL_PATH — Scratch is unconfigured; refusing the canonical /tmp fallback" >&2
  exit 75
}
MIRROR_KEY=$(printf '%s' "$REL_PATH" | cksum | cut -d' ' -f1)
BRANCH_KEY=$(printf '%s' "$BRANCH" | cksum | cut -d' ' -f1)
OUTPUT_SUBPATH="mirror-output/$MIRROR_KEY/$BRANCH_KEY"
OUTPUT_ROOT="$(diskm scratch-dir "$OUTPUT_SUBPATH" 2>/dev/null)" || {
  echo "FAILED:$REL_PATH — canonical Scratch output allocation failed" >&2
  exit 75
}
# Serialize cooperative bootstraps for this repository/branch without a new
# lock file. The existing Scratch output directory is the lock inode; fd 9 is
# held through session preflight, Git mutation, and tmux creation.
exec 9<"$OUTPUT_ROOT" || {
  echo "FAILED:$REL_PATH — cannot open Scratch coordination directory" >&2
  exit 75
}
flock -n 9 || {
  echo "FAILED:$REL_PATH — another mirror bootstrap holds the Scratch lock" >&2
  exit 75
}
TARGET_SUBPATH="mirrors/$MIRROR_KEY/$BRANCH_KEY/$REL_PATH"
TARGET="$(diskm scratch-dir "$TARGET_SUBPATH" 2>/dev/null)" || {
  echo "FAILED:$REL_PATH — canonical Scratch target allocation failed" >&2
  exit 75
}

BRANCH_SAFE=$(printf '%s' "$BRANCH" | tr -c 'a-zA-Z0-9_-' '-')
BRANCH_HASH=$(printf '%s' "$BRANCH" | cksum | cut -d' ' -f1)
SESSION="mirror-${MIRROR_KEY}-${BRANCH_SAFE}-${BRANCH_HASH}"
# Check an existing session before any clone, fetch, checkout, pull, or output
# mkdir. A matching branch in another repository cannot reuse this repo-keyed
# session name; a mismatched target is a hard failure, never a RESUMED claim.
if tmux has-session -t "=$SESSION" 2>/dev/null; then
  SESSION_CWD=$(tmux display-message -p -t "=$SESSION" '#{pane_current_path}' 2>/dev/null || true)
  [ -n "$SESSION_CWD" ] || { echo "FAILED:$SESSION — cannot inspect existing session cwd" >&2; exit 75; }
  SESSION_CWD_REAL=$(cd "$SESSION_CWD" 2>/dev/null && pwd -P) || {
    echo "FAILED:$SESSION — existing session cwd is unreadable" >&2
    exit 75
  }
  TARGET_REAL=$(cd "$TARGET" 2>/dev/null && pwd -P) || {
    echo "FAILED:$SESSION — existing session target is unreadable" >&2
    exit 75
  }
  [ "$SESSION_CWD_REAL" = "$TARGET_REAL" ] || {
    echo "FAILED:$SESSION — existing session target mismatch ($SESSION_CWD_REAL != $TARGET_REAL)" >&2
    exit 75
  }
  SESSION_ORIGIN=$(git -C "$TARGET" remote get-url origin 2>/dev/null || true)
  SESSION_BRANCH=$(git -C "$TARGET" branch --show-current 2>/dev/null || true)
  [ "$SESSION_ORIGIN" = "$REMOTE_URL" ] || {
    echo "FAILED:$SESSION — existing session origin mismatch" >&2
    exit 75
  }
  [ "$SESSION_BRANCH" = "$BRANCH" ] || {
    echo "FAILED:$SESSION — existing session branch mismatch" >&2
    exit 75
  }
  SESSION_HEAD=$(git -C "$TARGET" rev-parse HEAD 2>/dev/null || true)
  [ "$SESSION_HEAD" = "$INTENDED_SHA" ] || {
    echo "FAILED:$SESSION — active checkout SHA $SESSION_HEAD differs from intended source $INTENDED_SHA; preserving it" >&2
    exit 75
  }
  echo "RESUMED:$SESSION:$TARGET:$OUTPUT_ROOT:$SESSION_HEAD"
  exit 0
fi

# A child Bash reads BASH_ENV before its command. The host's BASH_ENV normally
# sources ~/.bashrc, which resets the two output variables to Scratch/tmp.
# Preserve that startup (including credentials), then restore this mirror's
# values. Re-export BASH_ENV so nested non-login Bash shells do the same.
SCOPED_BASH_ENV=$(mktemp "$OUTPUT_ROOT/.mirror-bash-env.XXXXXX") || {
  echo "FAILED:$OUTPUT_ROOT — cannot allocate scoped Bash startup" >&2
  exit 75
}
HOST_BASH_ENV=${BASH_ENV:-}
{
  if [ -n "$HOST_BASH_ENV" ]; then
    printf 'if [ -f %q ]; then . %q; fi\n' "$HOST_BASH_ENV" "$HOST_BASH_ENV"
  fi
  printf 'export CLAUDE_CODE_TMPDIR=%q\n' "$OUTPUT_ROOT"
  printf 'export PYTEST_DEBUG_TEMPROOT=%q\n' "$OUTPUT_ROOT"
  printf 'export BASH_ENV=%q\n' "$SCOPED_BASH_ENV"
} > "$SCOPED_BASH_ENV"
# Launch command for the caller's own CLI (see step 1: no hardcoded default).
# Keep the host's TMPDIR unchanged. Codex shell calls must use login:false:
# login Bash reads ~/.bash_profile after/instead of BASH_ENV and resets output.
LAUNCH_ENV=(env "DISKM_SCRATCH=$SCRATCH_ROOT" "CLAUDE_CODE_TMPDIR=$OUTPUT_ROOT" "PYTEST_DEBUG_TEMPROOT=$OUTPUT_ROOT" "BASH_ENV=$SCOPED_BASH_ENV")
case "$AGENT_CLI" in
  claude) LAUNCH=("${LAUNCH_ENV[@]}" claude --dangerously-skip-permissions -- "$CONTEXT") ;;
  pi)     LAUNCH=("${LAUNCH_ENV[@]}" pi -- "Caller handoff context: $CONTEXT") ;;
  codex)  LAUNCH=("${LAUNCH_ENV[@]}" codex
            -c "shell_environment_policy.set.DISKM_SCRATCH=$SCRATCH_ROOT"
            -c "shell_environment_policy.set.CLAUDE_CODE_TMPDIR=$OUTPUT_ROOT"
            -c "shell_environment_policy.set.PYTEST_DEBUG_TEMPROOT=$OUTPUT_ROOT"
            -c "shell_environment_policy.set.BASH_ENV=$SCOPED_BASH_ENV"
            --dangerously-bypass-approvals-and-sandbox -C "$TARGET" -- "$CONTEXT

Mirror shell contract: set login:false on every exec_command Bash call so BASH_ENV restores CLAUDE_CODE_TMPDIR and PYTEST_DEBUG_TEMPROOT to $OUTPUT_ROOT after host startup. Keep TMPDIR unchanged.") ;;
  agy)    LAUNCH=("${LAUNCH_ENV[@]}" agy --dangerously-skip-permissions --model gemini-3.8-flash-high --prompt-interactive="$CONTEXT") ;;
  *) echo "FAILED:$TARGET - unsupported AGENT_CLI '$AGENT_CLI' (claude|pi|codex|agy)" >&2; exit 1 ;;

esac


if [ ! -e "$TARGET/.git" ]; then
  mkdir -p "$(dirname "$TARGET")"
  git clone "$REMOTE_URL" "$TARGET"
fi

cd "$TARGET"

ORIGIN_URL=$(git remote get-url origin 2>/dev/null || echo "")
if [ -n "$ORIGIN_URL" ] && [ "$ORIGIN_URL" != "$REMOTE_URL" ]; then
  echo "ERROR:$TARGET already has a different origin ($ORIGIN_URL) — not touching it, resolve manually" >&2
  exit 1
fi

if [ -n "$(git status --porcelain --untracked-files=all --ignore-submodules=none)" ]; then
  echo "ERROR:$TARGET has uncommitted changes on the remote side — not overwriting them, resolve manually" >&2
  exit 1
fi

git fetch origin "$BRANCH"
REMOTE_BRANCH_SHA=$(git rev-parse "origin/$BRANCH")
if [ "$REMOTE_BRANCH_SHA" != "$INTENDED_SHA" ]; then
  echo "ERROR:$TARGET origin/$BRANCH moved to $REMOTE_BRANCH_SHA; intended source is $INTENDED_SHA — refusing checkout/launch" >&2
  exit 75
fi
if git show-ref --verify --quiet "refs/heads/$BRANCH"; then
  LOCAL_BRANCH_SHA=$(git rev-parse "$BRANCH")
  REMOTE_BRANCH_SHA=$(git rev-parse "origin/$BRANCH")
  if ! git merge-base --is-ancestor "$LOCAL_BRANCH_SHA" "$REMOTE_BRANCH_SHA"; then
    echo "ERROR:$TARGET branch is ahead of or diverged from origin/$BRANCH — not overwriting it, resolve manually" >&2
    exit 75
  fi
  git checkout "$BRANCH"
else
  git checkout -b "$BRANCH" "origin/$BRANCH"
fi

if ! git pull --ff-only origin "$BRANCH"; then
  echo "DIVERGED:$TARGET — local $BRANCH has diverged from origin/$BRANCH, resolve manually before continuing" >&2
  exit 1
fi
if [ "$(git rev-parse HEAD)" != "$INTENDED_SHA" ] || [ "$(git rev-parse "origin/$BRANCH")" != "$INTENDED_SHA" ]; then
  echo "ERROR:$TARGET did not converge exactly to origin/$BRANCH — refusing READY" >&2
  exit 75
fi

# tmux has-session prefix-matches by default — the leading "=" forces an
# exact match so a shorter branch name doesn't false-match a longer one.
if tmux has-session -t "=$SESSION" 2>/dev/null; then
  echo "FAILED:$SESSION — session appeared after preflight; refusing to attach or mutate its checkout" >&2
  exit 75
else
  # A bare shell in a checked-out repo is not "continuing the work session"
  # — launch the coding agent as the session's actual command, with
  # $CONTEXT as its argv, instead of `new-session` + a bare shell +
  # `send-keys` typed in after a fixed sleep. tmux execs trailing words
  # directly (no shell re-tokenization), so this also closes the injection
  # window a typed-and-Entered $CONTEXT would open if the CLI weren't at
  # its prompt yet: a `send-keys`-typed string lands in whatever the pane's
  # foreground process is at that moment, so a starting-vs-prompt-not-ready
  # race can dump $CONTEXT straight into an interactive shell and execute
  # it. Passing it as an argv element never touches a shell at all — this
  # only ever fires on a session that didn't already exist (the branch
  # above), so a resumed session never gets a replayed prompt injected on
  # top of work already in progress.
  #
  # `--dangerously-skip-permissions` and `--` are both required. `--`
  # stops `claude` from treating a `$CONTEXT` that happens to start with
  # `-`/`--` as a flag instead of the prompt. `--dangerously-skip-permissions`
  # skips tool-permission prompts, but — confirmed live, 2026-09-18 — it
  # does NOT suppress the first-run workspace-trust dialog for a git
  # repository specifically (it does for a plain non-git directory, which
  # is what made an earlier version of this fix look sufficient before
  # testing against an actual mirrored clone). That dialog's *default*
  # selection is "No, exit"; a bare `claude "$CONTEXT"` on a fresh mirror
  # clone sits there, and the session vanishes the instant anything —
  # including an unrelated Enter — accepts the default and exits `claude`.
  #
  # remain-on-exit is set in the same tmux invocation (not a separate
  # call) so a session that dies immediately — missing `claude` binary,
  # PATH not resolving it under a non-login tmux shell, a crash — leaves a
  # dead-but-inspectable pane instead of vanishing outright.
tmux new-session -d -s "$SESSION" -c "$TARGET" "${LAUNCH[@]}" \; set-option -t "$SESSION" remain-on-exit on 9>&-
  # Poll for the trust dialog and accept it with fixed navigation keys
  # (Down, Enter) — never $CONTEXT — so this carries none of the
  # injection risk the original send-keys-typed-$CONTEXT bug had. This
  # only fires the first time a given target directory is mirrored (the
  # dialog only appears once claude.json records the directory as
  # trusted); a no-op loop on an already-trusted directory is safe.
  # Only Claude Code uses this dialog-acceptance loop; other CLIs use the checks below.
  if [ "$AGENT_CLI" = "claude" ]; then
  for _ in $(seq 1 40); do
    if ! PANE_PROBE=$(tmux capture-pane -p -t "$SESSION" 2>/dev/null); then
      echo "FAILED:$SESSION - cannot capture the pane; refusing to infer a ready state" >&2
      exit 1
    fi
    if printf '%s' "$PANE_PROBE" | grep -qF "Yes, I trust this folder"; then
      # The dialog's text can be captured before its keyboard handler is
      # actually wired up — confirmed live under real load (this box
      # routinely runs 20+ concurrent mirror tmux sessions): a Down sent
      # the instant the text appeared was silently swallowed, and a
      # fixed-delay Enter afterward confirmed the still-focused default
      # "No, exit", killing the session (exit 1). Settle briefly, then
      # verify the cursor actually reached "Yes, I trust this folder"
      # before sending Enter — checking before each Down (not after)
      # means a Down that lands late is never followed by a second one
      # that would toggle the two-item list back to "No, exit".
      sleep 0.2
      for _ in $(seq 1 15); do
        tmux capture-pane -p -t "$SESSION" 2>/dev/null | grep -qE '❯[[:space:]]*Yes, I trust this folder' && break
        tmux send-keys -t "$SESSION" Down || true
        sleep 0.2
      done
      # || true on both send-keys calls: a session that died in the gap
      # since the last capture-pane check would make send-keys fail and,
      # under set -e, silently abort the whole remote script with no
      # FAILED: marker — the same class of gap 58d9db5 closed for
      # capture-pane. Falling through instead lets the existing
      # has-session/pane_dead check report FAILED correctly.
      tmux send-keys -t "$SESSION" Enter || true
      # send-keys returns before claude's render loop processes Enter —
      # confirmed live: the readiness check below ran ~8ms after Enter
      # and still saw the dialog text on screen, reporting a false
      # FAILED on a session that was actually fine one second later.
      # Poll (bounded) until the dialog text actually clears.
      for _ in $(seq 1 10); do
        tmux capture-pane -p -t "$SESSION" 2>/dev/null | grep -qF "Yes, I trust this folder" || break
        sleep 0.2
      done
      break
    fi
    # An already-trusted directory never shows the dialog, so without a
    # positive exit this loop always burns its full budget — confirmed
    # live: an already-trusted launch stalled the caller a flat 20s.
    # claude's status bar ("bypass permissions on") only ever appears
    # once past the dialog (confirmed live: never co-occurs with the
    # dialog text), so treat it as the "no dialog is coming" signal.
    printf '%s' "$PANE_PROBE" | grep -qF "bypass permissions on" && break
    sleep 0.5
  done
  # tmux new-session exits 0 even when the launched command can't be
  # exec'd, and with remain-on-exit set, has-session alone can't tell a
  # genuinely running session from a dead one either — remain-on-exit
  # keeps the session entry around specifically so it doesn't vanish, so
  # has-session still returns success. #{pane_dead} is the actual signal
  # (confirmed live: 1 immediately after an exec failure, 0 while running).
  # A still-showing trust dialog is a third failure mode #{pane_dead} can't
  # catch: claude is alive, just parked on the modal, if the poll above
  # exhausted its window before the dialog rendered (a real risk on a
  # loaded box — /advice round 3 caught this) — re-check for it explicitly
  # rather than trusting silence from the poll loop as acceptance.
  fi
  if [ "$AGENT_CLI" != "claude" ]; then
    if ! tmux has-session -t "=$SESSION" 2>/dev/null \
       || [ "$(tmux display-message -p -t "$SESSION" '#{pane_dead}')" != "0" ]; then
      echo "FAILED:$SESSION:$TARGET — agent exited before the settle check" >&2
      exit 1
    fi
    sleep 0.5
  fi
  if tmux has-session -t "=$SESSION" 2>/dev/null \
     && [ "$(tmux display-message -p -t "$SESSION" '#{pane_dead}')" = "0" ] \
     && { FINAL_PROBE=$(tmux capture-pane -p -t "$SESSION") || {
            echo "FAILED:$SESSION - cannot capture the pane; refusing to report READY" >&2; exit 1; }; } \
     && { [ "$AGENT_CLI" != "claude" ] || ! printf '%s' "$FINAL_PROBE" | grep -qF "Yes, I trust this folder"; }; then
    if [ "$AGENT_CLI" = "pi" ] \
       && printf '%s' "$FINAL_PROBE" | grep -qF "Trust project folder?"; then
      echo "FAILED:$SESSION:$TARGET — pi is waiting at its project-trust prompt; inspect it before reporting READY" >&2
      exit 1
    fi
    echo "READY:$SESSION:$TARGET:$OUTPUT_ROOT:$(git rev-parse HEAD)"
  else
    echo "FAILED:$SESSION:$TARGET — session did not survive launch (check that \`$AGENT_CLI\` is on the remote PATH); pane retained by remain-on-exit for inspection: tmux capture-pane -p -t $SESSION" >&2
    exit 1
  fi
fi
EOF
```

Pi treats each positional argument beginning with `@` as a file attachment, even after `--`. The fixed `Caller handoff context:` prefix keeps caller text as message content. If Pi's `Trust project folder?` prompt is visible after the settle check, leave the pane open and report `FAILED`; do not approve project resources automatically.

Note: `printf` (not `echo`) for the session-name sanitizing is deliberate — piping `echo`'s output through `tr -c '...' '-'` turns the trailing newline into a literal `-`, corrupting the session name.

### 5. Hand off

Follow the mandatory [agent submission and response proof contract](../linux-remote/SKILL.md#agent-submission-and-response-proof--mandatory). Before claiming work started, require a fresh response attributable to the dispatch and independently verify a task-specific first action or artifact produced by the remote agent. Report the first two or three response sentences verbatim, with secrets redacted, alongside the action and evidence reference. If either proof is missing, report the observed unconfirmed or blocked state and continue scoped recovery.

Report the session name, target path, and commit SHA from the `READY:`/`RESUMED:` line — cross-check that SHA against your local `git rev-parse HEAD`. `READY` proves the pane passed the launch and liveness checks; it does not prove the agent received or acted on `$CONTEXT`. `RESUMED` means an existing session was found as-is and nothing was typed into it — inspect that work directly rather than assuming it is idle. The preflight rejects local branches that are ahead of or diverged from the fetched remote branch, and the final HEAD is checked for exact equality before READY. Then give the attach command:

```bash
ssh -t "${SSH_ARGS[@]}" "$SSH_TARGET" "tmux attach -t <SESSION>"
```

### 6. Push discipline while mirrored

```bash
git add -A && git commit -m "..." && git push
```

If a PR is open for `$BRANCH`, pushes update its head automatically. Otherwise plain `git push` keeps the remote branch current so work isn't stranded on the Mac alone.

## Caveats

- Committed-state-only mirror — see "What this carries over" above.
- Source repo must live under `$HOME` (see Setup) — step 1 fails loudly rather than silently mirroring to the wrong place. The target-side checkout and agent output land under the target's configured Scratch root; existing `$HOME/mirror` paths are not reused or modified.
- Tool-owned auth, transcripts, and tmux state remain in their normal HOME locations; generated agent output and disposable test files use the Scratch output path reported by `READY`/`RESUMED`.
- Step 4 launches the calling CLI (`$AGENT_CLI`, resolved in step 1 — `pi`/`claude`/`codex`/`agy`) as the session's command with `$CONTEXT` passed as its argv (not typed via `send-keys`), but only on a freshly created session. Never assume a `RESUMED` session is idle just because this skill didn't launch anything into it.
- macOS SSH keychain may prompt on first connection; `ssh-add --apple-use-keychain ~/.ssh/id_ed25519` caches it.
- A bare host alias is typically LAN-only; off-LAN, target the Tailscale IP + explicit `-i` per Tier 2 — and make sure step 4 actually uses the resolved `$SSH_ARGS`/`$SSH_TARGET`, not a re-hardcoded alias.
- Never pass unencoded user-controlled values (repo path, branch name, remote URL) as literal SSH command arguments — base64-encode first (see step 4).
- Tier 3 hands off to a *different* agent/process with no shared context — see the debugging priority above before assuming it's broken vs. just needing a genuinely human-originated test or a missing permission grant.
- If your remote origin URL embeds a credential (HTTPS + PAT), that credential gets written to the target machine's `.git/config` in cleartext the first time this clones there — prefer an SSH remote or an external credential helper.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in tools →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.