跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

提交记录
修改README.md+123 −39看文件
@@ -4,7 +4,9 @@ Run AI coding agents inside sandboxed Linux VMs. The agent gets full autonomy wh
44
55Uses [Lima](https://lima-vm.io/) to create lightweight Debian VMs on macOS and Linux. Ships with dev tools, Docker, and a headless Chrome browser with [Chrome DevTools MCP](https://github.com/ChromeDevTools/chrome-devtools-mcp) pre-configured.
66
7删除:Currently supports [Claude Code](https://claude.ai/code). Other agents (Codex, etc.) can be added in the future.
7新增:Supports [Claude Code](https://claude.ai/code), [OpenCode](https://github.com/opencode-ai/opencode), and [Codex CLI](https://github.com/openai/codex) out of the box. Other agents can be run via `agent-vm shell`.
8新增:
9新增:Never install attack vectors such as npm, claude or even Docker on your host machine again!
810
911Feedbacks welcome!
1012
@@ -12,7 +14,7 @@ Feedbacks welcome!
1214
1315- macOS or Linux
1416- [Lima](https://lima-vm.io/docs/installation/) (installed automatically via Homebrew if available)
15删除:- A [Claude subscription](https://claude.ai/) (Pro, Max, or Team)
17新增:- A subscription or API key for your agent of choice
1618
1719## Install
1820
@@ -21,8 +23,8 @@ git clone https://github.com/sylvinus/agent-vm.git
2123cd agent-vm
2224
2325# Add to your shell config
24删除:echo "source $(pwd)/claude-vm.sh" >> ~/.zshrc # zsh
25删除:echo "source $(pwd)/claude-vm.sh" >> ~/.bashrc # or bash
26新增:echo "source $(pwd)/agent-vm.sh" >> ~/.zshrc # zsh
27新增:echo "source $(pwd)/agent-vm.sh" >> ~/.bashrc # or bash
2628```
2729
2830## Usage
@@ -30,94 +32,178 @@ echo "source $(pwd)/claude-vm.sh" >> ~/.bashrc # or bash
3032### One-time setup
3133
3234```bash
33删除:claude-vm-setup
35新增:agent-vm setup
3436```
3537
36删除:Creates a VM template with dev tools, Docker, Chromium, and Claude Code pre-installed. During setup, Claude will launch once for authentication. After it responds, type `/exit` to continue with the rest of the setup. (We haven't found a way to automate this step yet.)
38新增:Creates a base VM template with dev tools, Docker, Chromium, and AI coding agents pre-installed.
3739
3840Options:
3941
4042| Flag | Description | Default |
4143|------|-------------|---------|
42删除:| `--minimal` | Only install git, curl, jq, and Claude Code. Skips Docker, Node.js, Python, Chromium, and the Chrome MCP server. | off |
4344| `--disk GB` | VM disk size in GB | 20 |
4445| `--memory GB` | VM memory in GB | 8 |
4546
4647```bash
47删除:claude-vm-setup --minimal # Lightweight VM with just Claude
48删除:claude-vm-setup --disk 50 --memory 16 # Larger VM for heavy workloads
48新增:agent-vm setup --disk 50 --memory 16 # Larger VM for heavy workloads
4949```
5050
51删除:### Run Claude in a VM
51新增:### Run an agent in a VM
5252
5353```bash
5454cd your-project
55删除:claude-vm
55新增:agent-vm claude # Claude Code
56新增:agent-vm opencode # OpenCode
57新增:agent-vm codex # Codex CLI
58新增:```
59新增:
60新增:Creates a persistent VM for the current directory (or reuses it if one already exists), mounts your working directory, and runs the agent with full permissions. The VM persists after the agent exits so you can reconnect later.
61新增:
62新增:Each agent runs with its respective auto-approve flag:
63新增:- `claude` runs with `--dangerously-skip-permissions`
64新增:- `opencode` runs with `--dangerously-skip-permissions`
65新增:- `codex` runs with `--full-auto`
66新增:
67新增:Any extra arguments are forwarded to the agent command:
68新增:
69新增:```bash
70新增:agent-vm claude -p "fix all lint errors" # Run with a prompt
71新增:agent-vm claude --resume # Resume previous session
72新增:agent-vm opencode -p "refactor auth module" # OpenCode with a prompt
73新增:agent-vm codex -q "explain this codebase" # Codex with a query
74新增:```
75新增:
76新增:### Shell access
77新增:
78新增:```bash
79新增:agent-vm shell
5680```
5781
58删除:Clones the template into a fresh VM, mounts your current directory, and runs `claude --dangerously-skip-permissions`. The VM is deleted when Claude exits.
82新增:Opens a zsh shell in the same persistent VM for the current directory. Useful for debugging, running commands alongside an agent, or using agents not built in.
83新增:
84新增:### VM lifecycle
5985
60删除:Any arguments passed to `claude-vm` are forwarded to the `claude` command:
86新增:Each directory gets its own persistent VM. You can manage it with:
6187
6288```bash
63删除:claude-vm -p "fix all lint errors" # Run with a prompt
64删除:claude-vm --resume # Resume previous session
65删除:claude-vm -c "explain this codebase" # Continue conversation
89新增:agent-vm status # Show VM status for the current directory
90新增:agent-vm stop # Stop the VM (can be restarted later)
91新增:agent-vm destroy # Stop and permanently delete the VM
6692```
6793
68删除:### Debug shell
94新增:To resize an existing VM's disk or memory, just pass `--disk` or `--memory` again — the VM will be stopped, reconfigured, and restarted automatically:
6995
7096```bash
71删除:claude-vm-shell
97新增:agent-vm --disk 50 claude # Grow disk to 50GB, then run Claude
98新增:agent-vm --memory 16 shell # Increase memory to 16GB, then open shell
7299```
73100
74删除:Same as `claude-vm` but drops you into a bash shell instead.
101新增:Note: disk can only be grown, not shrunk.
102新增:
103新增:Running `agent-vm setup` again updates the base template but does **not** update existing VMs. You'll see a warning when using a VM cloned from an older base. Use `--reset` to re-clone:
104新增:
105新增:```bash
106新增:agent-vm --reset claude # Destroy and re-clone VM, then run Claude
107新增:```
75108
76109## Customization
77110
78删除:### Per-user: `~/.claude-vm.setup.sh`
111新增:### Per-user: `~/.agent-vm.setup.sh`
79112
80删除:Create this file in your home directory to install extra tools into the VM template. It runs once during `claude-vm-setup`, as the default VM user (with sudo available):
113新增:Create this file in your home directory to install extra tools into the base VM template. It runs once during `agent-vm setup`, as the default VM user (with sudo available):
81114
82115```bash
83删除:# ~/.claude-vm.setup.sh
116新增:# ~/.agent-vm.setup.sh
84117sudo apt-get install -y postgresql-client
85118pip install pandas numpy
86119```
87120
88删除:### Per-project: `.claude-vm.runtime.sh`
121新增:### Per-project: `.agent-vm.runtime.sh`
89122
90删除:Create this file at the root of any project. It runs inside the cloned VM each time you call `claude-vm`, just before Claude starts. Use it for project-specific setup like installing dependencies or starting services:
123新增:Create this file at the root of any project. It runs inside the VM each time a new VM is created for the project, just before you get access. Use it for project-specific setup like installing dependencies or starting services:
91124
92125```bash
93删除:# your-project/.claude-vm.runtime.sh
126新增:# your-project/.agent-vm.runtime.sh
94127npm install
95128docker compose up -d
96129```
97130
131新增:### MCP servers
132新增:
133新增:The base VM comes with [Chrome DevTools MCP](https://github.com/ChromeDevTools/chrome-devtools-mcp) pre-configured for Claude, giving the agent headless browser access.
134新增:
135新增:To add more MCP servers, add them to `~/.claude.json` in your `~/.agent-vm.setup.sh`, or edit the file directly inside a VM via `agent-vm shell`. Add entries to the `mcpServers` object:
136新增:
137新增:```json
138新增:{
139新增: "mcpServers": {
140新增: "chrome-devtools": {
141新增: "command": "npx",
142新增: "args": ["-y", "chrome-devtools-mcp@latest", "--headless=true", "--isolated=true"]
143新增: },
144新增: "postgres": {
145新增: "command": "npx",
146新增: "args": ["-y", "@modelcontextprotocol/server-postgres", "postgresql://localhost:5432/mydb"]
147新增: }
148新增: }
149新增:}
150新增:```
151新增:
152新增:## Shared configuration
153新增:
154新增:The VM mounts your host's `~/.claude/` directory. Login credentials, skills, user-level `CLAUDE.md`, conversation history, and settings all persist across VMs automatically.
155新增:
156新增:On first use, you'll need to authenticate. Credentials are stored in `~/.claude/.credentials.json` and reused by all subsequent VMs.
157新增:
158新增:This also means the configuration is shared with any Claude Code installation on the host — though we recommend running Claude exclusively in VMs for security.
159新增:
98160## How it works
99161
100删除:1. **`claude-vm-setup`** creates a Debian 13 VM with Lima, installs dev tools + Chrome + Claude Code, and stops it as a reusable template
101删除:2. **`claude-vm [args]`** clones the template, mounts your working directory read-write, runs optional `.claude-vm.runtime.sh`, then launches Claude with full permissions (forwarding any arguments to the `claude` command)
102删除:3. On exit, the cloned VM is stopped and deleted. The template persists for reuse
162新增:1. **`agent-vm setup`** creates a Debian 13 VM with Lima, runs `agent-vm.setup.sh` inside it to install dev tools + Chrome + agents, and stops it as a reusable base template
163新增:2. **`agent-vm claude|opencode|codex [args]`** clones the base template into a persistent per-directory VM, mounts your working directory and `~/.claude/`, runs optional `.agent-vm.runtime.sh`, then launches the agent with full permissions
164新增:3. The VM persists after exit. Running any agent command or `agent-vm shell` in the same directory reuses the same VM
165新增:4. Use `agent-vm stop` to stop the VM or `agent-vm destroy` to delete it
103166
104167Ports opened inside the VM (e.g. by Docker containers) are automatically forwarded to your host by Lima.
105168
106删除:## What's in the VM
169新增:## Project structure
170新增:
171新增:| File | Description |
172新增:|------|-------------|
173新增:| `agent-vm.sh` | Main script — source this in your shell config |
174新增:| `agent-vm.setup.sh` | Package installation script that runs inside the base VM during setup |
175新增:
176新增:## What's in the VM by default
107177
108178| Category | Packages |
109179|----------|----------|
110删除:| Core | git, curl, wget, build-essential, jq |
180新增:| Core | git, curl, wget, jq, build-essential, unzip, zip |
111181| Python | python3, pip, venv |
112删除:| Node.js | Node.js 22 (via NodeSource) |
182新增:| Node.js | Node.js 24 LTS (via NodeSource) |
113183| Search | ripgrep, fd-find |
184新增:| Utilities | htop, GitHub CLI (gh) |
114185| Browser | Chromium (headless), xvfb |
115186| Containers | Docker Engine, Docker Compose |
116删除:| AI | Claude Code, Chrome DevTools MCP server |
187新增:| AI | Claude Code, OpenCode, Codex CLI, Chrome DevTools MCP server |
117188
118删除:## Why a VM?
189新增:## Security model
119190
120删除:Running an AI agent with full permissions is powerful but risky. Here's how the options compare:
191新增:AI coding agents need full permissions to be useful — they install dependencies, run builds, execute tests, start servers. But running `npm install` or `pip install` means executing arbitrary third-party code on your machine.
192新增:
193新增:This is not a theoretical risk. The [Shai-Hulud](https://unit42.paloaltonetworks.com/npm-supply-chain-attack/) worm compromised thousands of npm packages in 2025 by injecting malicious code that runs during `npm install`. It harvested npm tokens, GitHub PATs, SSH keys, and cloud credentials from developers' machines, then used those credentials to spread to other packages the developer maintained. All of this happened silently, in the background, while the legitimate install appeared normal.
194新增:
195新增:An AI agent running with `--dangerously-skip-permissions` on your host would give such an attack full access to everything: your SSH keys, your cloud credentials, your browser sessions, your entire filesystem.
196新增:
197新增:**agent-vm keeps your credentials on the host and runs all code inside the VM.** The VM only has access to:
198新增:
199新增:- Your project directory (read-write mount)
200新增:- `~/.claude/` for agent credentials and settings
201新增:
202新增:It has **no access** to your SSH keys, npm tokens, cloud credentials, git config, browser sessions, or anything else on your host. If a supply chain attack executes inside the VM, it finds nothing to steal (except your source code) and nowhere to spread.
203新增:
204新增:Meanwhile, your host machine stays clean. You don't need Node.js, Docker, or any dev tooling installed locally. The only host dependency is Lima. Your SSH keys and signing credentials never enter the VM as we recommend running `git commit` on the host yourself.
205新增:
206新增:### Why not Docker?
121207
122208| | No sandbox | Docker | VM (agent-vm) |
123209|---|---|---|---|
@@ -129,13 +215,11 @@ Running an AI agent with full permissions is powerful but risky. Here's how the
129215| Protection from container escapes | None | None | Yes |
130216| Browser / GUI tools | Host only | Complex setup | Built-in (headless Chromium) |
131217
132删除:Docker containers share the host kernel, so a motivated agent could exploit kernel vulnerabilities or misconfigurations to escape. A VM runs its own kernel — even if the agent gains root inside the VM, it can't reach the host.
133删除:
134删除:A VM also avoids the practical headaches of Docker sandboxing. Docker runs natively inside the VM without Docker-in-Docker hacks or socket mounts. Headless Chromium works out of the box without fiddling with `--no-sandbox` flags or shared memory settings. Lima automatically forwards ports from the VM to your host, so if the agent starts a server on port 3000, it's immediately accessible at `localhost:3000`. The agent gets a normal Linux environment where everything just works.
218新增:Docker containers share the host kernel. A motivated attacker (or a compromised dependency running inside the container) could exploit kernel vulnerabilities to escape. A VM runs its own kernel — even root access inside the VM can't reach the host.
135219
136删除:Finally, using a VM means you don't need Node.js, npm, Docker, or any other dev tooling installed on your host machine. The only host dependency is Lima. All the tools (and their vulnerabilities) live inside the VM.
220新增:A VM also avoids the practical headaches of Docker sandboxing. Docker runs natively inside the VM without Docker-in-Docker hacks. Headless Chromium works out of the box. Lima automatically forwards ports to your host. The agent gets a normal Linux environment where everything just works.
137221
138删除:For AI agents running with `--dangerously-skip-permissions`, a VM is the only sandbox that provides meaningful security.
222新增:This workflow also replaces Docker Desktop on the Mac, which has become more and more bloated over the years.
139223
140224## License
141225
新增agent-vm.setup.sh+101 −0看文件
@@ -0,0 +1,101 @@
1新增:#!/usr/bin/env bash
2新增:#
3新增:# agent-vm.setup.sh: Package installation script that runs inside the base VM
4新增:# Part of https://github.com/sylvinus/agent-vm
5新增:#
6新增:# This script is executed inside the VM during "agent-vm setup".
7新增:#
8新增:
9新增:set -euo pipefail
10新增:
11新增:export DEBIAN_FRONTEND=noninteractive
12新增:
13新增:# Disable needrestart's interactive prompts
14新增:sudo mkdir -p /etc/needrestart/conf.d
15新增:echo '$nrconf{restart} = '"'"'a'"'"';' | sudo tee /etc/needrestart/conf.d/no-prompt.conf > /dev/null
16新增:
17新增:echo "Installing base packages..."
18新增:sudo apt-get update
19新增:sudo apt-get install -y \
20新增: git curl jq zsh \
21新增: wget build-essential \
22新增: python3 python3-pip python3-venv \
23新增: ripgrep fd-find htop \
24新增: unzip zip \
25新增: ca-certificates
26新增:
27新增:# Set zsh as default shell
28新增:sudo chsh -s /usr/bin/zsh "$(whoami)"
29新增:
30新增:# Install Docker from official repo (includes docker compose)
31新增:echo "Installing Docker..."
32新增:sudo install -m 0755 -d /etc/apt/keyrings
33新增:sudo curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc
34新增:sudo chmod a+r /etc/apt/keyrings/docker.asc
35新增:echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
36新增:sudo apt-get update
37新增:sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin
38新增:sudo usermod -aG docker "$(whoami)"
39新增:
40新增:# Install Node.js 24 LTS (needed for MCP servers)
41新增:echo "Installing Node.js 24..."
42新增:curl -fsSL https://deb.nodesource.com/setup_24.x | sudo -E bash -
43新增:sudo apt-get install -y nodejs
44新增:
45新增:# Install Chromium and dependencies for headless browsing
46新增:echo "Installing Chromium..."
47新增:sudo apt-get install -y chromium fonts-liberation xvfb
48新增:sudo ln -sf /usr/bin/chromium /usr/bin/google-chrome
49新增:sudo ln -sf /usr/bin/chromium /usr/bin/google-chrome-stable
50新增:sudo mkdir -p /opt/google/chrome
51新增:sudo ln -sf /usr/bin/chromium /opt/google/chrome/chrome
52新增:
53新增:# Install GitHub CLI from official repo
54新增:echo "Installing GitHub CLI..."
55新增:sudo mkdir -p -m 755 /etc/apt/keyrings
56新增:wget -qO- https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo tee /etc/apt/keyrings/githubcli-archive-keyring.gpg > /dev/null
57新增:sudo chmod go+r /etc/apt/keyrings/githubcli-archive-keyring.gpg
58新增:echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
59新增:sudo apt-get update
60新增:sudo apt-get install -y gh
61新增:
62新增:# Install Claude Code
63新增:echo "Installing Claude Code..."
64新增:curl -fsSL https://claude.ai/install.sh | bash
65新增:echo 'export PATH=$HOME/.local/bin:$HOME/.claude/local/bin:$PATH' >> ~/.zshrc
66新增:echo 'export PS1="vm:%1~%% "' >> ~/.zshrc
67新增:
68新增:# Install OpenCode
69新增:echo "Installing OpenCode..."
70新增:curl -fsSL https://raw.githubusercontent.com/opencode-ai/opencode/refs/heads/main/install | bash
71新增:echo 'export PATH=$HOME/.opencode/bin:$PATH' >> ~/.zshrc
72新增:
73新增:# Add PATH to .zshenv so non-interactive shells (limactl shell vmname cmd) also find the tools
74新增:echo 'export PATH=$HOME/.local/bin:$HOME/.claude/local/bin:$HOME/.opencode/bin:$PATH' >> ~/.zshenv
75新增:
76新增:# Install Codex CLI
77新增:echo "Installing Codex CLI..."
78新增:sudo npm i -g @openai/codex
79新增:
80新增:# Configure Chrome DevTools MCP server for Claude
81新增:echo "Configuring Chrome MCP server..."
82新增:CONFIG="$HOME/.claude.json"
83新增:if [ -f "$CONFIG" ]; then
84新增: jq '.mcpServers["chrome-devtools"] = {
85新增: "command": "npx",
86新增: "args": ["-y", "chrome-devtools-mcp@latest", "--headless=true", "--isolated=true"]
87新增: }' "$CONFIG" > "$CONFIG.tmp" && mv "$CONFIG.tmp" "$CONFIG"
88新增:else
89新增: cat > "$CONFIG" << 'JSON'
90新增:{
91新增: "mcpServers": {
92新增: "chrome-devtools": {
93新增: "command": "npx",
94新增: "args": ["-y", "chrome-devtools-mcp@latest", "--headless=true", "--isolated=true"]
95新增: }
96新增: }
97新增:}
98新增:JSON
99新增:fi
100新增:
101新增:echo "VM setup complete."
新增agent-vm.sh+461 −0看文件
@@ -0,0 +1,461 @@
1新增:#!/usr/bin/env bash
2新增:#
3新增:# agent-vm: Run AI coding agents inside sandboxed Lima VMs
4新增:# Part of https://github.com/sylvinus/agent-vm
5新增:#
6新增:# Source this file in your shell config:
7新增:# source /path/to/agent-vm/agent-vm.sh
8新增:#
9新增:# Usage:
10新增:# agent-vm setup - Create the base VM template (run once)
11新增:# agent-vm claude - Run Claude Code in a persistent VM for cwd
12新增:# agent-vm opencode - Run OpenCode in a persistent VM for cwd
13新增:# agent-vm codex - Run Codex CLI in a persistent VM for cwd
14新增:# agent-vm shell - Open a shell in the persistent VM for cwd
15新增:# agent-vm stop - Stop the VM for cwd
16新增:# agent-vm destroy - Stop and delete the VM for cwd
17新增:# agent-vm list - List all agent-vm VMs
18新增:# agent-vm status - Show VM status for cwd
19新增:# agent-vm help - Show help
20新增:#
21新增:
22新增:AGENT_VM_TEMPLATE="agent-vm-base"
23新增:AGENT_VM_STATE_DIR="${HOME}/.agent-vm"
24新增:AGENT_VM_CONFIG_DIR="${HOME}/.claude"
25新增:AGENT_VM_SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)"
26新增:
27新增:# Generate a deterministic VM name for a directory
28新增:_agent_vm_name() {
29新增: local dir="${1:-$(pwd)}"
30新增: local hash
31新增: hash=$(echo -n "$dir" | shasum -a 256 | cut -c1-8)
32新增: local base
33新增: base=$(basename "$dir" | tr -cs 'a-zA-Z0-9' '-' | sed 's/^-//;s/-$//')
34新增: echo "agent-vm-${base}-${hash}"
35新增:}
36新增:
37新增:# Check if a VM exists (any state)
38新增:_agent_vm_exists() {
39新增: limactl list -q 2>/dev/null | grep -q "^${1}$"
40新增:}
41新增:
42新增:# Check if a VM is running
43新增:_agent_vm_running() {
44新增: limactl list --format '{{.Name}} {{.Status}}' 2>/dev/null | grep -q "^${1} Running$"
45新增:}
46新增:
47新增:# Ensure the VM for cwd exists and is running, creating/starting as needed
48新增:# Usage: _agent_vm_ensure_running <vm_name> <host_dir> [--disk GB] [--memory GB] [--reset]
49新增:_agent_vm_ensure_running() {
50新增: local vm_name="$1"
51新增: local host_dir="$2"
52新增: shift 2
53新增: local disk="" memory="" reset=""
54新增: while [[ $# -gt 0 ]]; do
55新增: case "$1" in
56新增: --disk) disk="$2"; shift 2 ;;
57新增: --memory) memory="$2"; shift 2 ;;
58新增: --reset) reset=1; shift ;;
59新增: *) shift ;;
60新增: esac
61新增: done
62新增:
63新增: if ! limactl list -q 2>/dev/null | grep -q "^${AGENT_VM_TEMPLATE}$"; then
64新增: echo "Error: Base VM not found. Run 'agent-vm setup' first." >&2
65新增: return 1
66新增: fi
67新增:
68新增: mkdir -p "$AGENT_VM_CONFIG_DIR"
69新增:
70新增: # Destroy existing VM if --reset was requested
71新增: if [[ -n "$reset" ]] && _agent_vm_exists "$vm_name"; then
72新增: echo "Resetting VM '$vm_name'..."
73新增: limactl stop "$vm_name" &>/dev/null
74新增: limactl delete "$vm_name" --force &>/dev/null
75新增: rm -f "$AGENT_VM_STATE_DIR/.agent-vm-version-${vm_name}"
76新增: fi
77新增:
78新增: if ! _agent_vm_exists "$vm_name"; then
79新增: echo "Creating VM '$vm_name'..."
80新增: local clone_args=(
81新增: --set ".mounts=[{\"location\":\"${host_dir}\",\"writable\":true},{\"location\":\"${AGENT_VM_CONFIG_DIR}\",\"mountPoint\":\"/home/${USER}.linux/.claude\",\"writable\":true}]"
82新增: --tty=false
83新增: )
84新增: [[ -n "$disk" ]] && clone_args+=(--set ".disk=\"${disk}GiB\"")
85新增: [[ -n "$memory" ]] && clone_args+=(--set ".memory=\"${memory}GiB\"")
86新增: limactl clone "$AGENT_VM_TEMPLATE" "$vm_name" "${clone_args[@]}" &>/dev/null
87新增: # Record which base version this VM was cloned from
88新增: local base_ver="$AGENT_VM_STATE_DIR/.agent-vm-base-version"
89新增: if [[ -f "$base_ver" ]]; then
90新增: cp "$base_ver" "$AGENT_VM_STATE_DIR/.agent-vm-version-${vm_name}"
91新增: fi
92新增: elif [[ -n "$disk" || -n "$memory" ]]; then
93新增: # Auto-resize existing VM if --disk or --memory changed
94新增: local edit_args=()
95新增: [[ -n "$disk" ]] && edit_args+=(--set ".disk=\"${disk}GiB\"")
96新增: [[ -n "$memory" ]] && edit_args+=(--set ".memory=\"${memory}GiB\"")
97新增: if _agent_vm_running "$vm_name"; then
98新增: echo "VM '$vm_name' is currently running. It must be stopped to apply new resource settings."
99新增: printf "Stop the VM and apply changes? [y/N] "
100新增: local reply
101新增: read -r reply
102新增: if [[ ! "$reply" =~ ^[Yy]$ ]]; then
103新增: echo "Aborted. Starting with current settings."
104新增: return 0
105新增: fi
106新增: echo "Stopping VM..."
107新增: limactl stop "$vm_name" &>/dev/null
108新增: fi
109新增: echo "Updating VM resources..."
110新增: limactl edit "$vm_name" "${edit_args[@]}" &>/dev/null
111新增: fi
112新增:
113新增: # Warn if this VM was cloned from an older base
114新增: local base_ver="$AGENT_VM_STATE_DIR/.agent-vm-base-version"
115新增: local vm_ver="$AGENT_VM_STATE_DIR/.agent-vm-version-${vm_name}"
116新增: if [[ -f "$base_ver" ]] && { [[ ! -f "$vm_ver" ]] || [[ "$(cat "$base_ver")" != "$(cat "$vm_ver")" ]]; }; then
117新增: echo "Warning: Base VM has been updated since this VM was cloned. Use --reset to re-clone from the new base." >&2
118新增: fi
119新增:
120新增: if ! _agent_vm_running "$vm_name"; then
121新增: echo "Starting VM '$vm_name'..."
122新增: limactl start "$vm_name" &>/dev/null
123新增: fi
124新增:
125新增: # Run project-specific runtime script if it exists
126新增: if [ -f "${host_dir}/.agent-vm.runtime.sh" ]; then
127新增: echo "Running project runtime setup..."
128新增: limactl shell --workdir "$host_dir" "$vm_name" zsh -l < "${host_dir}/.agent-vm.runtime.sh"
129新增: fi
130新增:}
131新增:
132新增:agent-vm() {
133新增: local vm_opts=()
134新增: # Parse global options before the subcommand
135新增: while [[ $# -gt 0 ]]; do
136新增: case "$1" in
137新增: --disk)
138新增: vm_opts+=(--disk "$2"); shift 2 ;;
139新增: --disk=*)
140新增: vm_opts+=(--disk "${1#*=}"); shift ;;
141新增: --memory)
142新增: vm_opts+=(--memory "$2"); shift 2 ;;
143新增: --memory=*)
144新增: vm_opts+=(--memory "${1#*=}"); shift ;;
145新增: --reset)
146新增: vm_opts+=(--reset); shift ;;
147新增: *)
148新增: break ;;
149新增: esac
150新增: done
151新增:
152新增: local cmd="${1:-help}"
153新增: shift 2>/dev/null || true
154新增:
155新增: case "$cmd" in
156新增: setup)
157新增: _agent_vm_setup "${vm_opts[@]}" "$@"
158新增: ;;
159新增: claude)
160新增: _agent_vm_claude "${vm_opts[@]}" "$@"
161新增: ;;
162新增: opencode)
163新增: _agent_vm_opencode "${vm_opts[@]}" "$@"
164新增: ;;
165新增: codex)
166新增: _agent_vm_codex "${vm_opts[@]}" "$@"
167新增: ;;
168新增: shell)
169新增: _agent_vm_shell "${vm_opts[@]}" "$@"
170新增: ;;
171新增: stop)
172新增: _agent_vm_stop "$@"
173新增: ;;
174新增: destroy)
175新增: _agent_vm_destroy "$@"
176新增: ;;
177新增: list)
178新增: _agent_vm_list "$@"
179新增: ;;
180新增: status)
181新增: _agent_vm_status "$@"
182新增: ;;
183新增: help|--help|-h)
184新增: _agent_vm_help
185新增: ;;
186新增: *)
187新增: echo "Unknown command: $cmd" >&2
188新增: echo "Run 'agent-vm help' for usage." >&2
189新增: return 1
190新增: ;;
191新增: esac
192新增:}
193新增:
194新增:_agent_vm_help() {
195新增: cat << 'EOF'
196新增:Usage: agent-vm [options] <command> [args]
197新增:
198新增:Commands:
199新增: setup Create the base VM template (run once)
200新增: claude [args] Run Claude Code in the VM for the current directory
201新增: opencode [args] Run OpenCode in the VM for the current directory
202新增: codex [args] Run Codex CLI in the VM for the current directory
203新增: shell Open a shell in the VM for the current directory
204新增: stop Stop the VM for the current directory
205新增: destroy Stop and delete the VM for the current directory
206新增: list List all agent-vm VMs
207新增: status Show VM status for the current directory
208新增: help Show this help
209新增:
210新增:VM options (for claude, opencode, codex, shell):
211新增: --disk GB VM disk size (default: 20)
212新增: --memory GB VM memory (default: 8)
213新增: --reset Destroy and re-clone the VM from the base template
214新增:
215新增:Examples:
216新增: agent-vm setup # Create base VM
217新增: agent-vm claude # Run Claude in a VM
218新增: agent-vm opencode # Run OpenCode in a VM
219新增: agent-vm codex # Run Codex in a VM
220新增: agent-vm --disk 50 --memory 16 claude # With custom resources
221新增: agent-vm --reset claude # Fresh VM from base template
222新增: agent-vm shell # Shell into the VM
223新增: agent-vm claude -p "fix lint errors" # Pass args to claude
224新增:
225新增:VMs are persistent and unique per directory. Running "agent-vm shell" or
226新增:"agent-vm claude" in the same directory will reuse the same VM.
227新增:
228新增:Customization:
229新增: ~/.agent-vm.setup.sh Per-user setup (runs during "agent-vm setup")
230新增: <project>/.agent-vm.runtime.sh Per-project setup (runs on each VM start)
231新增:
232新增:More info: https://github.com/sylvinus/agent-vm
233新增:EOF
234新增:}
235新增:
236新增:_agent_vm_setup() {
237新增: local disk=20
238新增: local memory=8
239新增:
240新增: while [[ $# -gt 0 ]]; do
241新增: case "$1" in
242新增: --help|-h)
243新增: echo "Usage: agent-vm setup [--disk GB] [--memory GB]"
244新增: echo ""
245新增: echo "Create a base VM template with dev tools and agents pre-installed."
246新增: echo ""
247新增: echo "Options:"
248新增: echo " --disk GB VM disk size (default: 20)"
249新增: echo " --memory GB VM memory (default: 8)"
250新增: echo " --help Show this help"
251新增: return 0
252新增: ;;
253新增: --disk)
254新增: disk="$2"
255新增: shift 2
256新增: ;;
257新增: --disk=*)
258新增: disk="${1#*=}"
259新增: shift
260新增: ;;
261新增: --memory)
262新增: memory="$2"
263新增: shift 2
264新增: ;;
265新增: --memory=*)
266新增: memory="${1#*=}"
267新增: shift
268新增: ;;
269新增: *)
270新增: echo "Unknown option: $1" >&2
271新增: echo "Usage: agent-vm setup [--disk GB] [--memory GB]" >&2
272新增: return 1
273新增: ;;
274新增: esac
275新增: done
276新增:
277新增: if ! command -v limactl &>/dev/null; then
278新增: if command -v brew &>/dev/null; then
279新增: echo "Installing Lima..."
280新增: brew install lima
281新增: else
282新增: echo "Error: Lima is required. Install from https://lima-vm.io/docs/installation/" >&2
283新增: return 1
284新增: fi
285新增: fi
286新增:
287新增: limactl stop "$AGENT_VM_TEMPLATE" &>/dev/null
288新增: limactl delete "$AGENT_VM_TEMPLATE" --force &>/dev/null
289新增:
290新增: echo "Creating base VM..."
291新增: limactl create --name="$AGENT_VM_TEMPLATE" template:debian-13 \
292新增: --set '.mounts=[]' \
293新增: --disk="$disk" \
294新增: --memory="$memory" \
295新增: --tty=false &>/dev/null || { echo "Error: Failed to create base VM." >&2; return 1; }
296新增: limactl start "$AGENT_VM_TEMPLATE" &>/dev/null || { echo "Error: Failed to start base VM." >&2; return 1; }
297新增:
298新增: # Run the setup script inside the VM
299新增: echo "Installing packages inside VM..."
300新增: limactl shell "$AGENT_VM_TEMPLATE" bash -l < "${AGENT_VM_SCRIPT_DIR}/agent-vm.setup.sh" || { echo "Error: Setup script failed." >&2; return 1; }
301新增:
302新增: # Run user's custom setup script if it exists
303新增: local user_setup="$HOME/.agent-vm.setup.sh"
304新增: if [ -f "$user_setup" ]; then
305新增: echo "Running custom setup from $user_setup..."
306新增: limactl shell "$AGENT_VM_TEMPLATE" zsh -l < "$user_setup" || { echo "Error: Custom setup script failed." >&2; return 1; }
307新增: fi
308新增:
309新增: limactl stop "$AGENT_VM_TEMPLATE" &>/dev/null
310新增:
311新增: mkdir -p "$AGENT_VM_CONFIG_DIR"
312新增:
313新增: # Record base VM version so we can warn about stale clones
314新增: mkdir -p "$AGENT_VM_STATE_DIR"
315新增: date +%s > "$AGENT_VM_STATE_DIR/.agent-vm-base-version"
316新增:
317新增: echo ""
318新增: echo "Base VM ready. Run 'agent-vm shell', 'agent-vm claude', 'agent-vm opencode', or 'agent-vm codex' in any project directory."
319新增: echo "Note: Existing VMs were not updated. Use --reset to re-clone them from the new base."
320新增:}
321新增:
322新增:_agent_vm_claude() {
323新增: local vm_opts=()
324新增: local args=()
325新增: while [[ $# -gt 0 ]]; do
326新增: case "$1" in
327新增: --disk) vm_opts+=(--disk "$2"); shift 2 ;;
328新增: --memory) vm_opts+=(--memory "$2"); shift 2 ;;
329新增: --reset) vm_opts+=(--reset); shift ;;
330新增: *) args+=("$1"); shift ;;
331新增: esac
332新增: done
333新增: local host_dir
334新增: host_dir="$(pwd)"
335新增: local vm_name
336新增: vm_name="$(_agent_vm_name "$host_dir")"
337新增:
338新增: _agent_vm_ensure_running "$vm_name" "$host_dir" "${vm_opts[@]}" || return 1
339新增:
340新增: limactl shell --workdir "$host_dir" "$vm_name" claude --dangerously-skip-permissions "${args[@]}"
341新增:}
342新增:
343新增:_agent_vm_opencode() {
344新增: local vm_opts=()
345新增: local args=()
346新增: while [[ $# -gt 0 ]]; do
347新增: case "$1" in
348新增: --disk) vm_opts+=(--disk "$2"); shift 2 ;;
349新增: --memory) vm_opts+=(--memory "$2"); shift 2 ;;
350新增: --reset) vm_opts+=(--reset); shift ;;
351新增: *) args+=("$1"); shift ;;
352新增: esac
353新增: done
354新增: local host_dir
355新增: host_dir="$(pwd)"
356新增: local vm_name
357新增: vm_name="$(_agent_vm_name "$host_dir")"
358新增:
359新增: _agent_vm_ensure_running "$vm_name" "$host_dir" "${vm_opts[@]}" || return 1
360新增:
361新增: limactl shell --workdir "$host_dir" "$vm_name" opencode --dangerously-skip-permissions "${args[@]}"
362新增:}
363新增:
364新增:_agent_vm_codex() {
365新增: local vm_opts=()
366新增: local args=()
367新增: while [[ $# -gt 0 ]]; do
368新增: case "$1" in
369新增: --disk) vm_opts+=(--disk "$2"); shift 2 ;;
370新增: --memory) vm_opts+=(--memory "$2"); shift 2 ;;
371新增: --reset) vm_opts+=(--reset); shift ;;
372新增: *) args+=("$1"); shift ;;
373新增: esac
374新增: done
375新增: local host_dir
376新增: host_dir="$(pwd)"
377新增: local vm_name
378新增: vm_name="$(_agent_vm_name "$host_dir")"
379新增:
380新增: _agent_vm_ensure_running "$vm_name" "$host_dir" "${vm_opts[@]}" || return 1
381新增:
382新增: limactl shell --workdir "$host_dir" "$vm_name" codex --full-auto "${args[@]}"
383新增:}
384新增:
385新增:_agent_vm_shell() {
386新增: local vm_opts=()
387新增: while [[ $# -gt 0 ]]; do
388新增: case "$1" in
389新增: --disk) vm_opts+=(--disk "$2"); shift 2 ;;
390新增: --memory) vm_opts+=(--memory "$2"); shift 2 ;;
391新增: --reset) vm_opts+=(--reset); shift ;;
392新增: *) shift ;;
393新增: esac
394新增: done
395新增: local host_dir
396新增: host_dir="$(pwd)"
397新增: local vm_name
398新增: vm_name="$(_agent_vm_name "$host_dir")"
399新增:
400新增: _agent_vm_ensure_running "$vm_name" "$host_dir" "${vm_opts[@]}" || return 1
401新增:
402新增: echo "VM: $vm_name | Dir: $host_dir"
403新增: echo "Type 'exit' to leave (VM keeps running). Use 'agent-vm stop' to stop it."
404新增: limactl shell --workdir "$host_dir" "$vm_name" zsh -l
405新增:}
406新增:
407新增:_agent_vm_stop() {
408新增: local host_dir
409新增: host_dir="$(pwd)"
410新增: local vm_name
411新增: vm_name="$(_agent_vm_name "$host_dir")"
412新增:
413新增: if ! _agent_vm_exists "$vm_name"; then
414新增: echo "No VM found for this directory." >&2
415新增: return 1
416新增: fi
417新增:
418新增: echo "Stopping VM '$vm_name'..."
419新增: limactl stop "$vm_name" &>/dev/null
420新增: echo "VM stopped."
421新增:}
422新增:
423新增:_agent_vm_destroy() {
424新增: local host_dir
425新增: host_dir="$(pwd)"
426新增: local vm_name
427新增: vm_name="$(_agent_vm_name "$host_dir")"
428新增:
429新增: if ! _agent_vm_exists "$vm_name"; then
430新增: echo "No VM found for this directory." >&2
431新增: return 1
432新增: fi
433新增:
434新增: echo "Stopping and deleting VM '$vm_name'..."
435新增: limactl stop "$vm_name" &>/dev/null
436新增: limactl delete "$vm_name" --force &>/dev/null
437新增: rm -f "$AGENT_VM_STATE_DIR/.agent-vm-version-${vm_name}"
438新增: echo "VM destroyed."
439新增:}
440新增:
441新增:_agent_vm_list() {
442新增: limactl list | head -1
443新增: limactl list | grep "^agent-vm-" || echo "(no VMs)"
444新增:}
445新增:
446新增:_agent_vm_status() {
447新增: local host_dir
448新增: host_dir="$(pwd)"
449新增: local vm_name
450新增: vm_name="$(_agent_vm_name "$host_dir")"
451新增:
452新增: if ! _agent_vm_exists "$vm_name"; then
453新增: echo "No VM for this directory."
454新增: echo "VM name: $vm_name"
455新增: return 0
456新增: fi
457新增:
458新增: echo "VM name: $vm_name"
459新增: limactl list | head -1
460新增: limactl list | grep "$vm_name"
461新增:}
删除claude-vm.sh+0 −247
@@ -1,247 +0,0 @@
1删除:#!/usr/bin/env bash
2删除:#
3删除:# agent-vm / claude-vm: Run Claude Code inside a sandboxed Lima VM
4删除:# Part of https://github.com/sylvinus/agent-vm
5删除:#
6删除:# Source this file in your shell config:
7删除:# source /path/to/agent-vm/claude-vm.sh
8删除:#
9删除:# Functions:
10删除:# claude-vm-setup - Create the VM template (run once)
11删除:# claude-vm [args] - Run Claude in a fresh VM with cwd mounted (args forwarded to claude)
12删除:# claude-vm-shell - Open a debug shell in a fresh VM
13删除:
14删除:CLAUDE_VM_TEMPLATE="claude-template"
15删除:
16删除:claude-vm-setup() {
17删除: local minimal=false
18删除: local disk=20
19删除: local memory=8
20删除:
21删除: while [[ $# -gt 0 ]]; do
22删除: case "$1" in
23删除: --help|-h)
24删除: echo "Usage: claude-vm-setup [--minimal] [--disk GB] [--memory GB]"
25删除: echo ""
26删除: echo "Create a VM template with Claude Code pre-installed."
27删除: echo ""
28删除: echo "Options:"
29删除: echo " --minimal Only install git, curl, jq, and Claude Code"
30删除: echo " --disk GB VM disk size (default: 20)"
31删除: echo " --memory GB VM memory (default: 8)"
32删除: echo " --help Show this help"
33删除: return 0
34删除: ;;
35删除: --minimal)
36删除: minimal=true
37删除: shift
38删除: ;;
39删除: --disk)
40删除: disk="$2"
41删除: shift 2
42删除: ;;
43删除: --disk=*)
44删除: disk="${1#*=}"
45删除: shift
46删除: ;;
47删除: --memory)
48删除: memory="$2"
49删除: shift 2
50删除: ;;
51删除: --memory=*)
52删除: memory="${1#*=}"
53删除: shift
54删除: ;;
55删除: *)
56删除: echo "Unknown option: $1" >&2
57删除: echo "Usage: claude-vm-setup [--minimal] [--disk GB] [--memory GB]" >&2
58删除: return 1
59删除: ;;
60删除: esac
61删除: done
62删除:
63删除: if ! command -v limactl &>/dev/null; then
64删除: if command -v brew &>/dev/null; then
65删除: echo "Installing Lima..."
66删除: brew install lima
67删除: else
68删除: echo "Error: Lima is required. Install from https://lima-vm.io/docs/installation/" >&2
69删除: return 1
70删除: fi
71删除: fi
72删除:
73删除: limactl stop "$CLAUDE_VM_TEMPLATE" &>/dev/null
74删除: limactl delete "$CLAUDE_VM_TEMPLATE" --force &>/dev/null
75删除:
76删除: echo "Creating VM template..."
77删除: limactl create --name="$CLAUDE_VM_TEMPLATE" template:debian-13 \
78删除: --set '.mounts=[]' \
79删除: --disk="$disk" \
80删除: --memory="$memory" \
81删除: --tty=false
82删除: limactl start "$CLAUDE_VM_TEMPLATE"
83删除:
84删除: # Disable needrestart's interactive prompts
85删除: limactl shell "$CLAUDE_VM_TEMPLATE" sudo bash -c 'mkdir -p /etc/needrestart/conf.d && echo "\$nrconf{restart} = '"'"'a'"'"';" > /etc/needrestart/conf.d/no-prompt.conf'
86删除:
87删除: echo "Installing base packages..."
88删除: limactl shell "$CLAUDE_VM_TEMPLATE" sudo DEBIAN_FRONTEND=noninteractive apt-get update
89删除: limactl shell "$CLAUDE_VM_TEMPLATE" sudo DEBIAN_FRONTEND=noninteractive apt-get install -y \
90删除: git curl jq
91删除:
92删除: if ! $minimal; then
93删除: limactl shell "$CLAUDE_VM_TEMPLATE" sudo DEBIAN_FRONTEND=noninteractive apt-get install -y \
94删除: wget build-essential \
95删除: python3 python3-pip python3-venv \
96删除: ripgrep fd-find htop \
97删除: unzip zip \
98删除: ca-certificates
99删除:
100删除: # Install Docker from official repo (includes docker compose)
101删除: echo "Installing Docker..."
102删除: limactl shell "$CLAUDE_VM_TEMPLATE" bash -c '
103删除: sudo install -m 0755 -d /etc/apt/keyrings
104删除: sudo curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc
105删除: sudo chmod a+r /etc/apt/keyrings/docker.asc
106删除: echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
107删除: '
108删除: limactl shell "$CLAUDE_VM_TEMPLATE" sudo DEBIAN_FRONTEND=noninteractive apt-get update
109删除: limactl shell "$CLAUDE_VM_TEMPLATE" sudo DEBIAN_FRONTEND=noninteractive apt-get install -y \
110删除: docker-ce docker-ce-cli containerd.io docker-compose-plugin
111删除:
112删除: # Add user to docker group
113删除: limactl shell "$CLAUDE_VM_TEMPLATE" bash -c 'sudo usermod -aG docker $(whoami)'
114删除:
115删除: # Install Node.js 22 (needed for MCP servers)
116删除: echo "Installing Node.js 22..."
117删除: limactl shell "$CLAUDE_VM_TEMPLATE" bash -c "curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -"
118删除: limactl shell "$CLAUDE_VM_TEMPLATE" sudo DEBIAN_FRONTEND=noninteractive apt-get install -y nodejs
119删除:
120删除: # Install Chromium and dependencies for headless browsing
121删除: echo "Installing Chromium..."
122删除: limactl shell "$CLAUDE_VM_TEMPLATE" sudo DEBIAN_FRONTEND=noninteractive apt-get install -y \
123删除: chromium \
124删除: fonts-liberation \
125删除: xvfb
126删除: # Symlink so tools looking for google-chrome find Chromium
127删除: limactl shell "$CLAUDE_VM_TEMPLATE" sudo ln -sf /usr/bin/chromium /usr/bin/google-chrome
128删除: limactl shell "$CLAUDE_VM_TEMPLATE" sudo ln -sf /usr/bin/chromium /usr/bin/google-chrome-stable
129删除: limactl shell "$CLAUDE_VM_TEMPLATE" bash -c 'sudo mkdir -p /opt/google/chrome && sudo ln -sf /usr/bin/chromium /opt/google/chrome/chrome'
130删除: fi
131删除:
132删除: # Install Claude Code
133删除: echo "Installing Claude Code..."
134删除: limactl shell "$CLAUDE_VM_TEMPLATE" bash -c "curl -fsSL https://claude.ai/install.sh | bash"
135删除: limactl shell "$CLAUDE_VM_TEMPLATE" bash -c 'echo "export PATH=\$HOME/.local/bin:\$HOME/.claude/local/bin:\$PATH" >> ~/.bashrc'
136删除:
137删除: # Authenticate Claude (saves token in template, inherited by clones)
138删除: echo "Setting up Claude authentication..."
139删除: limactl shell "$CLAUDE_VM_TEMPLATE" bash -lc "claude 'Ok I am logged in, I can exit now.'"
140删除:
141删除: if ! $minimal; then
142删除: # Configure Chrome DevTools MCP server for Claude
143删除: echo "Configuring Chrome MCP server..."
144删除: limactl shell "$CLAUDE_VM_TEMPLATE" bash << 'VMEOF'
145删除:CONFIG="$HOME/.claude.json"
146删除:if [ -f "$CONFIG" ]; then
147删除: jq '.mcpServers["chrome-devtools"] = {
148删除: "command": "npx",
149删除: "args": ["-y", "chrome-devtools-mcp@latest", "--headless=true", "--isolated=true"]
150删除: }' "$CONFIG" > "$CONFIG.tmp" && mv "$CONFIG.tmp" "$CONFIG"
151删除:else
152删除: cat > "$CONFIG" << 'JSON'
153删除:{
154删除: "mcpServers": {
155删除: "chrome-devtools": {
156删除: "command": "npx",
157删除: "args": ["-y", "chrome-devtools-mcp@latest", "--headless=true", "--isolated=true"]
158删除: }
159删除: }
160删除:}
161删除:JSON
162删除:fi
163删除:VMEOF
164删除: fi
165删除:
166删除: # Run user's custom setup script if it exists
167删除: local user_setup="$HOME/.claude-vm.setup.sh"
168删除: if [ -f "$user_setup" ]; then
169删除: echo "Running custom setup from $user_setup..."
170删除: limactl shell "$CLAUDE_VM_TEMPLATE" bash < "$user_setup"
171删除: fi
172删除:
173删除: limactl stop "$CLAUDE_VM_TEMPLATE"
174删除:
175删除: echo "Template ready. Run 'claude-vm' in any project directory."
176删除:}
177删除:
178删除:claude-vm() {
179删除: local args=("$@")
180删除: local vm_name="claude-$(basename "$(pwd)" | tr -cs 'a-zA-Z0-9' '-' | sed 's/^-//;s/-$//')-$$"
181删除: local host_dir="$(pwd)"
182删除:
183删除: if ! limactl list -q 2>/dev/null | grep -q "^${CLAUDE_VM_TEMPLATE}$"; then
184删除: echo "Error: Template VM not found. Run 'claude-vm-setup' first." >&2
185删除: return 1
186删除: fi
187删除:
188删除: _claude_vm_cleanup() {
189删除: echo "Cleaning up VM..."
190删除: limactl stop "$vm_name" &>/dev/null
191删除: limactl delete "$vm_name" --force &>/dev/null
192删除: }
193删除: trap _claude_vm_cleanup EXIT INT TERM
194删除:
195删除: echo "Starting VM '$vm_name'..."
196删除: limactl clone "$CLAUDE_VM_TEMPLATE" "$vm_name" \
197删除: --set ".mounts=[{\"location\":\"${host_dir}\",\"writable\":true}]" \
198删除: --tty=false &>/dev/null
199删除:
200删除: limactl start "$vm_name" &>/dev/null
201删除:
202删除: # Run project-specific runtime script if it exists
203删除: if [ -f "${host_dir}/.claude-vm.runtime.sh" ]; then
204删除: echo "Running project runtime setup..."
205删除: limactl shell --workdir "$host_dir" "$vm_name" bash -l < "${host_dir}/.claude-vm.runtime.sh"
206删除: fi
207删除:
208删除: limactl shell --workdir "$host_dir" "$vm_name" claude --dangerously-skip-permissions "${args[@]}"
209删除:
210删除: _claude_vm_cleanup
211删除: trap - EXIT INT TERM
212删除:}
213删除:
214删除:claude-vm-shell() {
215删除: local vm_name="claude-debug-$$"
216删除: local host_dir="$(pwd)"
217删除:
218删除: if ! limactl list -q 2>/dev/null | grep -q "^${CLAUDE_VM_TEMPLATE}$"; then
219删除: echo "Error: Template VM not found. Run 'claude-vm-setup' first." >&2
220删除: return 1
221删除: fi
222删除:
223删除: _claude_vm_shell_cleanup() {
224删除: echo "Cleaning up VM..."
225删除: limactl stop "$vm_name" &>/dev/null
226删除: limactl delete "$vm_name" --force &>/dev/null
227删除: }
228删除: trap _claude_vm_shell_cleanup EXIT INT TERM
229删除:
230删除: limactl clone "$CLAUDE_VM_TEMPLATE" "$vm_name" \
231删除: --set ".mounts=[{\"location\":\"${host_dir}\",\"writable\":true}]" \
232删除: --tty=false &>/dev/null
233删除:
234删除: limactl start "$vm_name" &>/dev/null
235删除:
236删除: # Run project-specific runtime script if it exists
237删除: if [ -f "${host_dir}/.claude-vm.runtime.sh" ]; then
238删除: limactl shell --workdir "$host_dir" "$vm_name" bash -l < "${host_dir}/.claude-vm.runtime.sh"
239删除: fi
240删除:
241删除: echo "VM: $vm_name | Dir: $host_dir"
242删除: echo "Type 'exit' to stop and delete the VM"
243删除: limactl shell --workdir "$host_dir" "$vm_name" bash -l
244删除:
245删除: _claude_vm_shell_cleanup
246删除: trap - EXIT INT TERM
247删除:}