TheVoskamps

claude-vm

Launch Claude Code inside an isolated Linux micro-VM on macOS with config-driven egress, mounts, VM resources, guest environment variables (including third-party API keys forwarded by name from the host, never written into config), and repo isolation (clone or live). All non-secret knobs come from four-file YAML (a bake file + a boot file per tier, global + per-repo, all optional); the immutable base image is APFS-cloned per run so concurrent sessions never leak state. The guest authenticates with the host's claude.ai OAuth credential extracted from the macOS Keychain at launch, plus an identity seed (userID + oauthAccount from the host's ~/.claude.json, plus synthesized onboarding/auto-update-off/version keys) so the in-guest session comes up already onboarded, logged in, and with self-update disabled.

TheVoskamps 0 Updated 3d ago

Resources

1
GitHub

Install

npx skillscat add thevoskamps/claude-plugins-marketplace/claude-vm

Install via the SkillsCat registry.

SKILL.md

claude-vm

Run Claude Code inside an isolated Linux micro-VM on macOS. Every
non-secret operational knob — VM resources, the egress allowlist, extra
mounts, the proxy, the guest's own environment variables, and how the
repo is made available to the guest — comes from layered YAML config
rather than claude-vm's own environment variables.
The guest authenticates with the host's live claude.ai OAuth
credential
, which the launcher extracts from the macOS Keychain at
launch and shares into the guest (where the image's fstab mounts the
share ro), plus an identity seed the launcher builds from your host
~/.claude.json — the userID + oauthAccount selected from the host,
plus synthesized
hasCompletedOnboarding / autoUpdates: false / version keys — so the
interactive in-guest session comes up already onboarded, logged in, and
with self-update disabled (issue #88). Both are secrets, neither is
written to config, and both ride the same transient shred-on-exit
mount. No token environment variable is required — just be logged in to
Claude Code on the host.

The entry point is bin/claude-vm (issue #51), a preflight wrapper
that ships on PATH for the Bash tool; it forwards to the launcher and
image-build scripts, which ship as payloads under
${CLAUDE_PLUGIN_ROOT}/payload/. This skill explains the config
surface and drives the launcher.

Quick start

# 1. Be logged in to Claude Code on this host. The launcher installs the
#    host's live claude.ai OAuth credential (extracted from the macOS
#    Keychain) AND seeds the guest's identity (userID + oauthAccount from
#    your ~/.claude.json, plus synthesized onboarding/auto-update-off
#    keys) so the in-guest claude comes up already onboarded and logged
#    in. Run `claude` once and complete the claude.ai login if you have
#    not; the launcher aborts at a preflight if you are not logged in.
#    No token environment variable is required.

# 2. (Optional) drop a global config PAIR at
#    ~/.config/claude-vm/config-bake.yml + config-boot.yml and/or a
#    per-repo pair at <repo>/.claude-vm/config-{bake,boot}.yml. A bake
#    file holds image-bytes keys; a boot file holds run-time keys.
#    Run /claude-vm-config-global to write the global pair from the
#    resolved defaults, and /claude-vm-config-repo (from inside a repo)
#    to write per-repo overrides (both idempotent). claude-vm-config-keys
#    prints each key's file and default; payload/config-bake.example.yml
#    + config-boot.example.yml show what a populated entry looks like.
#    bin/claude-vm below also offers to create the global
#    config for you if it is missing. (A legacy single-file config.yml is
#    no longer read -- the launcher aborts with a migration message.)

# 3. Launch from inside the repo you want to run a VM for. bin/claude-vm
#    derives the repo name and root, names the run, and forwards to the
#    launcher, which makes the repo available RW to the guest.
claude-vm [--as <name>] [claude args...]

Launching as a named account (--as)

claude-vm --as <name> [claude args...] launches the guest as the host
Claude Code account whose config directory is D = $HOME/.claude.<name>.
The entry point passes it on as
claude-vm.sh --as <name> <repo-path> [claude args...]. A name holds only
ASCII letters, digits, _ and -, and is not backup. --as is
recognised only as the first argument of each, is not part of the computed
session name, and every later argument still reaches the guest claude
unchanged.

With --as, every host source follows from D; there is no config key for
accounts:

  • the credential comes from the Keychain service
    Claude Code-credentials-<h>, where <h> is the first 8 lowercase hex
    characters of the SHA-256 of D's path string with no trailing newline —
    the service Claude Code itself uses for CLAUDE_CONFIG_DIR=D. The entry
    point's presence check and the launcher read the same service;
  • the identity seed comes from D/.claude.json;
  • the curated working rules come from D.

The account comes from --as alone: an inherited CLAUDE_CONFIG_DIR is
never read. Wherever else this skill names the Claude Code-credentials
item, ~/.claude.json or ~/.claude as a host source, it describes a launch
without --as.

Before any build or boot, the launcher refuses a missing or invalid name, a
missing account directory, a missing D/.claude.json or one with no usable
identity, and a missing or unusable Keychain item. A refusal names the
account and the missing piece and prints no value read from the Keychain or
the identity file; nothing is copied or substituted for a missing piece, and
no launch falls back to another account's identity or credential. Log an
account in on the host with CLAUDE_CONFIG_DIR=$HOME/.claude.<name> claude.
The selection of keys from each source, the file modes and the removal on
exit are the same as without --as.

On exit in clone mode, repo.copy_back decides whether the launcher
copies the guest's changes back to the local source. The companion
skills extract work
explicitly: /claude-vm-diff, /claude-vm-apply-local,
/claude-vm-apply-remote.

Config surface

Four files, all optional (issue #179) — a bake file and a
boot file per tier. Placement rule: a key that changes bytes in
the guest .raw image
goes in a bake file; a key applied at run
time
goes in a boot file. Placement IS the classification, made
once by the operator — a knob in the wrong file loudly does nothing
instead of silently poisoning the image cache.

  1. Global bake: ~/.config/claude-vm/config-bake.yml — machine-wide
    image-bytes defaults.
  2. Global boot: ~/.config/claude-vm/config-boot.yml — machine-wide
    run-time defaults.
  3. Per-repo bake: <repo>/.claude-vm/config-bake.yml — this repo's
    image-bytes overrides. Shipping this file gives the repo its OWN image.
  4. Per-repo boot: <repo>/.claude-vm/config-boot.yml — this repo's
    run-time overrides.

Run /claude-vm-config-global to create the global pair, and
/claude-vm-config-repo (from inside a repo) to write per-repo
overrides; both are idempotent and never clobber an existing file. A
legacy single-file config.yml (either tier) is no longer read — the
launcher aborts with a migration message rather than silently dropping
the knobs it set.

Keys

The key set, the file type each key sits in, its type, whether it merges
as a list or a scalar, and its default come from the launcher's own key
table:

claude-vm-config-keys

It prints one key per line as the tab-separated fields key, file (bake,
boot or both), type, list or scalar, and default. Read
${CLAUDE_PLUGIN_ROOT}/skills/claude-vm/config-keys.md for what each
key means, how the tiers layer, and which values abort the launch.

Host paths vfkit embeds

vfkit embeds every host path it is given in a comma-delimited option
string, and a comma in one reads as the start of another option. The
launcher checks a directory mounts source for a comma, and the
single-file wrap directory ($RUN/mount-wrap) when it wraps a file,
naming the run dir. A repo path under repo.mount: live, $HOME,
XDG_STATE_HOME, CLAUDE_VM_RUNS_DIR or $TMPDIR carrying a comma
breaks the built-in shares, the EFI store, the disk clone, the console
log or the gvproxy socket the same way and is not checked: none of those
is a value the operator fixes by editing YAML, and vfkit refuses the
unknown option, so the launch stops loudly rather than booting with a
share pointing elsewhere.

Plugin bake and boot phases

The image build runs the host-verified guest claude binary inside the
build container with HOME=/root and drives its own CLI —
claude plugin marketplace add, then claude plugin install — so the
registry format is claude's and is never hand-written. A failed add or
install of what the image must carry fails the build; a marketplace
declared only for boot that has no url, fails to add, or registers under
another name warns and is left to the boot phase.

At boot, before claude starts, the guest adds any configured marketplace
the image does not carry, refreshes the marketplaces when
claude.plugins.update_at_boot is on, installs the install_at_boot
refs, and, again under update_at_boot, updates every installed plugin.
The image-identity hash excludes marketplace HEAD, so a marketplace bump
reaches a baked plugin at the next boot with no rebuild. A failure warns
on the boot console and the session continues. The image bakes git for
this phase: the claude CLI shells out to system git for every git-url
marketplace operation.

Guest environment variables (issue #135)

env values reach the guest on two carriers, one per tier — run.env is
neither and stays launcher-owned, deliberately a non-secret channel. Bake
env.set is written into the image at build time and persists. The
whole boot tier, including the non-secret env.set literals, rides
the same transient claudecreds mount as the OAuth credential and
identity seed (0600, mounted ro guest-side, shredded on exit); the guest
sources it off that mount and never copies it, so no forwarded value
reaches the guest filesystem. One carrier for the whole boot tier means
the secret and non-secret boot paths cannot diverge. The guest sources
run.env before both env files, so a config entry naming a
launcher-owned variable would overwrite the launcher's own value; the
launcher refuses those names at load.

Guest Claude settings.json (issue #104)

The launcher renders the guest's /root/.claude/settings.json
host-side from the merged config and shares it into the guest over the
existing transient claudecreds mount (the same one the OAuth
credential and identity seed ride). The guest boot launcher installs it
at $HOME/.claude/settings.json. The guest's permission and plugin
surface — everything the rendered file carries — is derived from the claude-vm
configs only: the host's ~/.claude/settings.json and the host's own
installed plugins are never read, so the guest deliberately runs its own
(possibly riskier) posture. (The host's ~/.claude working rules — the
non-policy layer of CLAUDE.md, rules/, agents/, skills/ and
keybindings.json — are seeded in; see Host working rules seeded into
the guest
below.) The rendered keys:

  • permissions.allow / .ask / .deny come verbatim from
    claude.permissions.*.
  • permissions.defaultMode comes from claude.permission_mode. A value
    outside its type aborts the launch (it is a security-posture value with
    no defined behavior for an unknown mode). bypassPermissions treats the
    VM as the isolation boundary, with the deny list as backstop. The guest
    runs claude as root, which claude
    refuses in bypassPermissions unless IS_SANDBOX=1; the launcher sets
    IS_SANDBOX=1 unconditionally in run.env (the guest is the
    sandbox).
  • enabledPlugins maps every ref in
    claude.plugins.bake ++ claude.plugins.install_at_boot to true
    (de-duplicated), then the optional claude.plugins.enabled map
    overrides those defaults per key. enabled mirrors settings.json's
    own enabledPlugins vocabulary: false marks a
    plugin installed-but-disabled (re-enabling needs no reinstall — handy
    for toggling debug plugins like show-loaded-rules / show-loaded-skills
    around a specific issue). The map is validated once: every value must
    fit its type and every key must name an installed ref — an unknown key is a
    typo and aborts the launch.
  • extraKnownMarketplaces maps every configured marketplace name (the
    effective bake ++ boot set) to its source, in the shape claude itself
    writes: an https:// url renders as {"source":"git","url":…}, an
    owner/repo shorthand as {"source":"github","repo":…}. This key is
    rendered because claude plugin install was observed writing it into
    ~/.claude/settings.json alongside enabledPlugins — and the boot
    launcher copies the host-rendered file over whatever the image baked, so
    omitting it would drop the marketplace declarations the bake step's own
    CLI run wrote. Rendering it from the same effective set the bake and boot
    paths use keeps the three from drifting. It does not make claude
    self-install a missing plugin (tested directly: a home dir with only this
    settings.json and no ~/.claude/plugins tree installs nothing), which is
    why the guest's explicit ensure/install/update phase is load-bearing.

claude-vm has no own CLI flags but a leading --as <name> (see
Launching as a named account above), which it takes for itself because
the account must be known before any host state is read: every other
argument is forwarded to the guest claude verbatim. Plugin enable/disable
state is set through
claude.plugins.enabled in the config files, not on the command line.

Host working rules seeded into the guest (issue #108)

The section above is the policy layer, which the guest gets from the
claude-vm config rather than from the host. The operator's "who I am /
how I work"
layer goes the other way — it follows them into the VM. The
launcher stages copies of the host's ~/.claude/CLAUDE.md, rules/,
agents/, skills/ and keybindings.json onto the same transient
claudecreds mount the credential, identity seed and rendered
settings.json ride, and the boot launcher copies them additively into
the guest's ~/.claude/: a directory is merged into whatever is already at
that path (the image's baked plugins/ is untouched) and a same-named file
is overwritten. CLAUDE.md and rules/ travel together because the former
references the latter as @~/.claude/rules/*.md.

There is no config key for this — the list is fixed in the launcher and
spelled again in the boot launcher it emits, so adding an entry is a
deliberate edit on both sides of the seam. And it is an include list: a
host ~/.claude accumulates directories claude-vm has never heard of, and
an exclude list would leak every future one by default. Nothing else is
copied. Not the policy layer
(settings.json is rendered, plugin state is config-driven), and not
host-scoped session state — projects/ (keyed by host paths the guest does
not have), history.jsonl, todos/, sessions/, logs/, statsig/,
shell-snapshots/, ide/, teams/, usage-data/.

Your host files are never touched: what the guest sees is a copy, staged
under umask 077 in the run's shred-on-exit credential dir. Symlinks are
dereferenced, so a ~/.claude that is a checkout with rules/ or
skills/ symlinked out of it still seeds real content rather than a
dangling link. Every entry is optional — a host with no keybindings.json
and no global CLAUDE.md launches normally and silently. A copy that
fails prints a warning from the side that attempted it — on the launcher's
stderr when the host cannot stage the entry (which then never reaches the
guest at all), in the guest's hvc0 diagnostic log when the guest cannot
install it — and the launch continues: unlike the credential and
settings.json, no copy failure in this layer aborts a boot. The guest half
therefore guards every command it runs on an entry, its mkdir -p as
much as its copies, since the boot launcher runs under set -euo pipefail.

A failed entry is also dropped, not left half-copied: cp -R keeps going
past a per-file error, and a partial rules/ tree is worse than an absent
one. The guest can only drop what this seed created, so a destination that
already existed in the image is left alone — with a warning that it may now
hold a partial copy — rather than having baked content deleted under it.

Interactive session (the launching terminal IS the in-VM claude)

claude-vm <repo> opens an interactive Claude Code session on the
launching terminal — the terminal becomes the guest's hvc1 console and
you drive the full REPL inside the micro-VM (detached clone + egress
proxy). This is the product goal; headless one-shot is not. Pass
--remote-control --name <n> straight through (claude-vm <repo> --remote-control --name foo) and the same session is also
Remote-Control-attached for AFK observation/replies — those flags reach
the in-guest claude via the existing CLAUDE_ARGS plumbing; no extra
transport is involved.

Ways to turn on Remote Control:

  • Per-launch, via CLI — pass --remote-control (and optionally
    --name <n>) after the repo path, as above.
  • By config — set claude.remote_control: true in the global
    or per-repo config. The launcher then injects --remote-control for
    you (without duplicating it if you also pass it on the CLI). Either way,
    if Remote Control is in effect but you gave no --name, the launcher
    appends a date-stamped --name (format like Jul10-14:30) so the run
    is named — matching the date-stamp default this skill documents. A
    user-supplied --name (in either --name <v> or --name=<v> form) is
    never overridden. Arbitrary CLI args survive verbatim: the launcher
    quotes CLAUDE_ARGS per-argument into run.env and the guest boot
    launcher reconstructs the exact argv, so a value like
    --name "foo #7 micro-vm" (with spaces and a #) round-trips intact.

Topology: vfkit attaches two virtio-serial consoles. The first
(logFilePath, guest hvc0) captures all kernel/systemd boot output to
$CLAUDE_VM_STATE_DIR/logs/<run-id>/guest-console.log (preserving the
observability from the guest-console capture); the second (stdio,
guest hvc1) bridges the launching terminal. The guest runs claude as
the login program of an autologin serial-getty@hvc1, so claude is
the session with no shell in between. Boot diagnostics stay on hvc0
(off your terminal).

Because the stdio console is a byte pipe that needs a real controlling
TTY on the host, launch claude-vm from a real terminal, not from a
pipe. The console carries no live window-resize channel, so the launcher
seeds the guest tty geometry once from the host's stty size at launch;
there is no live resize.

Repo mount strategy (repo.mount)

How the repo is made available RW to the guest:

  • clone: git clone --no-hardlinks the repo into a
    persistent worktree, mounted RW. The guest never touches the live
    working tree or .git. The worktree lives under
    $CLAUDE_VM_RUNS_DIR/<runid>/worktree — the runs root, runs/
    under the state root lib/config.sh resolves — whether or not the
    argument is a git repo. It persists after the run so the companion
    diff/apply skills can inspect and extract results; they find this
    repo's runs by the repo_src line of each run's run.meta.
  • live: mount the live repo dir RW directly. More convenient,
    less isolated.

Getting work back out (clone mode)

After the guest exits, repo.copy_back: local copies the guest's changes
back to the local source, and repo.copy_back: none leaves them to
extract manually. The three
companion skills handle extraction explicitly:

  • /claude-vm-diff — read-only: show what changed in the VM worktree
    vs. the local source.
  • /claude-vm-apply-local — apply the VM worktree's changes to the
    local source.
  • /claude-vm-apply-remote — push the VM worktree's changes to the
    remote.

Reaping a run whose launcher has exited

A launcher killed with kill -9 (or a crash, or a closed terminal)
never runs its exit trap, and its run dir keeps its guest-image clone.
Each launcher holds a lockf lock on $RUN/run.lock for its lifetime,
and no process it leaves running holds it, so a dead launcher is a
dead run. A watcher the launcher starts beside vfkit waits on that
lock and, the moment the launcher dies, stops vfkit, gvproxy and the
proxy — so a kill -9 of the launcher stops the VM too. The watcher
signals those three pids, and the launcher's own exit trap the
gvproxy, proxy and watcher pids, only while each still carries the
start time recorded for it at launch.
bin/claude-vm-cleanup, run by hand, reaps the rest for every repo at
once: it reaps only a run whose lock it can take, whether that run
exited normally or crashed — killing the pids its run.meta records
(vfkit_pid, gvproxy_pid, proxy_pid, a backstop for a watcher that
was killed as well) while each still carries the start time recorded
beside it, so a pid since taken by another process is never signalled,
and removing its gvproxy socket dir, its creds/ dir (the OAuth
credential and identity seed), any raw Keychain blob
(.keychain-blob.raw.json) and its guest-clone.raw — and leaves
every live run alone. It keeps the run
dir, worktree/, run.meta and run.lock included, so the companion skills still
find the run, and it never removes $CLAUDE_VM_STATE_DIR/logs/, where
each run's console, gvproxy and proxy logs and egress capture are kept.
It reports each run it reaped, with its log dir and kept worktree, or
spared.

Guest image — built on demand, version-pinned, claude verified host-side

Claude Code updates daily, so the guest image does not bake in
claude:

  • The baked image is a stable base: a pinned OS plus a boot launcher
    that, on boot, loads the run environment and then runs the
    host-side GPG-verified claude binary mounted RO at
    /mnt/claudebin against the repo at /mnt/repo, as an interactive
    session on the hvc1 console (issue #88). claude is never
    baked in and never fetched-and-run inside the guest (no
    curl install.sh | bash anywhere — there is no such fallback); the
    host fetches, verifies, and caches it. The base only changes when the
    base OS pin or the launcher logic changes — not when claude does.

  • The base is version-pinned in payload/build-guest-image.sh
    (BASE_OS_REV + LAUNCHER_LOGIC_REV; never the claude version).

  • Baked packages (issue #105, re-keyed by #179). A bake file's
    packages: and apt_sources: ARE baked into the image (unlike
    claude): the baked packages are present in the guest with no
    boot-time network, and each apt_sources repo's key_url is fetched
    into a keyring so its packages install (signed-by that key) at build
    time. An apt_sources entry's repo may already carry its own apt
    one-line [options] block (e.g. an operator-authored signed-by=);
    the renderer adapts to the line's existing shape instead of
    unconditionally appending a second [options] block (apt allows only
    one, and two make the line unparseable) — no block gets one added, a
    block without signed-by= gets it merged in, and a block that already
    pins signed-by=<path> is left verbatim with the fetched key written
    to that path's staging equivalent. Baked packages: entries that are
    null/empty (e.g. a stray - in the YAML list) are stripped during the
    build render rather than baked in as a literal "None" package name.

  • Immutable base + whole-file image identity (issue #179). The image
    cache key + filename is a whole-file, raw-byte hash of the BAKE
    files
    — no key-picking, no canonicalization. Placement of a key in a
    bake file IS the classification, made once by the operator: a knob in
    the wrong file loudly does nothing instead of silently poisoning the
    cache. Because the hash is over raw bytes, list order, key order,
    whitespace, and even a trailing-newline toggle all change it — the
    trailing-newline toggle is the documented force-rebuild lever. The
    shape:

    • a repo without a .claude-vm/config-bake.yml shares one image
      keyed on the GLOBAL bake file's hash: guest+global<hash>.raw,
      version BASE_OS_REV+launcherN+global<hash> (an absent global bake
      file hashes to the 00000000 sentinel);
    • a repo that ships a .claude-vm/config-bake.yml appends its own
      segment — the repo NAME plus a hash of the repo bake file —
      guest+global<hash>+<reponame>-<repohash>.raw, so the filename tells
      you whose override runs where. The repo segment's PRESENCE is gated
      on the bake FILE existing (not its content), so two repos with
      byte-identical repo-bake files still get two images (the name
      disambiguates): legibility over dedup, an explicit choice.

    Editing a boot file never changes identity and never rebuilds;
    editing a bake file (including only its trailing newline) does.
    guest_image, when set, opts out of identity derivation and is
    used verbatim.

    The cached base .raw is immutable and is NEVER attached to a VM:
    each run APFS-clones it (cp -c, instant zero-copy) into the run dir
    and boots the CLONE. N concurrent sessions cost one base plus each
    session's written blocks — no cross-session/cross-repo state leakage
    (OAuth credential, identity seed, transcripts, boot-installed packages)
    and no multi-writer corruption on a shared image. The clone is
    discarded on a clean exit and retained (path logged) on an abnormal one
    for forensics. There is no host-driven forced stop: the guest halts
    itself and vfkit (running foreground) exits on its own, so the
    launcher's sync in cleanup simply narrows the window in which writes
    in flight to the clone are still unflushed when the guest goes away.

  • Ending a session (issue #179). The guest decides its own fate from
    claude's exit status; there is no host→guest shutdown channel.

    • A deliberate quit powers the guest off. Ctrl-D Ctrl-D, /exit,
      and Ctrl-C Ctrl-C all exit claude 0, and on 0 the guest starts
      systemd's ordered poweroff (SIGRTMIN+4 to PID 1 — the bus-less path,
      so no spurious "Failed to connect to bus" error on a guest that ships
      no dbus). vfkit then exits on its own, control returns to
      the claude-vm launcher on the host, your terminal is restored, the
      per-run clone is discarded, and the copy-back step runs. This is the
      normal way to end a session — nothing on the host needs to be killed.
    • Ctrl-C belongs to the guest claude. The launcher disables
      isig/ixon on the host tty for the session, so Ctrl-C (and
      Ctrl-Z/Ctrl-\/Ctrl-S/Ctrl-Q) travel to the guest as bytes
      instead of signalling host-side vfkit — the first Ctrl-C shows
      claude's press-again warning, the second exits 0 and powers off, same
      as Ctrl-D Ctrl-D. Consequence: the keyboard cannot abort a *wedged*
      guest from that terminal; the recovery path is kill <vfkit pid>
      from another terminal (vfkit tears the guest down within ~5s and the
      launcher cleans up normally). The saved tty state is restored on
      every exit path.
    • An abnormal claude death drops you into a guest shell. If claude
      exits nonzero (a crash, an OOM kill, or declining the
      bypass-permissions dialog — the easy way to try this path), the guest
      does not power off yet. The boot launcher hands you an
      interactive root login shell on the same console you were already
      attached to
      , so you can run a post-mortem inside the still-running
      guest: inspect /mnt/repo, see how the clone diverged, read dmesg,
      check whether the network wiring survived. claude is not
      relaunched — there is no respawn loop. Exiting that shell powers
      the guest off
      and returns control to the host launcher; the clone
      is retained (its path is logged) for further forensics.
  • Boot-time package install/update (issue #106). A boot file's
    packages: and update_at_boot do not feed the
    image-identity hash — they
    run a blocking phase in the boot launcher itself, right before claude launches,
    through the same proxy the rest of the guest's egress goes through. The
    base image DOES need one thing unconditionally to support this phase: apt
    itself, baked into the base Packages= list regardless of whether
    install_at_boot/update_at_boot are configured (mkosi does not otherwise put
    apt/dpkg tooling into the guest rootfs, since it installs baked packages
    from OUTSIDE the image with its own build-container apt) — this is covered
    by LAUNCHER_LOGIC_REV, the base-version pin, not by the image-identity
    hash.

    The phase runs apt-get update and apt-get -y upgrade under
    update_at_boot, then, for a nonempty boot packages list, renders the
    boot-tier apt_sources into the guest's live /etc/apt with the same
    keyring-fetch and sources.list.d shape the image build uses, ported to
    plain bash since the guest carries no python3 or jq, and runs
    apt-get -y install. Both calls pass -o Acquire::http::Proxy= and
    -o Acquire::https::Proxy= at the run's proxy, and the boot launcher
    also writes /etc/apt/apt.conf.d/99claude-vm-proxy, so a mid-session
    apt-get is proxied too; run.env carries lowercase
    http_proxy/https_proxy/no_proxy beside the uppercase forms, since
    apt honours only the lowercase ones. The image's apt sources are
    binary-only (main, updates, security) with no translations or package
    caches, and the phase ends with apt-get clean, keeping the per-boot
    working set near 50 MB. That working set, and anything the session
    writes, lands in a root filesystem the provisioner sizes to a fixed
    floor (ROOT_BASE_FLOOR_MB in payload/provisioners/podman-mkosi.sh)
    plus image.root_headroom_mb of free space. The headroom sizes the
    image, so raising it after a boot-time install hits ENOSPC rebuilds the
    image. A failed update or install warns on the boot
    console and the session continues. add_apt_uris_to_allowlist's
    derivation runs after the warm-boot drop of claude.ai and
    downloads.claude.ai, so it never re-adds a host that step removed.

  • On startup, the launcher ensures the image exists and matches the
    pinned version
    . If the resolved image is missing or version-mismatched,
    it builds the image (payload/build-guest-image.sh --output …, passing the
    merged bake config through CLAUDE_VM_BAKE_CONFIG and the pre-computed
    image-identity segments through CLAUDE_VM_IMAGE_IDENTITY_SEGMENTS) rather
    than erroring.
    The image's pinned version is stamped at <image>.version.

  • No image artifact is committed to the repo, and there is no
    publish-prebuilt-image path. Every machine builds its own.

The provisioning step that produces the bootable raw image defaults to
the bundled payload/provisioners/podman-mkosi.sh: mkosi run inside a
throwaway rootless podman container (Debian Trixie build container,
systemd ≥ 254 for the offline, loop-device-free RepartOffline=yes
path), emitting a raw EFI-bootable Debian guest with the boot launcher
wired as the autologin serial-getty@hvc1 login program (so claude
becomes the interactive hvc1 console session — issue #88), plus an
unlocked passwordless root (RootPassword=hashed:). vfkit boots it
--bootloader efi. build-guest-image.sh pins the version and emits the
boot launcher, then hands <boot-launcher-path> <output-image-path> to
the provisioner. The CLAUDE_VM_IMAGE_PROVISIONER env var overrides the
bundled default with your own script honoring the same two-argument
contract.

The launcher captures the booting guest's boot serial console
(hvc0) to $CLAUDE_VM_STATE_DIR/logs/<run-id>/guest-console.log via
the first vfkit --device virtio-serial,logFilePath=…. The recipe KernelCommandLine sets
console=hvc0, so all kernel/systemd boot output — and the boot
launcher's diagnostic/seam lines, which it writes explicitly to
/dev/console — are observable from the host instead of being
discarded, while staying off the interactive hvc1 terminal. The path
is reported on exit and retained in the run's log dir, beside the
gvproxy and proxy logs and the egress capture, where reaping the run
does not reach it.

Verified claude cache

The host fetches, verifies and caches the claude binary the guest runs,
and the guest never runs install.sh. For claude.version:

  1. resolve the channel or pin to a concrete version, the cache key;
  2. download that version's manifest.json and manifest.json.sig;
  3. gpg --verify the signature and require, from gpg's --status-fd
    stream, a VALIDSIG whose fingerprint is the pinned
    claude.signing_key_fingerprint — a bare gpg --verify accepts a
    valid signature by any key in the keyring;
  4. read the linux-arm64 SHA256 from the verified manifest;
  5. download the binary and verify its SHA256;
  6. cache it under $CLAUDE_VM_STATE_DIR/cache/<version>/linux-arm64/claude
    and share it into the guest (mountTag=claudebin), where the image's
    fstab mounts it ro.

A failed verify, a checksum mismatch, or an unset pin aborts the launch
before anything unverified is cached or run. There is no lower-trust
fallback: the signed manifest is the only trust path. This runs before
the image build, since the build's plugin bake step drives the same
binary, so a verification failure aborts before a multi-minute build.

The operator's one-time setup imports the signing key, reads its
fingerprint, verifies that fingerprint out of band, and pins it as
claude.signing_key_fingerprint:

curl -fsSL https://downloads.claude.ai/keys/claude-code.asc | gpg --import
gpg --fingerprint claude-code

On a warm boot — the resolved version already cached — nothing is
re-downloaded, gpg does not run, and the launcher drops claude.ai and
downloads.claude.ai from the guest's egress allowlist.

Authentication (secrets)

This section covers the two credentials the launcher handles itself: the
host's claude.ai OAuth credential, and (under github.auth: host-token) a
GitHub token. Any other third-party key — an OpenRouter or Tavily key for
an in-guest tool, MCP server or model provider — reaches the guest through
env.copy / env.files instead; see Guest environment variables above,
which carries the same "never in config, never in run.env, shredded on
exit" posture.

The guest authenticates claude with the host operator's live claude.ai
OAuth credential
— the full-scope login credential, not a scoped
inference token — installed at $HOME/.claude/.credentials.json. That
bearer token alone is not sufficient for the interactive TUI to treat
itself as onboarded and logged in: current Claude Code also reads
onboarding + identity state from ~/.claude.json, which a fresh throwaway
guest lacks — so without it every launch hits the onboarding/login wall
despite the mounted credential. Two keys matter beyond identity:
hasCompletedOnboarding (absent → claude runs its onboarding flow) and
autoUpdates (unset → claude tries to self-update and fails against its
RO-mounted binary in the egress-confined guest).

So the launcher also seeds the guest's identity + onboarding state
(issue #88): it reads your host ~/.claude.json and emits a seed carrying
userID and oauthAccount selected from the host, plus four synthesized
keys: hasCompletedOnboarding: true (skip the wall), autoUpdates: false
(no self-update), and lastOnboardingVersion / lastReleaseNotesSeen
stamped with the concrete resolved claude version. It additively
carries benign host UI keys when present — installMethod,
hasSeenTasksHint, hasUsedStash, tipsHistory (each silently omitted
when absent) — and seeds a projects entry for the guest mount
(/mnt/repo) with hasTrustDialogAccepted / hasCompletedProjectOnboarding
forced true so the guest skips the "Do you trust this folder? /mnt/repo"
dialog (if the host already has an entry for the launched repo, a named
allowlist
of benign per-project keys — allowedTools and friends —
survives, rekeyed to /mnt/repo with those two flags forced true; the
operator's prompt history, lastSessionId, and mcpServers are
deliberately dropped, and unrecognized future keys default to excluded).
Nothing else from ~/.claude.json (no other projects{} entries, no
telemetry, no machineID) is copied;
machineID is deliberately not seeded — the guest mints its own. That
object is shared into the guest under the same claudecreds mount, and
the guest boot launcher installs it at $HOME/.claude.json (mode 0600)
before launching claude, so the in-guest session comes up already
onboarded, logged in, folder-trusted, and with self-update disabled. The
seed is built via lib/credential.sh's claude_vm_select_claude_json_seed
(using python3; unit-tested in payload/test/credential-test.sh) and
carries account identity, so it rides the same secret posture as the
credential: written under umask 077 into the transient, owner-only
(0600), shred-on-exit claudecreds mount, never into run.env or the
verified-binary cache. A preflight aborts the run with an actionable
message if the host ~/.claude.json is missing or lacks a usable
userID/oauthAccount (i.e. you are not logged in on the host).

The launcher also quiets claude's startup install-health check
(issue #88): claude probes for a working claude at the native installer's
~/.local/bin/claude, but the guest runs the RO-mounted binary from
/mnt/claudebin, so that path is empty and the TUI prints two claude command at /root/.local/bin/claude missing or broken · run claude install to repair warnings. The guest boot launcher symlinks $HOME/.local/bin/claude
→ the verified RO-mounted binary right after the claude-fetch seam validates
it; the symlink target is the running binary, so the version comparison
passes by construction and autoUpdates: false plus the RO mount prevent
write-through (empirically confirmed to clear the warnings on real hardware).
Belt-and-braces with the seeded autoUpdates: false, the launcher also
writes the documented DISABLE_AUTOUPDATER=1 env knob into run.env.

A second credential-token preflight guards against a degraded Keychain
entry: the claudeAiOauth object can be structurally complete yet carry
empty accessToken / refreshToken strings (with expiresAt: 0) —
which happens when your host claude sessions coast on the shared auth
daemon's in-memory tokens while the persisted Keychain entry has gone
stale. Booting the guest with it lands at "Not logged in · Run /login",
and an in-guest /login can trip OAuth reuse-detection and revoke your
other live sessions
. So after selecting the credential, the launcher
validates both tokens are non-empty
(claude_vm_validate_claude_credential_tokens) and aborts fast if not,
telling you to re-login on the host (claude then /login, or restart
Claude Code — either repairs the Keychain entry) rather than inside the
guest.

At launch the launcher reads the credential from the macOS login
Keychain by service name alone
(security find-generic-password -s "Claude Code-credentials" -w).
That Keychain item is not only the claude.ai login — its JSON also
carries sibling keys such as mcpOAuth (per-MCP-server OAuth). To avoid
mounting unrelated MCP credentials into the guest, the launcher selects
only the claudeAiOauth key
and writes a file in the shape claude
expects, {"claudeAiOauth": { ... }} (selection via lib/credential.sh,
using python3; unit-tested in payload/test/credential-test.sh). The
selected credential is written to a transient, owner-only (0600)
tmpfile and shared into the guest under mountTag=claudecreds, which the
image's fstab mounts ro
. The ro is guest-side, not host-side — vfkit's
virtio-fs device has no read-only export, so the host shares this exactly as
it shares an extra mount, and the same caveat applies: a guest-side ro
stops an accidental write, not a determined one, since the guest session is
root. Nothing rests on it — the guest boot launcher copies the file into
$HOME/.claude/.credentials.json (mode 0600) before launching
claude.

The credential is a secret and is handled like one: it is never
written to config, to run.env, or to the verified-binary cache; its
host-side tmpfile is created under a tightened umask 077 and removed
by the launcher's cleanup()/trap on every exit. The full raw
Keychain blob (before selection) lives only in a transient tmpfile
outside the guest share and is removed immediately after selection.

Requirements: macOS only (security find-generic-password is a
macOS Keychain tool; python3, used for credential and identity-seed
selection, ships with macOS), and you must be logged in to Claude Code
on the host first. The launcher fails fast with an actionable message if
the host ~/.claude.json is missing or lacks a usable
userID/oauthAccount, or if the Keychain lookup returns empty or
non-zero, or the blob has no usable claudeAiOauth key. egress.allow
must include
the Anthropic API host (api.anthropic.com) so the in-guest claude
can reach it.

Requirements

yq (mikefarah v4.54.3 or a later v4), git, python3 (stock on
macOS; used to select the claudeAiOauth key from the Keychain blob — see "Authentication
(secrets)" above), gpg (brew install gnupg, for the host-side verified claude
cache), a sha256
tool (shasum / sha256sum, both stock on macOS/Linux), and — for an
actual VM boot — vfkit and tinyproxy (for the bundled default
proxy.cmd). A launch that has to build the guest image is the only
one that runs podman, for the bundled podman-mkosi provisioner; the
podman formula is in practice a requirement of every launch regardless,
because that is where gvproxy normally comes from (next paragraph). What
a build does
not need is a started podman machine: the launcher inits and starts
one itself and stops it again at end of run if it was the one that
started it (see "The launcher manages the podman machine" below). On a
clean host:
brew install yq git gnupg vfkit podman tinyproxy.

gvproxy is not a separate install and need not be on PATH: it
ships inside the podman Homebrew formula at
<brew-prefix>/libexec/podman/gvproxy and a stock brew install podman
does not symlink it onto PATH. The launcher resolves it automatically
(an explicit on-PATH gvproxy first, then podman's libexec), so
installing podman is enough.

Before any image build, network call, or Keychain read, the launcher
runs a trust-path preflight that checks the local, instant
preconditions for the verified cache and credential selection up front:
gpg on PATH, the claude.signing_key_fingerprint pinned in config,
that pinned fingerprint actually present in the gpg keyring, and
python3 on PATH. Immediately after, a separate identity-seed
preflight
aborts if the host ~/.claude.json is missing or lacks a
usable userID/oauthAccount (i.e. you are not logged in on the host).
Later, once the credential is selected, a credential-token check
aborts if the selected claudeAiOauth carries empty accessToken /
refreshToken (the degraded-Keychain state described under
"Authentication (secrets)"), steering you to re-login on the host.
Each failed check prints the exact remediation
command(s) (e.g. brew install gnupg, the
curl … | gpg --import + gpg --fingerprint pin steps). Without this
gate, a cold boot would otherwise pay for a guest-image build and three
network fetches before aborting on a condition that was knowable at
startup. These are an additive early gate; the deep checks in the
verified cache (gpg-on-PATH and unset-pin hard-abort) and credential
selection (python3) remain as defense-in-depth.

After the trust-path preflight, and still before any build/boot work,
the launcher runs a dependency preflight that checks the VM
toolchain up front (gvproxy resolvable, vfkit on PATH, and — only when
the bundled default proxy is in use — tinyproxy). It fails fast with
one actionable remediation line per missing piece rather than dying deep
in the boot sequence. A custom proxy.cmd owns its own dependencies, so
the tinyproxy check is skipped then.

The config-resolution half (layering, scalar/list resolution) is
exercisable without the virtualization stack; see
payload/test/config-test.sh, and the verified-cache logic (resolve /
verify / checksum / abort / warm-boot) in
payload/test/claude-cache-test.sh.

The per-run endpoint primitives (issue #179) are also exercisable
without a VM: payload/test/endpoint-test.sh covers free-TCP-port
acquisition and TCP/unix-socket liveness (a live listener vs a stale
socket-file corpse, the exact distinction the concurrency fix turns on),
using real perl listeners; payload/test/bin-config-check-test.sh
regression-tests bin/claude-vm's four-file bake/boot config-presence
check so it no longer prints a false "no global config" when the
migrated pair is present. payload/test/cleanup-test.sh covers the
run's run.lock across a kill -9 of the launcher, the watcher
stopping a vfkit stand-in after one, and bin/claude-vm-cleanup over
dead, live and lockless run dirs.

payload/test/podman-mkosi-test.sh regression-tests the recipe the
default provisioner generates (the literal mkosi.conf and
build-in-container.sh), stubbing only podman at the container
handoff — added after a real end-to-end build caught failures (a
backtick-command-substitution bug corrupting mkosi.conf, and a missing
curl/ca-certificates in the build container) that no pure-function
config-test.sh case could catch, since none of them render or execute
the actual generated recipe files.

The end-to-end acceptance test — default-provisioner build, vfkit boot
to the claude-fetch seam (running the host-verified claude off the
mount), egress confinement, and the host-side GPG-verified cache — is
payload/test/host-acceptance.sh; it is host-gated by cause: it skips
cleanly when a required binary is absent,
but a stopped or absent podman machine is not a skip — the test starts
the machine itself and tears down exactly what it changed on exit. A
bring-up the test attempted that then fails (podman machine init/start) is a real failure, not a skip: the test exits non-zero
rather than green-exiting with nothing proven. Diagnostics (including
the machine init/start stderr) are retained under
$CLAUDE_VM_STATE_DIR/logs/<run-id>/ — the state root lib/config.sh
resolves, ~/.local/state/claude-vm by default — so a failed run stays
diagnosable.

payload/test/podman-machine-test.sh covers the launcher's own podman
machine management (issue #215) against a stateful stub podman, and — by
slicing the build-or-reuse block out of claude-vm.sh and running it —
the scoping: a warm-cache launch invokes podman zero times, a
build-needing one inits/starts, builds, and stops again — including when
the bring-up leaves a machine up behind a failure, whether podman machine start itself exits non-zero after bringing it up or the
confirmation that follows fails.

The launcher manages the podman machine

The dependency preflight deliberately checks neither the podman binary
nor any machine state, because only a launch that builds the guest
image runs podman. A warm-cache launch — the image on disk already stamps
the pinned version — boots it with vfkit and invokes podman not once, so
it neither gates on a started machine nor starts one. (The preflight does
check gvproxy, which normally resolves out of podman's Homebrew formula,
so a host with neither podman nor an on-PATH gvproxy still fails there.)

On the build path the launcher brings podman up itself rather than
printing two commands and refusing, since claude-vm is meant to be one
command on a fresh host where podman has never been initialized. The
decision reads podman machine list: no machine listed gets a podman machine init then a podman machine start; a listed-but-stopped machine
gets a start; a running machine is left exactly as found. At end of run
the launcher stops the machine iff it was the one that started it — a
machine found running is left running, and an init'd machine is stopped
rather than removed, so the next build reuses it. The launcher records
that it started the machine before each podman machine start, and arms
the stop before the bring-up, so a start that brings the machine up and
then exits non-zero, or a bring-up whose podman info confirmation
fails, still ends with the machine stopped.

There is no config surface for any of this: it is launcher plumbing, not
policy. Every init/start/stop is logged to stderr as it happens, and
those log lines are its only trace.

Categories