Skip to main content

Module claude_peer

Module claude_peer 

Source
Expand description

Live Claude Code peer sessions: registry discovery and inbound policy.

Claude Code is the one supported harness whose running interactive sessions are addressable. Each live process registers ~/.claude/sessions/<pid>.json and binds the Unix socket named in it. The catalog (supercode_interchange::catalog) is deliberately about persisted state only, so nothing there may claim liveness; this module is the separate, explicitly process-checking half; it feeds session activity and the mail router’s native door, which reach clients as a discovered descriptor’s activity and delivery.

Two rules earn their place here:

  1. A registry file is not a live session. These files survive a crash, so every read re-checks the recorded pid with kill(pid, 0) and drops the record when the process is gone. A live pid is still not the session’s holder when Claude Code itself says it is not: a window whose session was moved to the background keeps its record with parkedJobId set and the status it had at that moment (the background job registers its own record), and a pid the OS reused after the session died fails the recorded procStart. Claude Code skips both when it looks for a session’s holder, and so do we.
  2. Nothing here writes the socket. The socket path is documented, but its wire frame is not, and a foreign process authenticating to it is not a supported case. Messages reach a live session through a Claude relay (crate::claude_relay), a headless Claude that sends with Claude’s own SendMessage.

Structs§

ClaudePeerRefusalError
A refusal paired with the detail that names it.
ClaudePeerSession
One live Claude Code session: a registry record whose pid answered kill(pid, 0) during the read that produced this value.
ClaudePeerSettings
The user-settings portion Supercode can inspect without pretending to know a target process’s complete managed/project/CLI precedence stack.

Enums§

ClaudeCrossSessionInbound
User-level policy Claude Code applies to messages from other sessions.
ClaudePeerRefusal
Why a message could not be delivered into a live session.
ClaudePeerSettingsError
Failure to read or safely update Claude Code’s user settings.
ClaudePeerStatus
Activity a live Claude Code session reports for itself.

Functions§

read_claude_peer_settings
Inspect only the user-level inbound setting. The report deliberately does not claim to be Claude’s effective value because managed, project, and command-line settings can have higher precedence in a particular target.
read_registry
Read every LIVE session from a Claude registry directory.
registry_dir
Directory holding the live-session registry for the configured Claude home.
resolve_live_session
Resolve session_id to the live Claude session running it.
update_claude_peer_settings
Set or reset Claude Code’s user-level inbound policy. expected_revision prevents an explicit UI action from overwriting settings inspected before another process changed the file.
user_settings_path
Claude Code’s user settings file for the configured Claude home.
write_claude_peer_settings
Explicitly update Claude Code’s user-level inbound policy while preserving every unrelated setting. The write is atomic, refuses symlinks, and aborts when it observes an edit between its initial read and commit.