aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xclaude-vm26
-rw-r--r--claude-vm.113
2 files changed, 34 insertions, 5 deletions
diff --git a/claude-vm b/claude-vm
index 3219cfc..c4939ba 100755
--- a/claude-vm
+++ b/claude-vm
@@ -32,6 +32,7 @@ NETWORK_SPECIFIED=false
MACVLAN_PARENT=""
NEW_INSTANCE=false
X11=false
+TMUX=false
# Mount arrays: each entry is "host_path|guest_path|readonly"
MOUNTS=()
@@ -57,6 +58,7 @@ Options:
--network MODE Network mode: 'nat' (default) or 'macvlan' for direct L2 access
--parent IFACE Parent interface for macvlan mode (auto-detected if not specified)
--x11 Enable X11 forwarding (mounts XAUTHORITY and X11 socket)
+ --tmux Create and attach to a tmux session named after the instance
--fresh Remove all existing mount devices before applying new mounts
--bootstrap Create claude user and install claude-code on first boot
--init Initialize guest with config from ~/.config/claude-vm/
@@ -151,6 +153,10 @@ while [[ $# -gt 0 ]]; do
X11=true
shift
;;
+ --tmux)
+ TMUX=true
+ shift
+ ;;
--fresh)
FRESH=true
shift
@@ -452,7 +458,7 @@ if [ "$INIT" = true ]; then
echo "Initializing guest config from ~/.config/claude-vm/..."
_push() { test -f "$1" && incus file push --uid "${GUEST_UID}" --gid "${GUEST_UID}" "$1" "$2" || :; }
CONFIG_DIR="$HOST_HOME/.config/claude-vm"
- _push "$CONFIG_DIR/claude/AGENTS.md" "${INSTANCE_NAME}${GUEST_HOME}/.claude/CLAUDE.vm"
+ _push "$CONFIG_DIR/claude/CLAUDE.md" "${INSTANCE_NAME}${GUEST_HOME}/.claude/CLAUDE.md"
_push "$CONFIG_DIR/claude/settings.json" "${INSTANCE_NAME}${GUEST_HOME}/.claude/settings.json"
_push "$CONFIG_DIR/claude.json" "${INSTANCE_NAME}${GUEST_HOME}/.claude.json"
fi
@@ -463,7 +469,17 @@ INCUS_EXTRA=(--env "PATH=$(printf %s: "${PATH_EXTRA[@]}")$GUEST_PATH" "${INCUS_E
# Run command with provided arguments
GUEST_ARGV=("$COMMAND" "$@")
-incus exec "${INSTANCE_NAME}" --user "${GUEST_UID}" --cwd "${GUEST_HOME}/host" \
- --env ANTHROPIC_API_KEY="${ANTHROPIC_API_KEY}" --env USER="${GUEST_UID}" \
- --env HOME="${GUEST_HOME}" "${INCUS_EXTRA[@]}" \
- -- bash -c "$(declare -p GUEST_ARGV); \"\${GUEST_ARGV[@]}\""
+
+if [ "$TMUX" = true ]; then
+ # Run inside tmux session named after the instance
+ exec tmux new-session -A -s "${INSTANCE_NAME}" \
+ incus exec "${INSTANCE_NAME}" --user "${GUEST_UID}" --cwd "${GUEST_HOME}/host" \
+ --env ANTHROPIC_API_KEY="${ANTHROPIC_API_KEY}" --env USER="${GUEST_UID}" \
+ --env HOME="${GUEST_HOME}" "${INCUS_EXTRA[@]}" \
+ -- bash -c "$(declare -p GUEST_ARGV); \"\${GUEST_ARGV[@]}\""
+else
+ incus exec "${INSTANCE_NAME}" --user "${GUEST_UID}" --cwd "${GUEST_HOME}/host" \
+ --env ANTHROPIC_API_KEY="${ANTHROPIC_API_KEY}" --env USER="${GUEST_UID}" \
+ --env HOME="${GUEST_HOME}" "${INCUS_EXTRA[@]}" \
+ -- bash -c "$(declare -p GUEST_ARGV); \"\${GUEST_ARGV[@]}\""
+fi
diff --git a/claude-vm.1 b/claude-vm.1
index 5506312..8ff1ff3 100644
--- a/claude-vm.1
+++ b/claude-vm.1
@@ -69,6 +69,11 @@ Enable X11 forwarding. Mounts the host's XAUTHORITY file to \fB~/.host/Xauthorit
and \fB/tmp/.X11-unix\fR to \fB~/.host/X11-unix\fR, setting the appropriate
environment variables (DISPLAY and XAUTHORITY) for GUI applications.
.TP
+.B \-\-tmux
+Create and attach to a tmux session named after the instance.
+If the session already exists, attach to it; otherwise create a new session.
+This allows for persistent sessions and easy reconnection.
+.TP
.B \-\-fresh
Remove all existing mount devices before applying new mounts.
.TP
@@ -167,6 +172,14 @@ Bootstrap a fresh image:
claude-vm --image images:archlinux --bootstrap --rw .
.fi
.RE
+.PP
+Run in a persistent tmux session:
+.PP
+.RS
+.nf
+claude-vm --tmux --rw .
+.fi
+.RE
.SH SEE ALSO
.BR incus (1),
.BR claude (1)