Skip to main content

Module continuity_relocate

Module continuity_relocate 

Source
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 relocate placed, 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 sid for cwd under config_dir can be copied in by relocate: 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: relocate cuts 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 from config_dir.
is_resumable_file 🔒
Whether path is 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. With complete_only that 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 record is 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 exists check, 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 src in as session sid for cwd under dest_config_dir, marked as owner_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 relocate placed, 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 sid for cwd under config_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>/claude has its projects/ linked to shared/identities/<id>/claude/projects.
sweep 🔒
Remove every copy owner_uid left in cwd‘s project dir under config_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 path back 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.