/agent-fork:agent-fork [name-hint] [--now] | --session | --session-onlyfrom agent-fork
Fork a Claude Code, Codex, Muse, OpenCode, or borg1 session together with its project files: create a new branch and separate Git worktree, copy tracked files and, by default, their staged and unstaged changes plus untracked files, then print the command to continue the conversation there. Use for "fork this session", /agent-fork, $agent-fork, or requests for the current session ID or repository context. Supports a name hint, --now to skip confirmation, --session for session details, transcript path, and fork and resume commands, and --session-only to print only the command to fork the conversation. Not for ordinary Git branch, worktree, directory, or status requests.
Ships in agent-fork. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Delegate to a compatible agent-fork CLI. Run every command from the user's
active repository directory. Let the CLI own agent detection, session evidence,
Git operations, automatic naming, verification, rollback, registry state, and
continuation-command construction.
Inspect the complete skill argument text before choosing a route or discarding any token. This gate precedes every CLI call:
--session selects session inspection including the native fork
command.--session-only selects command-only output. --session-only is one exact token,
not --session followed by text.--now skips the fork confirmation. It may appear at most once and
may accompany a name hint in either order.
It may never accompany --session or --session-only.--session combined with any other text is invalid. --session-only combined with any other text
is also invalid. Refuse without calling the CLI.
In particular, /agent-fork --session review-auth and
/agent-fork --session-only review-auth are not named forks.- other than those three exact forms is
unsupported. Refuse without calling the CLI.--now, all remaining text is one name hint.
That remaining text may contain no option-like token.Never remove --session and then treat the remaining text as a fork name.
A runner is the complete executable prefix used to launch Agent Fork.
Every agent-fork command below specifies the route arguments; replace its
agent-fork prefix with the selected runner for the whole operation, including
inspection, preview, fork, and doctor. Keep that prefix and source revision in
working context rather than relying on shell variables surviving tool calls.
pwd -P before selecting a runner.command -v agent-fork and select that executable when present. If lookup
fails, read references/cli-runner.md and select its temporary runner.agent-fork session --json through the selected runner and validate it
below. An absent executable, shell exit 127, or command not found means
Agent Fork never ran; read references/cli-runner.md and recover once.
Otherwise-valid output missing a required contract field takes that same
recovery path. Do not ask for confirmation merely because recovery fetches
code. Malformed output and a CLI refusal do not trigger recovery.directory to equal the recorded invocation directory.
If it differs, report Agent-fork invocation directory mismatch with both
paths terminal-escaped and stop before presentation, preview, or mutation.agent-fork session --json.
--now skips the fork preview and confirmation, not this read-only check.Never report tool setup as a completed inspection or fork. A CLI that runs
and reports an environment problem has actually run: preserve its exact output
and suggest agent-fork doctor through the selected runner. Doctor checks Git,
the agent CLIs, configuration, XDG paths, and whether a setup hook would run.
Classify before normalizing. Choose exactly one route.
For exact skill argument --session, or a natural-language request for the
current Claude Code/Codex/Muse/OpenCode/borg1 session ID or that agent session's repository context,
run exactly:
agent-fork session --json
Validate the session object and its fork_command and resume_command
objects as specified below. Summarize the fields the user requested; show raw
JSON only when requested. If a command's status is available, include its
command character-for-character under a clear label — fork command for
fork_command, resume command for resume_command. resume_command is the
"rehydrate" command: it re-enters the exact same session in place (same
session ID, same directory, same branch/worktree) rather than creating a new
one, for picking a set-aside session back up. Do not rebuild, reorder,
re-quote, execute, or copy either command. For not_detected, ambiguous,
or unsafe_input, report the exact status and null command for each.
Also present transcript: the absolute path of the file where this session's
conversation is stored on disk — a Claude Code JSONL transcript, a Codex
rollout JSONL, a Muse session.jsonl, or a borg1 ~/.borg1/sessions/<id>.jsonl; an OpenCode session reports a null path because OpenCode keeps
history in its database. When transcript.path is a string, show it under a clear label
with terminal control characters escaped — the path embeds the invocation
directory, so it is a repository-controlled value like any other and is
never printed raw — and state whether transcript.exists is true or
false; a
false value means the path is where the transcript belongs but no file is
there yet, which is normal early in a session and also happens when the CLI
was invoked from a directory other than the session's own. When
transcript.path is null,
report that the transcript could not be located and do not guess a path.
Escaping makes the value safe to display; it never licenses rewriting,
shortening, or re-encoding the path itself. Never read, summarize, copy, or
quote the file's contents — this field is a location only.
When messaging is present, also show it under the label "Message as": the
name other Claude Code sessions can use to message this one (the to value
for SendMessage, and the name ListAgents lists). It is distinct from
"Session name", which is only a /rename title. For status live, show
messaging.name, terminal-escaped like every other session-controlled value,
and say it is valid while this session runs and can change. For any other
status, show — with the exact status. Older CLIs omit messaging; its
absence is not an older-contract diagnostic and never triggers recovery.
When message_route is present, also show it under the label "Message
route": how another session can message this one, for Claude Code, Codex,
Muse, OpenCode, or borg1. For status available, show message_route.command
character-for-character and say where the message goes: as the command's
final argument (message_via: argument) or on stdin (message_via: stdin).
Never execute the command. For address_only, show message_route.address
terminal-escaped and name the channel (claude-sendmessage means the
SendMessage tool; muse-session-message means Muse's in-session
messaging; opencode-session and borg1-session have no delivery command that agent-fork reports). For
any other status, show — with the exact status. Show message_route.name,
terminal-escaped, when it is non-null. message_route is optional and
informational: its absence never triggers recovery, and an unrecognized
status or field is shown raw rather than treated as invalid output.
For exact skill argument --session-only, run exactly:
agent-fork session --json
Validate the same session and fork_command object used by --session. When
status is available, emit only the exact fork_command.command string,
character-for-character, with no label, explanation, code fence, reconstruction,
execution, or clipboard action. For not_detected, ambiguous, or
unsafe_input, report the exact unavailable status and stop without inventing a
command.
Fork routes resolve exactly one candidate name before any mutation. Pick the first case that matches:
repository.detached is false,
repository.branch is present, and repository.on_default_branch is false.
Pass no positional name and let the CLI derive it, together with its
date and collision suffixes.Case 3 is a proposal, not a decision: it reaches the user through the
confirmation below, or through --now when they have chosen to skip that.
Every fork is confirmed before it exists, unless the argument gate found an
exact --now.
Resolve the candidate name above. If this route has not already run
agent-fork session --json, run it now — the dry run reports the fork it
would create, not where you are, so the summary takes the current branch
from repository.branch.
Compute the real plan without mutating anything:
agent-fork fork '<candidate-name>' --dry-run --require-agent --json
Omit the positional name only for the branch-derived case, which lets the
CLI name it. Check that dry_run is true and
mutation_performed is false before showing anything, and that
plan.branch.name, plan.worktree.path, and plan.files_to_carry are all
present.
Report Invalid agent-fork JSON output and stop if any is missing.
State the plan in visible text immediately before the question: the
current branch from repository.branch, or detached HEAD when it is
null, the target branch from plan.branch.name, the destination
from plan.worktree.path, and the counts under plan.files_to_carry.
Report those values verbatim — semantically exact, never shortened or
normalized — but
terminal-escape them as repository-controlled values.
Do not predict, reformat, or shorten a path.
Ask one question with three options: create the fork as shown, use a different name, or do not fork. Do not ask three separate questions.
A different name re-enters at step 1 as an explicit hint. Declining stops without mutation and without a second question.
On approval, run the fork exactly as the route below specifies.
A dry run is not a fork. Never report one as a created fork, and never treat an approved confirmation as finished until the real run returns.
--nowAn exact --now forks immediately: resolve the candidate name, then
skip the dry run and the question, and run the fork exactly as the route
below specifies, treating each route's approval step as already satisfied.
--now skips the confirmation, never the naming rules, so it
never invents a random name. A name hint still wins, a topic branch still
yields the CLI's derived name, and a default or detached branch still gets the
name proposed from the conversation. Report the effective name, branch, and
worktree afterward exactly as any other fork.
Treat all non-option text after the skill name as one name hint. Normalize it as specified below, confirm it as specified above, then run exactly this command shape:
agent-fork fork '<normalized-name>' --require-agent --json
Pass the normalized value as one shell-quoted argument. Do not add --agent or --parent-session; strict ambient detection belongs to the CLI.
For /agent-fork, $agent-fork, or “Fork this session” without a name:
Run agent-fork session --json from the active repository directory.
If agent or current_session is null, report lineage.status and stop.
Naming cannot make strict agent detection succeed.
If repository is null, report the invocation directory and stop. Asking
for a name cannot make the directory forkable.
Resolve the candidate name and confirm it as specified above.
On approval of a branch-derived name, run exactly:
agent-fork fork --require-agent --json
Do not pass a positional name. The CLI owns branch-derived normalization and date and collision suffixes.
On approval of any other name, run the explicit-name route's command with it. That name is already confirmed; do not confirm it twice.
Use the same working directory for inspection and fork. Do not run cd or
change branches between the two calls.
The only skill options are the exact single-token forms --session,
--session-only, and --now.
Every token beginning with - other than those three exact forms
is unsupported and must refuse before normalization and before any CLI call.
For --status, say: Use --session to inspect the current agent session.
Do not turn --sesion into a fork name.
Refuse --session mixed with a name or another token.
Refuse --session-only mixed with a name, --session, or another token.
Refuse --now mixed with --session, --session-only, or another --now.
Show the three supported forms:
/agent-fork [name hint] [--now]
/agent-fork --session
/agent-fork --session-only
Advanced destination, state-copy, submodule-copy, verification, identity,
output, clipboard, dry-run, and force controls are direct-CLI use cases, not
skill arguments (this restricts what the user may pass to the skill, not the
confirmation's own dry-run call above). Submodules are carried recursively by
default (--no-with-submodules opts out); a dirty submodule counts as at
most one entry in plan.files_to_carry above (its own gitlink path) — the
individual files changed inside it are not broken out separately.
Produce [a-z0-9]+(?:-[a-z0-9]+)*:
Examples:
"Review Auth" -> "review-auth"
"feature/auth-refresh" -> "feature-auth-refresh"
"Fix OAuth @ Login" -> "fix-oauth-login"
"---" -> empty; ask for another name
When the name changes, report
Fork name normalized: "<input>" -> "<normalized>" before mutation. Do not ask
for another confirmation solely because of mechanical normalization. Preserve
an explicit-name collision error; do not silently suffix a user-selected name.
When a successful agent-fork session --json or fork run reports "agent",
read the matching example file from this skill's directory before presenting
results:
"claude" -> references/output-claude.md"codex" -> references/output-codex.md"muse" -> references/output-muse.md"opencode" -> references/output-opencode.md"borg1" -> references/output-borg1.mdThe file shows the presentation format for each route: the --session
summary, the bare --session-only line, the fork confirmation plan, and the
fork result. It changes formatting only; every validation, escaping, and
character-for-character command rule in this file still governs, and its
example values are never material to reconstruct a command from. When
agent is null or the CLI is missing, no reference applies.
A missing CLI is handled by the preflight above, not here.
Before classifying output as an older contract, require exit 0, one JSON
object, the base session fields listed below, and valid values for every
present command or transcript object. Malformed JSON, invalid present fields,
and unknown status values are Invalid agent-fork JSON output; stop without
fetching or retrying.
Otherwise-valid session JSON without fork_command predates that contract.
Only the --session route also requires resume_command and transcript;
--session-only never requires either. Record the matching diagnostic:
Installed agent-fork predates the fork_command contractInstalled agent-fork predates the resume_command contractInstalled agent-fork predates the transcript contractRead references/cli-runner.md, select a compatible runner, and repeat the
inspection once before any mutation. On success, continue the original route
with that runner; a successful --session-only still emits only the returned
command. If recovery fails, report the diagnostic, missing fields, selected
source, and actual failure. Never recover after attempting a real fork.
agent-fork --version is not a reliable discriminator: fork_command's
addition did not get one, so check required fields instead of trusting a version.
Treat exit 0 as success only when stdout is one JSON object with the expected route fields:
agent, current_session, parent_session, lineage, notices,
directory, and repository (which may be null), plus fork_command; the
--session route additionally requires resume_command and transcript.
Each of fork_command and resume_command must be an object whose status
is exactly available, not_detected, ambiguous, or unsafe_input.
available requires a non-empty string command; every other status
requires a null command. transcript must be an object whose
transcript.path is a non-empty string or null and whose
transcript.exists is a boolean; a null path with exists true is
invalid output. messaging is optional; when present it must be an object
whose status is exactly live, not_running, unavailable, or
not_applicable, whose name is a non-empty string for live and null
otherwise, and whose name_source is a string or null.command and non-empty strings fork.name, fork.branch, and fork.worktree.Otherwise report Invalid agent-fork JSON output and stop. Do not invent
missing values. An unknown future fork_command.status or
resume_command.status is invalid output; stop without reconstructing or
executing anything.
On fork success, present the effective name, branch, and worktree, followed by
the exact returned command string. Do not rebuild, reorder, or re-quote it.
Preserve nonzero CLI output and stop.
git ls-remote lookup in references/cli-runner.md.agents/openai.yaml (opens in a new tab)references/cli-runner.md (opens in a new tab)references/output-borg1.md (opens in a new tab)references/output-claude.md (opens in a new tab)references/output-codex.md (opens in a new tab)references/output-muse.md (opens in a new tab)references/output-opencode.md (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
npx claudepluginhub smorinlabs/agent-fork --plugin agent-fork