Migrate Session Skill
Move the currently running amplihack CLI session to a fresh azlin-managed VM
and resume it there in a detached tmux. One command end-to-end.
⚠️ Do not activate this skill on any natural-language prompt that merely
contains the word "migrate" (e.g. "migrate from Python", "data migration",
"memory backend migration"). Activate only when the user explicitly types
the /amplihack:migrate slash command or asks to "move the current session
to ".
When to Use
- Local host is low on disk/RAM under heavy orchestrator load
- You want to move long-running OODA work to a beefier Azure VM
- You need to hand off the session to an unattended cloud host so the laptop
can sleep
- You are switching from a constrained dev container to a full Linux VM
Usage
/amplihack:migrate <hostname>
/amplihack:migrate <hostname> --session <session-id>
The destination <hostname> must be an azlin-managed VM (reachable via
azlin connect / azlin cp).
What It Does
- Detects the active CLI session via env var → newest session-state dir.
- Bootstraps the destination (idempotent): node, npm, gh, uv, copilot,
amplihack — skips tools already installed at a matching version.
- Builds a selective
zstd-compressed tarball containing only:
~/.config/, ~/.copilot/skills/, ~/.amplihack/, ~/.ssh/
- The active
~/.copilot/session-state/<id>/ directory only
~/.simard/ only when --include-simard is passed. It is host-local
runtime state, not session state, and the destination is often a live
Simard host whose own store must not be replaced (issue #1166).
- Ships the tarball to the destination via
azlin cp, extracts it.
- Verifies
gh auth, copilot --version, and session-state integrity.
- Runs a final delta
rsync of the active session-state to capture
events written during the transfer.
- Reconstructs the project tree on the destination so the resumed session
lands in a valid git checkout instead of
$HOME:
- Reads
cwd, git_root, repository, host_type, branch from the
active session's workspace.yaml (flat grep/sed parsing, no yq).
- Skips (warn + resume in
$HOME, no hard-gate) when the session has no
reconstructable project: no workspace.yaml, absent repository/git_root,
or a non-github host_type.
- Validates the untrusted fields (repo/branch/host_type regex + allowlist);
a malformed field on a github session is fatal (exit 11).
- Re-derives destination paths from the validated
repository/branch
(the source git_root, which amplihack records equal to cwd, is not
reused): $HOME/src/<repo> for the clone and
$HOME/src/<repo>/worktrees/<branch> for worktree sessions (detected by
/worktrees/ in cwd; double-nested worktrees normalized to one level).
gh repo clone <repository> (idempotent fetch+checkout if .git exists);
git worktree add for worktree sessions, falling back to a standalone
clone/checkout at cwd so the hard-gate still passes.
- All GitHub network calls (clone/fetch) use bounded retry-with-backoff
(
AMPLIHACK_MIGRATE_RETRIES / AMPLIHACK_MIGRATE_RETRY_DELAY) so a
transient network failure retries before the exit-13 hard failure.
- Rewrites
cwd and git_root in the destination workspace.yaml.
- Hard-gates before resume: aborts if
cwd is missing or not a git
checkout on the recorded branch (unless reconstruction was skipped).
- Starts the CLI in a detached tmux on the destination:
- copilot:
copilot --resume <id>
- claude:
claude --resume <id> (best-effort)
- amplifier: prints manual-attach instructions (v1)
Prints an azlin connect -y <hostname>:session-<id> command you can paste on
your laptop to attach.
What Is Not Migrated
~/src/* source trees — reconstructed on the destination via
gh repo clone / git worktree add from the paths recorded in the session's
workspace.yaml (cross-user paths remapped under $HOME), not copied in the
tarball. Uncommitted / unpushed changes are not carried over.
- Caches:
**/target/, **/.venv/, **/node_modules/, ~/.cache/,
**/__pycache__/, and any directory tagged CACHEDIR.TAG
- Inactive sessions under
~/.copilot/session-state/
Security Note
Unlike the remote-work skill, this migration intentionally copies
credentials (~/.ssh, ~/.config/gh/hosts.yml) to the destination. The
skill prints a warning before transfer. Only use with trusted destinations.
Invocation
The slash command resolves to this skill's helper script, which is staged by
the bundle installer into ~/.amplihack/.claude/skills/migrate/scripts/.
bash "$AMPLIHACK_HOME/.claude/skills/migrate/scripts/migrate.sh" <hostname> [--session <id>]
The script is idempotent: re-running against the same destination skips
already-installed toolchain, overwrites the active session-state on the
destination (source is authoritative until resume), and re-extracts
~/.config/ / ~/.amplihack/ (cheap; ensures freshness).
See Also
- Full documentation: docs/skills/migrate.md
azlin skill — destination provisioning and transport
remote-work skill — related but does not copy credentials
1---2name: amplihack-migrate3description: Move the active amplihack CLI session (Copilot/Claude/Amplifier) to a fresh azlin-managed VM, preserving auth, plugins, skills, plan.md, todos, and conversation history. Resumes the session in a detached tmux on the destination host.4---56# Migrate Session Skill78Move the currently running amplihack CLI session to a fresh azlin-managed VM9and resume it there in a detached tmux. One command end-to-end.1011> ⚠️ Do not activate this skill on any natural-language prompt that merely12> contains the word "migrate" (e.g. "migrate from Python", "data migration",13> "memory backend migration"). Activate only when the user explicitly types14> the `/amplihack:migrate` slash command or asks to "move the current session15> to <host>".1617## When to Use1819- Local host is low on disk/RAM under heavy orchestrator load20- You want to move long-running OODA work to a beefier Azure VM21- You need to hand off the session to an unattended cloud host so the laptop22 can sleep23- You are switching from a constrained dev container to a full Linux VM2425## Usage2627```text28/amplihack:migrate <hostname>29/amplihack:migrate <hostname> --session <session-id>30```3132The destination `<hostname>` must be an azlin-managed VM (reachable via33`azlin connect` / `azlin cp`).3435## What It Does36371. Detects the active CLI session via env var → newest session-state dir.382. Bootstraps the destination (idempotent): node, npm, gh, uv, copilot,39 amplihack — skips tools already installed at a matching version.403. Builds a selective `zstd`-compressed tarball containing only:41 - `~/.config/`, `~/.copilot/skills/`, `~/.amplihack/`, `~/.ssh/`42 - The **active** `~/.copilot/session-state/<id>/` directory only43 - `~/.simard/` **only** when `--include-simard` is passed. It is host-local44 runtime state, not session state, and the destination is often a live45 Simard host whose own store must not be replaced (issue #1166).464. Ships the tarball to the destination via `azlin cp`, extracts it.475. Verifies `gh auth`, `copilot --version`, and session-state integrity.486. Runs a final delta `rsync` of the active session-state to capture49 events written during the transfer.507. Reconstructs the project tree on the destination so the resumed session51 lands in a valid git checkout instead of `$HOME`:52 - Reads `cwd`, `git_root`, `repository`, `host_type`, `branch` from the53 active session's `workspace.yaml` (flat `grep`/`sed` parsing, no `yq`).54 - **Skips** (warn + resume in `$HOME`, no hard-gate) when the session has no55 reconstructable project: no `workspace.yaml`, absent `repository`/`git_root`,56 or a non-github `host_type`.57 - Validates the untrusted fields (repo/branch/host_type regex + allowlist);58 a malformed field on a github session is fatal (exit 11).59 - Re-derives destination paths from the **validated** `repository`/`branch`60 (the source `git_root`, which amplihack records equal to `cwd`, is not61 reused): `$HOME/src/<repo>` for the clone and62 `$HOME/src/<repo>/worktrees/<branch>` for worktree sessions (detected by63 `/worktrees/` in `cwd`; double-nested worktrees normalized to one level).64 - `gh repo clone <repository>` (idempotent fetch+checkout if `.git` exists);65 `git worktree add` for worktree sessions, falling back to a standalone66 clone/checkout at `cwd` so the hard-gate still passes.67 - All GitHub network calls (clone/fetch) use bounded retry-with-backoff68 (`AMPLIHACK_MIGRATE_RETRIES` / `AMPLIHACK_MIGRATE_RETRY_DELAY`) so a69 transient network failure retries before the exit-13 hard failure.70 - Rewrites `cwd` **and** `git_root` in the destination `workspace.yaml`.71 - Hard-gates before resume: aborts if `cwd` is missing or not a git72 checkout on the recorded branch (unless reconstruction was skipped).738. Starts the CLI in a detached tmux on the destination:74 - copilot: `copilot --resume <id>`75 - claude: `claude --resume <id>` (best-effort)76 - amplifier: prints manual-attach instructions (v1)7778Prints an `azlin connect -y <hostname>:session-<id>` command you can paste on79your laptop to attach.8081## What Is Not Migrated8283- `~/src/*` source trees — **reconstructed** on the destination via84 `gh repo clone` / `git worktree add` from the paths recorded in the session's85 `workspace.yaml` (cross-user paths remapped under `$HOME`), not copied in the86 tarball. Uncommitted / unpushed changes are not carried over.87- Caches: `**/target/`, `**/.venv/`, `**/node_modules/`, `~/.cache/`,88 `**/__pycache__/`, and any directory tagged `CACHEDIR.TAG`89- Inactive sessions under `~/.copilot/session-state/`9091## Security Note9293Unlike the `remote-work` skill, this migration **intentionally** copies94credentials (`~/.ssh`, `~/.config/gh/hosts.yml`) to the destination. The95skill prints a warning before transfer. Only use with trusted destinations.9697## Invocation9899The slash command resolves to this skill's helper script, which is staged by100the bundle installer into `~/.amplihack/.claude/skills/migrate/scripts/`.101102```bash103bash "$AMPLIHACK_HOME/.claude/skills/migrate/scripts/migrate.sh" <hostname> [--session <id>]104```105106The script is idempotent: re-running against the same destination skips107already-installed toolchain, overwrites the active session-state on the108destination (source is authoritative until resume), and re-extracts109`~/.config/` / `~/.amplihack/` (cheap; ensures freshness).110111## See Also112113- Full documentation: [docs/skills/migrate.md](../../../docs/skills/migrate.md)114- `azlin` skill — destination provisioning and transport115- `remote-work` skill — related but does not copy credentials