How to Bring Agent Sessions Back After a Terminal Loss¶
Long-lived Claude Code sessions, such as a coordinator and its area
controllers, usually run inside one tmux server. When that server ends, every
session in it ends too. amplihack agent keeps a registry of these sessions,
and a supervisor service checks them every minute. When a registered
session's claude process and its tmux session are both gone, the supervisor
creates the tmux session again and resumes the session from its own saved
conversation, in the same directory and with the same profile, model, effort,
directories and permissions. The resumed session is told when and why it was
resumed. Each recovery is one line in a log and in amplihack agent status.
The exact flags, file formats, messages and exit codes are in the
amplihack agent reference.
Contents¶
- Before you start
- Run the supervisor service
- Where the tmux server runs
- Register sessions
- Register the coordinator and its areas
- Check what is registered
- What happens on a terminal loss
- Clean exits stay ended
- Crash loops
- Run one pass by hand
- Change the timing
- Stop supervising a session
- Unattended resumes and other users
- Limits
Before you start¶
You need:
- Linux. The supervisor reads
/procto find runningclaudeprocesses. On other systemsamplihack agent superviseexits without starting anything. - tmux, git and Claude Code on the
PATHthat the service uses. - Each long-lived session in its own tmux session. The supervisor recreates one tmux session per agent, and leaves an agent alone while its tmux session exists. Two active agents cannot share a tmux session.
- systemd user services, to run the supervisor as a service. Without them,
run
amplihack agent supervisein a terminal of its own, outside the tmux server it supervises. ~/.amplihack,~/.claudeand every profile directory owned by you and not writable by other users. Group write is accepted when the group is your own private group, which is the usual layout with a umask of002.- amplihack's
SessionEndhook, installed byamplihack installor by the amplihack Claude Code plugin, so that a session you register while it runs is not resumed after you leave it with/exit. See Clean exits stay ended.
Do not run any amplihack agent command, or amplihack claude --supervise,
under sudo. They refuse files that the user they run as does not own.
Run the supervisor service¶
amplihack does not install the service. Write the unit yourself.
- Find the programs the supervisor runs:
- Create
~/.config/systemd/user/amplihack-agent-supervisor.service:
[Unit]
Description=amplihack agent supervisor
[Service]
ExecStart=%h/.local/bin/amplihack agent supervise
Environment=PATH=%h/.local/bin:/usr/local/bin:/usr/bin:/bin
Restart=always
RestartSec=10
KillMode=process
[Install]
WantedBy=default.target
Change ExecStart if amplihack is installed somewhere else, and make
PATH list every directory from step 1. systemd replaces %h with your
home directory. Do not add credentials, sandboxing settings such as
PrivateTmp= or ProtectHome=, or resource limits such as MemoryMax=:
every agent the supervisor resumes inherits them. Do not put secrets in
Environment= lines either: the unit file and systemctl --user show
expose them, and every resumed agent inherits them. The
reference gives the reasons.
Every directory in PATH must be writable only by you or by root. The
supervisor finds tmux, git, systemd-run and amplihack through
PATH, so a directory that another user can write to lets that user
choose the program it runs. Check with:
alex drwxr-xr-x /home/alex/.local/bin
root drwxr-xr-x /usr/local/bin
root drwxr-xr-x /usr/bin
root drwxr-xr-x /bin
- Load and start it:
- Let your user services run without a login session, so the supervisor starts at boot and keeps running after you log out:
Without lingering, systemd starts the supervisor when you log in, and at logout it stops the supervisor and every agent the supervisor resumed.
The supervisor starts each tmux server in a scope unit of its own, outside
the service's control group, so stopping the service leaves the agents
running; see Where the tmux server runs.
KillMode=process is a second safeguard for a server that had to be started
without that scope. Such a server belongs to the service's control group, and
systemd's default would end it with the service. Because it is left running,
each restart of the service logs
Found left-over process ... in control group while starting unit for each
of its processes. This is expected with KillMode=process.
The login rotator has the same need to outlive a tmux server. Issue #1759
covers running it as its own user service, amplihack-rotator.service, and an
installer shared by both units belongs with that work. The two units are
independent: either runs without the other.
Where the tmux server runs¶
When the supervisor resumes an agent and no tmux server is running on the
agent's socket, its tmux new-session starts one. By default that server
would be a child of the supervisor and so part of the service's control
group. To keep it out, the supervisor starts it through systemd-run, in a
scope unit of its own:
systemd-run --user --scope --collect --quiet --unit=amplihack-tmux-server-1793349461-1 -- \
tmux new-session -d -s coordinator -n main -c /home/alex/src/example-org -- ...
The name ends in the Unix time of the launch and a counter that starts at 1
in each pass and goes up by one for every scope the pass starts, so two
scopes started in the same second get different names. Only the first resume on each
tmux socket in a pass checks whether a server is running; later resumes on
that socket in the same pass join the server it started, with plain tmux.
A server that was already running is used as it is, and systemd-run is not
called.
List the scopes, and see which agents run in each:
● amplihack-tmux-server-1793349461-1.scope - /usr/bin/tmux new-session -d -s coordinator ...
Loaded: loaded (/run/user/1000/systemd/transient/amplihack-tmux-server-1793349461-1.scope; transient)
Active: active (running) since Thu 2026-10-29 23:27:41 UTC; 9h ago
CGroup: /user.slice/user-1000.slice/user@1000.service/app.slice/amplihack-tmux-server-1793349461-1.scope
├─48211 tmux new-session -d -s coordinator -n main -c /home/alex/src/example-org ...
├─48214 /home/alex/.local/bin/amplihack claude --no-reflection --profile work --supervise coordinator ...
└─48230 claude --resume 0f8e5c1a-3b2d-4c6e-9a7f-1d2e3f4a5b6c ...
Because the server is in its own scope, stopping or restarting the
supervisor service does not touch it, and the service's start no longer logs
Found left-over process for it. Keep KillMode=process in the unit all the
same: it still protects agents when the scope could not be used.
systemd-run needs to reach your user manager. From a user service this
works when XDG_RUNTIME_DIR and DBUS_SESSION_BUS_ADDRESS are set, which
systemd does for user services on most distributions. When systemd-run is
not on PATH, the supervisor starts tmux without it. When systemd-run
fails or does not answer within 10 seconds, the supervisor:
- asks tmux whether the agent's session now exists, because
systemd-runcan fail after tmux has started. If it does, the resume counts as done and nothing else is started. If tmux's answer is unexpected, nothing else is started either, and the result isskipped: tmux session exists (tmux state unknown: REASON); - otherwise starts tmux once more without
systemd-run, so the agent is still resumed.
Either way, a server started without systemd-run gives a WARNING line:
2026-10-29T23:27:41Z WARNING: agent coordinator tmux server started without its own scope: systemd-run is not on PATH
A server started this way is in the service's control group, as before, and
KillMode=process is what keeps it alive across a service restart. If the
WARNING lines keep coming, either install systemd-run (part of systemd), or
run tmux as a user service of its own and let the supervisor use that
server. A minimal ~/.config/systemd/user/tmux-server.service:
[Unit]
Description=tmux server
[Service]
Type=forking
Environment=PATH=%h/.local/bin:/usr/local/bin:/usr/bin:/bin
ExecStart=/usr/bin/tmux new-session -d -s keepalive
ExecStop=/usr/bin/tmux kill-server
[Install]
WantedBy=default.target
With that server running, the supervisor finds a server on the default
socket and does not call systemd-run. Two things differ from scopes:
- Resumed agents run with the environment of the tmux server, not of the
supervisor unit. Give
tmux-server.servicethe sameEnvironment=PATH=as the supervisor unit, with the same rule that every directory on it is writable only by you or root. - It covers only the default socket. An agent registered with its own tmux socket still gets a scope, or a WARNING line, when no server is running on that socket.
If tmux gives an unexpected answer when the supervisor asks whether a server
is running, the agent, and every other agent on that socket, is not resumed
in that pass and is skipped with
skipped: tmux session exists (tmux state unknown: REASON). The next pass
asks again.
Register sessions¶
There are three ways to put a session in the registry. Each records the
session under a NAME of your choice: letters, digits, ., _ and -,
starting with a letter or digit, at most 64 characters.
Start a session under supervision¶
Create a tmux session for the agent, then start Claude Code in it with
--supervise NAME:
In the new tmux session:
Before Claude Code starts, --supervise records:
- the tmux socket, session and window;
- the current directory, which is the directory Claude Code finds the conversation by;
- the Claude Code options after
--:--model,--effort, each--add-dir, and--permission-modeor--dangerously-skip-permissions; --profile,--subprocess-safeand--no-reflection;- the model and effort variables
set in your environment, such as
ANTHROPIC_MODEL.
Then Claude Code starts as amplihack claude always starts it. The
conversation id is recorded as soon as Claude Code writes its session file,
usually within seconds. With --resume ID after --, it is recorded at
once. If the id cannot be recorded within two minutes, a WARNING: line in
~/.amplihack/agents/supervisor.log gives the reason; nothing is printed in
the session.
--supervise needs Linux and tmux. It refuses -p and --print, and it
cannot be combined with --auto, --append, --docker or --checkout-repo.
Every session the supervisor resumes runs with --supervise, so after its
first recovery an agent's clean exits are always recorded.
Register a session that is already running¶
amplihack agent register NAME reads a running claude process and records
it. From inside the session, use Claude Code's ! prefix:
registered coordinator: session coordinator, window main, conversation 0f8e5c1a-3b2d-4c6e-9a7f-1d2e3f4a5b6c, directory /home/alex/src/example-org
From any other shell, name the tmux pane the session runs in:
or the claude process id, if you know it:
--pane asks the tmux server of the shell you run it in, or tmux's default
server outside tmux. For a pane on another server, add
--tmux-socket with that server's socket.
register reads the conversation id and directory from the process's session
file, the Claude Code options from its command line, --profile,
--subprocess-safe and --no-reflection from the amplihack claude that
started it, and the tmux names from the tmux server in the process's own
environment. A flag you give replaces the value it found. A warning: line
on stderr means a value was found but not recorded; read it before you rely
on the registration.
Register a session that is already gone¶
With no running process, give the tmux names, the directory and the conversation id yourself, with the options the session used:
amplihack agent register area-reports \
--tmux-socket /tmp/tmux-1000/default --session area-reports --window main \
--dir /home/alex/src/reports \
--conversation 6f3b9d2e-4a7c-4e1b-8c5d-2e9a7f1b4d36 \
--profile work --model opus --effort high
- Conversation id. Each
<id>.jsonlin the project's transcript directory is one conversation. The directory is under~/.claude/projects/, or under the profile's directory for a session that used--profile, and is named after the launch directory with/and.replaced by-. The most recently changed transcript is usually the one you want:
- Socket.
--tmux-socketis the socket of the tmux server the session ran on. Inside any tmux session on that server,tmux display-message -p '#{socket_path}'prints it. Without--tmux-socket, the supervisor uses tmux's default server for its own environment; when that server's socket does not exist, for example after a reboot, the session counts as gone. - Environment. Only the variables you give with
--env KEY=VALUEare recorded.
You can run this from inside another Claude session, such as the
coordinator's. register uses the session it runs in only when that
session's conversation is the one --conversation names. Here it is not, so
register records no process and takes nothing from the coordinator: the
area agent's entry holds only the values you gave.
The supervisor's next pass finds the agent lost and resumes it.
Register the coordinator and its areas¶
A typical layout has a coordinator, a writer, a custodian and several area
controllers, each in its own tmux session named after the agent, with one
window called main. Register the coordinator from inside its session:
Then register the others from any shell, including the coordinator's:
for a in writer custodian area-billing area-docs area-ingest area-reports area-search; do
amplihack agent register "$a" --pane "$a:main"
done
Each conversation and each tmux session belongs to at most one active agent.
register refuses a second registration with
this conversation is already used by registered agent OTHER or
tmux session S is already used by registered agent OTHER.
Registering a NAME again replaces its record and clears its restart history
and any alert. Do this after you move a session to another tmux session or
directory. Start new sessions with
--supervise instead.
Check what is registered¶
NAME STATE CONVERSATION DIRECTORY LAST RECOVERY
area-billing active 5c2f8e1a-7d3b-4a9e-b6c4-1e8f2a7d3c95 /home/alex/src/billing -
area-docs active 2b7e4f1c-8d3a-4c6e-9f2b-5a1d7e3c8b64 /home/alex/src/docs -
area-ingest active 9a4e7c21-5b3d-4e8f-a1c6-3f2d8b7e6a90 /home/alex/src/ingest -
area-reports active 6f3b9d2e-4a7c-4e1b-8c5d-2e9a7f1b4d36 /home/alex/src/reports -
area-search active e7b1d4c9-2a6f-4e3b-8d5c-9f1a7e2b6d48 /home/alex/src/search -
coordinator active 0f8e5c1a-3b2d-4c6e-9a7f-1d2e3f4a5b6c /home/alex/src/example-org -
custodian active 3d8a6f2b-1e5c-4b7a-9d2e-6c4f8a1b3e57 /home/alex/src/example-org -
writer active b4e9a2d7-6c1f-4d8b-a3e5-7f2c9d6b1a84 /home/alex/src/example-org -
status reads the registry only; it checks no processes and no tmux
sessions. A conversation shown as - has not been found yet. For scripts,
amplihack agent status --json prints the same records with the tmux names,
the restart count for the last hour, the alert and the end time. The fields
are in the reference.
What happens on a terminal loss¶
Say the tmux server ends at 23:27:09. At its next pass, 31 seconds later, the
supervisor finds that the claude processes and the tmux sessions of all
eight agents are gone.
What is resumed¶
The supervisor resumes an agent when all of these hold:
- the agent is
active, notendedorstopped; - no
claudeprocess of yours is running its conversation, under~/.claudeor under any profile directory; - its tmux session does not exist;
- it has a conversation id, its launch directory exists, and the
conversation's transcript is in the config directory the resume uses (the
recorded profile's directory, else the default profile pointer's, else
~/.claude); - it has been resumed fewer than 3 times in the last hour.
For each one, it creates the tmux session and window again in the recorded
directory, starting the tmux server if none is running. In the window it runs
amplihack claude --supervise NAME with the recorded profile and flags,
--resume with the conversation id, and the recorded Claude Code options. The
resumed session's first message is:
amplihack agent supervisor: the terminal session for this agent was lost at 2026-10-29T23:27:40Z. This conversation was resumed at 2026-10-29T23:27:41Z. Before continuing, check what your interrupted step had already done (git status, open pull requests, running processes) and do not repeat finished steps.
The first time is when the supervisor first found the agent gone. That is usually within one interval of the loss. A loss that happens while a pass is still resuming later batches is found by the next pass, after that pass ends and the interval has passed.
Order and batches¶
Agents with uncommitted changes to tracked files in their launch directory go first, those with the most changed tracked files first; the rest follow by name. The supervisor resumes 6 agents, waits 60 seconds, resumes the next 6, and so on, so that a mass restart does not use up a login's capacity at once. Before each resume it checks the agent again, in case you resumed the session yourself during the wait.
Here area-billing and coordinator had uncommitted work, and custodian
and writer were in the second batch:
2026-10-29T23:27:41Z agent=area-billing conversation=5c2f8e1a-7d3b-4a9e-b6c4-1e8f2a7d3c95 lost=2026-10-29T23:27:40Z resumed=2026-10-29T23:27:41Z result=resumed
2026-10-29T23:27:41Z agent=coordinator conversation=0f8e5c1a-3b2d-4c6e-9a7f-1d2e3f4a5b6c lost=2026-10-29T23:27:40Z resumed=2026-10-29T23:27:41Z result=resumed
2026-10-29T23:27:42Z agent=area-docs conversation=2b7e4f1c-8d3a-4c6e-9f2b-5a1d7e3c8b64 lost=2026-10-29T23:27:40Z resumed=2026-10-29T23:27:42Z result=resumed
2026-10-29T23:27:42Z agent=area-ingest conversation=9a4e7c21-5b3d-4e8f-a1c6-3f2d8b7e6a90 lost=2026-10-29T23:27:40Z resumed=2026-10-29T23:27:42Z result=resumed
2026-10-29T23:27:43Z agent=area-reports conversation=6f3b9d2e-4a7c-4e1b-8c5d-2e9a7f1b4d36 lost=2026-10-29T23:27:40Z resumed=2026-10-29T23:27:43Z result=resumed
2026-10-29T23:27:43Z agent=area-search conversation=e7b1d4c9-2a6f-4e3b-8d5c-9f1a7e2b6d48 lost=2026-10-29T23:27:40Z resumed=2026-10-29T23:27:43Z result=resumed
2026-10-29T23:28:43Z agent=custodian conversation=3d8a6f2b-1e5c-4b7a-9d2e-6c4f8a1b3e57 lost=2026-10-29T23:27:40Z resumed=2026-10-29T23:28:43Z result=resumed
2026-10-29T23:28:44Z agent=writer conversation=b4e9a2d7-6c1f-4d8b-a3e5-7f2c9d6b1a84 lost=2026-10-29T23:27:40Z resumed=2026-10-29T23:28:44Z result=resumed
Attach to a resumed session as usual:
What is left alone¶
The supervisor never starts a conversation that is already running, and never creates a tmux session that already exists. A healthy agent, with its conversation running and its tmux session present, writes nothing. Otherwise the pass writes one of these lines:
| Result | Meaning | What to do |
|---|---|---|
skipped: already running |
The conversation is running in a claude process outside the agent's tmux session. |
Nothing, if you resumed it elsewhere on purpose. Register the agent again for its new tmux session. |
skipped: tmux session exists |
The tmux session is there, but no claude process runs the conversation. Claude Code may have exited and left a shell in the window. |
Restart the session in that window, or close the tmux session and the next pass resumes it. |
skipped: already running (liveness unknown: REASON) |
The supervisor could not tell whether the conversation is running, so it assumes it is. | Fix REASON, for example a Claude config directory that other users can write to. |
skipped: tmux session exists (tmux state unknown: REASON) |
tmux did not answer clearly, so the supervisor assumes the session exists. | Fix REASON. socket directory is not private is explained in Unattended resumes and other users. |
failed: no conversation id |
The agent has no conversation id to resume. | Register it again with --conversation. |
failed: launch directory missing |
The recorded directory no longer exists. | Restore the directory, or register the agent again with --dir. |
failed: no transcript |
The conversation's transcript is not in the config directory the resume would use. A recorded profile whose directory no longer exists, or a default profile pointer that cannot be read, gives the same result. | Check amplihack_flags.profile in agent status --json. A launch under an inherited AMPLIHACK_CLAUDE_PROFILE or the default pointer records its profile once its session file is found; if none was recorded and the conversation is in ~/.claude, clear or change the default pointer, or register the agent again with the right --profile. |
failed: tmux: MESSAGE |
tmux refused to create the session. | Read MESSAGE. The attempt counts towards the restart limit, so a launch that keeps failing ends with the agent stopped. |
Each of these lines is written once. The same result for the same agent and conversation is not written again at every pass; a resume is always written. Once the agent is seen healthy again, a stored skip or failure is cleared, so the same result is written again if it comes back.
Read the log¶
Every line goes to ~/.amplihack/agents/supervisor.log and to the
supervisor's output, which the journal keeps:
amplihack agent status shows each agent's latest line in its
LAST RECOVERY column:
NAME STATE CONVERSATION DIRECTORY LAST RECOVERY
area-billing active 5c2f8e1a-7d3b-4a9e-b6c4-1e8f2a7d3c95 /home/alex/src/billing 2026-10-29T23:27:41Z resumed
area-docs active 2b7e4f1c-8d3a-4c6e-9f2b-5a1d7e3c8b64 /home/alex/src/docs 2026-10-29T23:27:42Z resumed
area-ingest active 9a4e7c21-5b3d-4e8f-a1c6-3f2d8b7e6a90 /home/alex/src/ingest 2026-10-29T23:27:42Z resumed
area-reports active 6f3b9d2e-4a7c-4e1b-8c5d-2e9a7f1b4d36 /home/alex/src/reports 2026-10-29T23:27:43Z resumed
area-search active e7b1d4c9-2a6f-4e3b-8d5c-9f1a7e2b6d48 /home/alex/src/search 2026-10-29T23:27:43Z resumed
coordinator active 0f8e5c1a-3b2d-4c6e-9a7f-1d2e3f4a5b6c /home/alex/src/example-org 2026-10-29T23:27:41Z resumed
custodian active 3d8a6f2b-1e5c-4b7a-9d2e-6c4f8a1b3e57 /home/alex/src/example-org 2026-10-29T23:28:43Z resumed
writer active b4e9a2d7-6c1f-4d8b-a3e5-7f2c9d6b1a84 /home/alex/src/example-org 2026-10-29T23:28:44Z resumed
Clean exits stay ended¶
An agent whose session finishes normally is marked ended and is not
resumed. How the supervisor learns of the exit depends on how the session
was started.
- Sessions started with
--supervise, including every session the supervisor resumed. When Claude Code exits normally, for example after/exit, the agent is markedendedbywrapper. A session that exits with an error status, or ends because its terminal or tmux server was lost (SIGHUP) or it was told to stop (SIGTERM), staysactiveand is resumed. - Sessions registered with
amplihack agent register. Here amplihack'sSessionEndhook reports the exit. When you leave the session from its prompt, for example with/exit, or log out with/logout, the hook writes a marker file under~/.amplihack/agents/ended/. At its next pass the supervisor marks the agentendedbysession-endand deletes the marker./clearand/resumekeep the session running with another conversation, and write no marker; the supervisor follows the new conversation id. A session lost with its terminal or tmux server writes no marker either, and staysactive. The reference lists every reason Claude Code sends.
The hook comes with amplihack install and with the amplihack Claude Code
plugin, and it must be installed in the config directory the session uses
(~/.claude, or the profile's directory). Without it, an /exit in a
registered session is not recorded. The agent then stays active, and the
next time its tmux session is lost the supervisor resumes it.
Ending an agent writes no line in the log. amplihack agent status shows an
ended agent's state with the time and the source:
NAME STATE CONVERSATION DIRECTORY LAST RECOVERY
...
writer ended 2026-10-30T08:02:15Z (wrapper) b4e9a2d7-6c1f-4d8b-a3e5-7f2c9d6b1a84 /home/alex/src/example-org 2026-10-29T23:28:44Z resumed
To supervise an ended agent again, start it with
amplihack claude --supervise NAME, or register it again.
Crash loops¶
Every resume, and every launch that tmux refuses, counts towards a limit of 3
per agent in any hour. When an agent is lost again after 3 such attempts in
the last hour, the supervisor does not
resume it. It marks the agent stopped and writes an alert:
2026-10-30T00:41:40Z agent=custodian conversation=3d8a6f2b-1e5c-4b7a-9d2e-6c4f8a1b3e57 lost=2026-10-30T00:41:40Z resumed=- result=stopped: restart limit
2026-10-30T00:41:40Z ALERT: agent custodian stopped: restart limit (3 restarts in the last hour)
amplihack agent status shows the agent as stopped, with the alert below
the table:
NAME STATE CONVERSATION DIRECTORY LAST RECOVERY
...
custodian stopped 3d8a6f2b-1e5c-4b7a-9d2e-6c4f8a1b3e57 /home/alex/src/example-org 2026-10-30T00:41:40Z stopped: restart limit
...
ALERT custodian: stopped: restart limit (3 restarts in the last hour)
status --json gives the same text in the agent's alert field. A stopped
agent stays stopped until you act.
A standing session is relaunched by its own
pane on every exit, so it reaches this recovery only when the pane could not
relaunch it: the launch failed without an exit status from Claude Code, or the
wait for a login with room ended without one. The pane then leaves the reason
in the agent's alert field, of the form not relaunched: …, and leaves the
agent active for this recovery. An alert of the form relaunched in its pane
at … is the pane's record of its last relaunch, with the number of
relaunches since the model last replied; it is evidence for you or the
supervisor agent to judge, not a request for recovery. See
when a session keeps exiting.
stopped: restart limit is a session the supervisor has given up on.
The agent step that reads these alerts is the bundled
supervise-agent-sessions skill, which a supervisor agent uses on every pass.
It judges the relaunch records, stops a crash loop with
amplihack agent unregister, and finds out why a session with a
not relaunched alert was not resumed: the service is not running, or the
pane is held open by a shell and this pass writes
skipped: tmux session exists. See
who reads the record.
Find out why the session fails before you re-arm it. A session that exits with an error closes its tmux window, so run it yourself in a window that stays open. First read the recorded options:
jq '.agents.custodian | {tmux_session, tmux_window, launch_dir, conversation_id,
model, effort, add_dirs, permission_mode, skip_permissions, amplihack_flags}' \
~/.amplihack/agents/registry.json
{
"tmux_session": "custodian",
"tmux_window": "main",
"launch_dir": "/home/alex/src/example-org",
"conversation_id": "3d8a6f2b-1e5c-4b7a-9d2e-6c4f8a1b3e57",
"model": "opus",
"effort": "high",
"add_dirs": [],
"permission_mode": null,
"skip_permissions": true,
"amplihack_flags": {
"subprocess_safe": false,
"no_reflection": false,
"profile": "work"
}
}
Then open the agent's tmux session with a shell, and start the session there with the same options:
amplihack claude --profile work --supervise custodian -- \
--resume 3d8a6f2b-1e5c-4b7a-9d2e-6c4f8a1b3e57 --model opus --effort high
Claude Code's error stays on screen. amplihack claude --supervise makes the
agent active again and clears its alert as it starts, before Claude Code
runs, so the agent is supervised again even if Claude Code then fails. Its
restart history is kept, so if it is lost again within the hour the
supervisor stops it again instead of resuming it.
To clear the restart history as well, register the agent again with
amplihack agent register. Registering replaces the whole record, so give
every option, as in
Register a session that is already gone.
Run one pass by hand¶
Only one supervisor runs at a time. To run a single pass yourself, stop the service, run the pass, and start the service again:
systemctl --user stop amplihack-agent-supervisor.service
amplihack agent supervise --once
systemctl --user start amplihack-agent-supervisor.service
Stopping the service does not stop the agents it resumed. With the service
running, --once prints
another amplihack agent supervisor is running (pid N) and exits 1.
Change the timing¶
| Flag | Default | What it controls |
|---|---|---|
--interval SECS |
60 | Time from the end of one pass to the start of the next |
--batch N |
6 | Agents resumed per batch |
--gap SECS |
60 | Wait between batches |
--max-restarts N |
3 | Launch attempts allowed per agent in any hour before it is stopped |
To change them, override ExecStart in a drop-in:
systemctl --user edit reloads systemd when you save. Then restart the
service:
Stop supervising a session¶
This removes the record only. The session, its tmux session and its
processes are left alone. Earlier lines in the log are kept. A
standing session whose record is removed is
not relaunched when its current run exits: its pane refuses with
reason=superseded.
Unattended resumes and other users¶
- The registry is a list of sessions that start on their own. The
supervisor resumes every active agent with no one watching, and
amplihack claudestarts Claude Code with--dangerously-skip-permissions, so tool calls run without permission prompts. With lingering on, this happens after a reboot before anyone logs in. Register only sessions you would leave running that way, and reviewamplihack agent statusfrom time to time: any program running as your user can add an agent. - Credentials are not recorded. Only eleven variables that choose models,
effort and output limits, such as
ANTHROPIC_MODELandCLAUDE_CODE_EFFORT_LEVEL, are ever recorded. API keys, tokens andANTHROPIC_BASE_URLare not, and--envrefuses them. A value typed after--envis already in your shell history and visible to other users in the process list, even whenregisterrefuses it. Do not put credentials in the unit either. Claude Code keeps its login in~/.claudeand needs none. - The journal is readable by some other users. Log lines name agents,
conversation ids, directories and results. On most distributions members of
the
admorsystemd-journalgroup can read your user journal. - Private directories. The supervisor resumes nothing while it cannot trust what it reads:
- When
~/.claude, the profile root, a profile directory or asessions/directory below them is not owned by you, or other users can write to it, every lost agent is skipped withskipped: already running (liveness unknown: Claude config directory is not private).amplihack agent registerfails with an error that names the directory, for asessions/directory when it reads a running session; remove the write bits withchmod go-w. - When
~/.amplihack/agents/endedis a symlink, or is not a directory of yours that only you can open, the supervisor reads no SessionEnd markers from it, deletes nothing in it, and printswarning: ~/.amplihack/agents/ended: REASON; no markers were readat each pass. Remove it; the hook creates it again. - Before it talks to a tmux socket, the supervisor checks the socket's
directory, for example
/tmp/tmux-1000. If it is not yours, or other users can open it, the agent is skipped withskipped: tmux session exists (tmux state unknown: socket directory is not private). After a reboot clears/tmp, another user can create that directory before the supervisor does; until it is removed, which needs root because the directory is not yours, recovery stays withheld. Your own tmux refuses the same directory.
Limits¶
- Linux only. On other systems
registerneeds every field as a flag, and neitheramplihack agent supervisenoramplihack claude --supervisestarts anything. - One tmux session per agent. The supervisor finds an agent's tmux
session by its exact name. Do not rename the tmux session or window of a
registered agent; register it again after you do. Session names cannot
contain
:,.or#, and window names cannot contain#. - A conversation change just before an exit. For a session registered
with
amplihack agent register, the supervisor follows a new conversation id after/clearor/resumeat its next pass. If you run/clearand then/exitbefore that pass, the exit names a conversation the registry does not know, and a later tmux loss resumes the old conversation. Sessions started with--superviseare not affected. - Transcript directory names. Claude Code names a project's transcript
directory after the launch directory. The supervisor checks the two names
Claude Code is known to use. If Claude Code uses another, for example for a
very long path, the result is
failed: no transcriptalthough the transcript exists. - Server placement is checked once per socket per pass. If something else ends the tmux server between two resumes on the same socket in one pass, the later resume starts a server without its own scope and without a WARNING line. The next pass checks again.
- No log rotation.
~/.amplihack/agents/supervisor.loggrows by one line per recovery attempt. Truncate it while the service is stopped if it gets large.
Related¶
- Keep a Session Running After Its Process Exits -
Relaunch a standing session in its pane with
claude --continue amplihack agentreference - Every flag, the registry fields, the result texts, the status formats and the unit- Rotate Claude Logins - Keep
~/.claudeon the account with the most capacity while many sessions resume - Manage Claude Login Profiles - The profiles that
--profilerefers to - Install amplihack as a Claude Code plugin -
The plugin that carries the
SessionEndhook