Skip to main content

Module session

Module session 

Source
Expand description

Multi-session wire on one machine (v0.5.16).

Problem: multiple Claude Code (or any agent harness) sessions on the same machine share a single WIRE_HOME, which means they share the same DID, same relay slot, same inbox JSONL, and same daemon. Peers have no way to address a specific session, and the operator can’t tell which session sent what.

Solution: a wire session subcommand that bootstraps isolated per-session WIRE_HOME trees. Each session gets its own identity, handle, relay slot, daemon, and inbox/outbox. Sessions pair with each other through the public relay (wireup.net) like any other peer — no protocol changes. The bilateral-pair gate from v0.5.14 still applies in both directions.

Storage layout:

~/.local/state/wire/sessions/
  registry.json                — cwd → session_name map
  <session-name>/               — full WIRE_HOME tree per session
    config/wire/...
    state/wire/...

Naming: derived from basename(cwd) so re-opening the same project reuses the same session identity. Collisions across two different paths with the same basename get a 4-char SHA-256 path-hash suffix.

Structs§

FederationOnlySessionView
Sessions with no Local endpoint — shown separately so the operator knows they exist but are federation-only.
LocalEndpointView
Stripped view of a Local endpoint for tooling output. Drops slot_token because it is a bearer credential — exposing it through wire session list-local --json would risk accidental leak via logs, screenshots, or piped output. Routing code uses the full Endpoint from relay.json directly; this type is for human/JSON observation only.
LocalSessionListing
Result shape for wire session list-local. local is grouped by the local-relay URL so output can render each cluster of mutually- reachable sister sessions together. federation_only lists the rest.
LocalSessionView
One row of wire session list-local output: a session that has a Local-scope endpoint plus metadata to render it.
SessionInfo
Summary of one on-disk session for wire session list.
SessionRegistry

Functions§

derive_name_from_cwd
Derive a stable session name for the given cwd. Resolution order:
detect_session_wire_home
v0.6.7: cwd → session WIRE_HOME lookup. Read-only.
list_local_sessions
Build the listing for wire session list-local from current on-disk state. Read-only; no daemon contact, no relay probe.
list_sessions
maybe_adopt_session_wire_home
v0.6.7: apply detect_session_wire_home for the current process.
read_registry
read_session_endpoints
Read a session’s relay.json and return its self.endpoints[] array (v0.5.17 dual-slot). Empty Vec on any read/parse error — this is a best-effort discovery helper, not a verification tool. A pre- v0.5.17 session writes only the legacy flat fields; self_endpoints promotes those to a federation-only Endpoint, so the result is still meaningful for legacy sessions.
registry_path
Registry tracks cwd → session_name so repeated wire session new from the same project reuses the same identity instead of creating a fresh one each time. Lives at <sessions_root>/registry.json.
resolve_local_sister
v0.7.4: resolve an operator-typed name to a local sister session. Input may be the session NAME (e.g. slancha-api), the card HANDLE (usually equal to the name), or the character NICKNAME (e.g. noble-slate). Returns the session NAME suitable for the --local-sister add path. Case-insensitive. None on no match.
resolve_session_key
v0.13: resolve a stable per-session key — host-agnostic, with a Claude Code adapter and the path left open for other hosts. Order:
sanitize_name
Sanitize an arbitrary string to a session-name-safe form: lowercase ASCII alphanumeric + - + _, replace other chars with -, dedupe consecutive dashes, trim leading/trailing dashes, max 32 chars.
session_daemon_pid
Read a session home’s daemon pid from <home>/state/wire/daemon.pid (path-based; does NOT consult WIRE_HOME). None if absent/corrupt. Used to enumerate which daemon pids legitimately belong to a session so orphan detection doesn’t flag a sibling session’s daemon (A2).
session_dir
Full filesystem path for the named session’s WIRE_HOME root. Inside this dir the standard wire layout applies: config/wire/... and state/wire/....
session_home_for_key
v0.13: the WIRE_HOME for a resolved session key — <sessions_root>/by-key/<hash> where hash is the first 16 hex of SHA-256(key). Deterministic and cwd-independent, so two sessions never collide and there is no path-string to mis-normalize (the Windows bug cannot occur). 64 bits is collision-safe at this scale.
sessions_root
Root directory under which all session WIRE_HOMEs live.
update_registry
v0.7.0-alpha.3: flock’d read-modify-write of the session registry.
warn_on_identity_collision
v0.6.10: warn at MCP/CLI startup if another wire mcp process is already running with the same effective WIRE_HOME. Closes the “two Claudes in same cwd silently share an identity” failure mode that wasted hours of operator debugging time: today the collision is invisible (both Claudes resolve to the same wire session via v0.6.7 auto-detect, race the inbox cursor, “look identical” from the operator’s view). This surfaces it explicitly with a clear remediation path.
write_registry