Expand description
Same-identity relocation
(SPEC_RESUME_GATE_AND_SAME_IDENTITY_CONTINUATION_2026_09_25.md §4.3): the
file half. When the agent’s chain head lives under another login of the
same Anthropic identity, one session file is copied into the spawn’s
config dir so --resume <head> --fork-session can read it. The fork
writes a new session and never touches the copy or the original (verified
against Claude Code 2.1.280, spec §2.4), so the copy exists only until the
fork reports its own id.
Every copy carries a marker naming the agent that made it, so the next spawn of that agent can remove one a dead process left behind, and no other agent’s copy is touched. The marker is written before the copy takes its real name: a copy is never visible to the CLI without one, so a crash can’t leave a lasting second file with the head’s id (spec §3 I4). Each marker’s name carries a token of its own, so a relocation settles only its own copy, never a later one placed at the same path.
Structs§
- Relocated 🔒
- A copy
relocateplaced, with the marker that makes it this relocation’s. Each relocation’s marker has its own name, so holding one is ownership: once a sweep has taken it (and a later relocation placed a new copy at the same path, under a new marker), settling through the old handle finds its marker gone and touches nothing (codex P1 on #3907).
Constants§
- MARKER_
SUFFIX 🔒 - TAIL_
CHECK_ 🔒BYTES - How much of a session’s end is read first to find its last record; more is read when the record is larger.
- TMP_
INFIX 🔒
Functions§
- can_
relocate 🔒 - Whether session
sidforcwdunderconfig_dircan be copied in byrelocate: it exists (source_file) and holds a complete record. Its last record may still be being written, by a parent a fork starts from mid-turn:relocatecuts the copy back to its last complete one. - copy_
name_ 🔒of - The copy a marker (its name without the suffix) is for. A marker from
before tokens is
<sid>.jsonl.agentmux-relocated. - global_
twin 🔒 <shared>/identities/<id>/<rest…>for a config dir under some…/identities/<id>/<rest…>, when that differs fromconfig_dir.- is_
resumable_ 🔒file - Whether
pathis a session the CLI can resume: a non-empty file whose last record parses (spec H5 — a file cut mid-write is not resumed). - last_
record 🔒 path’s last record and the offset where it ends. Withcomplete_onlythat is the last newline-ended record, so a record still being written is passed over; a file with no newline at all is one record either way, left to the parse to judge. Reads the file’s end, widening the window until it holds the whole record, however large (a big tool result).- marker_
for 🔒 <copy>.<token>.agentmux-relocated: the token makes each relocation’s marker its own.- parses 🔒
- Whether
recordis one JSON value (an empty one isn’t: an empty file isn’t resumable). - place 🔒
- Give the finished copy its real name, only if nothing has it: two spawns
relocating the same head at once both pass the
existscheck, and a rename would let the second replace the first’s copy under both markers (codex P1 on #3924). A hard link fails on an existing name, atomically. - relocate 🔒
- Copy
srcin as sessionsidforcwdunderdest_config_dir, marked asowner_uid’s. Refuses when the destination already exists: an existing file with the head’s id is never overwritten (spec §4.3 (5)). - remove 🔒
- Remove a copy
relocateplaced, and its marker, if it is still this relocation’s. The marker goes first: only a relocation that still held it removes the copy. Returns whether it did. - remove_
file 🔒 - source_
file 🔒 - The session file
sidforcwdunderconfig_dir, or under the always-global history dir of the same login when the channel-local one is gone (a cleaned-up build channel):channels/<c>/identities/<id>/claudehas itsprojects/linked toshared/identities/<id>/claude/projects. - sweep 🔒
- Remove every copy
owner_uidleft incwd‘s project dir underconfig_dir(a process that died before its fork reported an id), and any half-made one. Returns how many copies went. Other agents’ copies and every ordinary session are left alone. - trim_
to_ 🔒complete_ records - Cut
pathback to its last complete (newline-ended) record: a copy of a session file another process is appending to may end mid-record. Returns the kept length. A tail with no newline at all is left as it is; the resumability check that follows judges it. - unmark 🔒
- Drop a copy’s marker only, keeping the copy: the CLI resumed it in place, so it is a live session now and no sweep may remove it. Returns whether the copy was still this relocation’s.