Skip to content

feat(fork): agentbox fork + /agentbox for Claude/Codex/OpenCode#12

Merged
madarco merged 3 commits into
mainfrom
feat/agentbox-fork
May 28, 2026
Merged

feat(fork): agentbox fork + /agentbox for Claude/Codex/OpenCode#12
madarco merged 3 commits into
mainfrom
feat/agentbox-fork

Conversation

@madarco
Copy link
Copy Markdown
Owner

@madarco madarco commented May 28, 2026

Summary

Adds agentbox fork — snapshot the current host agent session and resume it in a fresh box, opening it in a new terminal tab (iTerm/tmux) or background. Plus a user-invocable /agentbox command installed into Claude, Codex, and OpenCode.

  • agentbox fork (apps/cli/src/commands/fork.ts): thin wrapper over each agent's existing create+teleport+attach pipeline. Flags: --agent claude|codex|opencode (default claude), --session, --provider, -n, --attach-in (default tab), --carry-yes. Background fallback when no tmux/iTerm (never hijacks the calling terminal). LLM-resilience guards: refuses inside a box (AGENTBOX_RELAY_URL), tolerates empty --provider, rejects --session with --agent opencode.
  • agentbox install: writes the /agentbox command into ~/.claude/skills (fork command + renamed agentbox-info reference), and — when detected — ~/.codex/prompts/agentbox.md and ~/.config/opencode/commands/agentbox.md. Idempotent via an <!-- agentbox-managed:v1 --> sentinel. agentbox claude prints a one-time install tip.
  • Per-agent session pinning: Claude uses the ${CLAUDE_SESSION_ID} skill placeholder; Codex (no session-id variable) has its agent resolve the live uuid from the newest rollout file; OpenCode starts a fresh box (session teleport not implemented yet).

Fixes folded in

  • iTerm new-tab spawn (terminal/host.ts): the create window/tab ... command "..." AppleScript parameter is broken on iTerm 3.7 betas (bounces to Terminal.app); switched all modes to create-then-write text.
  • Cloud resume on new-tab attach (core/provider.ts, sandbox-cloud/cloud-provider.ts, _cloud-attach.ts): cloud sessions start lazily at attach, and the new-tab re-invocation of agentbox <agent> attach carried no --resume, so hetzner forks started fresh. Added a detached build option and pre-create the resumed session before the new-tab spawn.

Scope

v1 is host→box only; box→box fork is deferred (needs downloadPath from the source box + a relay endpoint). OpenCode resume is deferred (sessions live in a multi-tenant SQLite DB).

Test plan

  • pnpm -w build, typecheck, lint, vitest (329 pass) green
  • agentbox install writes all 4 agent files; idempotent re-run
  • Docker fork resumes the Claude session in a new iTerm tab; background fallback works
  • fork --agent codex resumed a real Codex session in a box; fork --agent opencode started a fresh box
  • Live Hetzner fork now launches claude --resume <id> in the box (was fresh before)
  • Manual: /agentbox in Claude, /prompts:agentbox in Codex, /agentbox in OpenCode

Note

Medium Risk
New fork/install orchestration touches session teleport and terminal/cloud attach paths; cloud detached pre-start fixes resume correctness but adds attach complexity.

Overview
Adds agentbox fork to teleport the current host Claude/Codex/OpenCode session into a new sandbox (default new iTerm/tmux tab, background when no splittable terminal so the caller’s session isn’t hijacked). It delegates to each agent’s existing create + session-teleport + attach flow, with guards for in-box runs (AGENTBOX_RELAY_URL), ambiguous recent Claude sessions, and no OpenCode resume yet.

Adds agentbox install to ship bundled host skills/prompts (/agentbox fork + agentbox-info reference) into Claude, and into Codex/OpenCode when those config dirs exist, with idempotent agentbox-managed overwrite rules. agentbox claude shows a one-time tip to run install when the fork skill is missing.

Fixes cloud resume on new-tab attach: pre-creates the tmux session detached with the full launch command (claude --resume …) before the tab re-invokes attach without extra args. iTerm spawning now uses create-then-write text instead of broken command parameters on 3.7 betas.

Reviewed by Cursor Bugbot for commit 7e45062. Configure here.

madarco added 3 commits May 28, 2026 08:48
…n into a box

Add `agentbox fork`: snapshot the current host Claude Code session and
resume it in a fresh box, opening the box in a new iTerm tab / tmux window
(or background when no multiplexer). Thin wrapper over the existing
`agentbox claude --resume` create+teleport pipeline, with a
background-not-inline fallback and LLM-resilience guards (refuses inside a
box via AGENTBOX_RELAY_URL, tolerates an empty --provider).

Add `agentbox install` to write the host-side Claude skills
(`/agentbox` fork command + the renamed `agentbox-info` reference) into
~/.claude/skills, idempotent via a managed sentinel. `agentbox claude`
prints a one-time install tip.

Fix iTerm new-tab/window spawning: the `create window/tab ... command "..."`
AppleScript parameter is unreliable on iTerm 3.7 betas (fails and bounces
the command to Terminal.app); switch all modes to create-then-`write text`.
…ent`

`agentbox fork` learns `--agent claude|codex|opencode` (default claude),
routing the create+teleport+attach pipeline to the matching agent command:
Claude/Codex resume via teleport; OpenCode starts a fresh box (its session
teleport is still a stub).

`agentbox install` now also writes the fork command for Codex
(~/.codex/prompts/agentbox.md → /prompts:agentbox) and OpenCode
(~/.config/opencode/commands/agentbox.md → /agentbox) when those tools are
set up on the host, reusing the managed-sentinel idempotence. The Codex
prompt has its agent resolve the live session uuid from the newest rollout
file (Codex exposes no session-id variable); the OpenCode command notes it
starts a fresh session.
On cloud providers the in-box agent session starts lazily at attach time.
With `--attach-in tab|window|split`, runWrappedAttach re-invokes
`agentbox <agent> attach <box>` in the fresh pane, and that re-invocation
carries no launch args — so a forked `claude --resume <id>` (hetzner)
started a fresh session instead of resuming the teleported one. (Docker
starts the session at create time; Daytona is forced to inline attach, so
both dodged this.)

Add a `detached` build option that produces a "create the tmux session but
don't attach" command. cloudAgentAttach now pre-creates the session with the
full `--resume` command before the new-terminal spawn; the re-invoked attach
finds it via `tmux has-session` and attaches to the already-resumed session.

Verified on a live Hetzner box: the in-box process is `claude --resume <id>`
and the teleported transcript is present.
@madarco madarco merged commit be19c9e into main May 28, 2026
2 checks passed
madarco added a commit that referenced this pull request May 28, 2026
…vercelTimeoutMs)

vcpus and session timeout were hardcoded (2 / 45min). Add flat config keys
box.vercelVcpus + box.vercelTimeoutMs (matching the box.defaultCheckpointVercel
convention) and thread them: config -> providerOptions (vercel-only) ->
cloud-provider resource/timeout overrides -> CloudProvisionRequest.timeoutMs +
resources.cpu -> Sandbox.create({ resources: { vcpus }, timeout }). daytona /
hetzner are untouched (they don't set the override keys). Region stays fixed
iad1 (Vercel constraint).

Verified live: vercelVcpus=4 yields sandbox.vcpus===4 (default 2).

Closes backlog #12.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant