Hand work to a fork
An agent working in a machine can fork the machine to hand a separate task to a copy of itself, keep
working, and act on the fork’s reply. This page shows the loop with space-env, and the
instructions that teach an agent to run it.
The loop
In the parent machine, commit what the fork needs (it gets the disk, not your memory), then fork with a task a newcomer can do:
space-env fork issue-1 --text "Fix issue 1 in /root/work/app on branch issue-1, push it, then reply to me."forked issue-1 (context issue-1): it is starting a fresh agent that gets your message as its task; ...The context, issue-1, is the conversation id; it defaults to the fork’s name. In the fork,
the task is the first message:
space-env receive --timeout 60The fork does the work, pushes its branch, and replies once with what the parent needs to review it, copying the context:
space-env send parent --reply --context issue-1 --text "done: branch issue-1 pushed; tests pass"The parent goes on with its own work and, when it runs out, waits for replies:
space-env receive --type agent --timeout 300It then fetches the branch, reviews and tests it, and merges it, or replies to the fork with what to change (same context) and waits again. When it is done with the fork, it deletes it:
space-env forks delete issue-1A machine can delete only the forks it created itself, not other machines of the project and not
its forks’ forks. A fork that has forked again is refused unless --cascade, which deletes
the whole branch below it too, deepest first. space-env forks lists a machine’s forks. From your
own machine, space machines delete issue-1 --yes works as for any machine.
A fork with its programs running
space-env fork gives the fork the disk only. On a machine without an agent, such as one
that runs a development website, space-env fork --hot NAME --text "TASK" copies its memory
too, so the fork starts with the website already running. The machine pauses while its
memory is copied, its tunnels and port forwards must be opened again after, and programs
that make keys or ids should be restarted in the fork: Hot
forks has the details. A machine that runs an
agent, such as a Claude Code session’s machine, isn’t forked hot: its copy would carry on
the same agent’s session.
Agents’ machines aren’t forked
Forks are for machines only. An agent’s own machine (the one the platform made with the agent)
isn’t forked: a copy would run the same agent. space-env fork on it is refused with “an agent’s
machine isn’t forked: fork the machines it works on”, and so is a new machine from a checkpoint of
it (space machines create --from CHECKPOINT, the portal, the MCP tools). The portal’s canvas
offers no Fork for it. An agent hands separate work to a subagent instead, and forks the ordinary
machines it works on.
Who a fork works for
A fork remembers where it comes from. space-env whoami in the fork shows created_by: vm:<parent's id> and on_behalf_of: user:<id>: the person the parent works for, copied
down to every fork of a fork. The machine a person creates in the portal or with space works for
that person. The portal shows the same in the machine’s Manage dialog, with the person’s name; inside
the machine it is only an id. See How it works.
Instructions for the agent
Agents learn the loop from the agents’ handbook.
space-env docs prints it, in the version that matches the machine’s space-env; the same text
is in /usr/share/space-env/AGENTS.md, and the details of each command in its --help. Point
your agent’s instructions at it, or copy it into its CLAUDE.md or AGENTS.md:
space-env docsThe text is the one we are testing with Claude Code, and changes with what the tests show.
An agent per machine
On an agent machine nobody has to wait for messages: vmagent keeps the agent running (The agent over ACP), and a message that waits for the agent becomes a prompt in its conversation. The agent’s own machine isn’t forked (below): the loop above runs on the ordinary machines it works on, and the agent hands separate work to a subagent.