Repository navigation
Description
Problem
Messages received through session-peer contain the message body, but the receiver cannot reliably tell whether the sender is Claude Code or Codex.
The current From: envelope only discovers a Claude sender through CLAUDE_CODE_MESSAGING_SOCKET. A send initiated from Codex therefore has no useful agent identity even though Codex exposes CODEX_THREAD_ID/CODEX_SESSION_ID. This becomes especially confusing when both agent types operate in the same project.
Remote sends have a related addressing problem: callers may use an SSH alias, a Tailscale IP, a device hostname, or a stale name. session-peer does not consult tailscale status --json to identify the peer's current MagicDNS name before connecting.
Related work: #15 added the original Claude sender header. #45 covers broader reply URI and route diagnostics. This issue is limited to identifying the current sender agent and resolving known Tailscale SSH endpoints to their canonical MagicDNS identities.
Proposed behavior
-
Detect the sending agent from its runtime environment:
- Claude Code:
CLAUDE_CODE_MESSAGING_SOCKETplus the matching session registry record. - Codex:
CODEX_THREAD_ID, falling back toCODEX_SESSION_ID.
- Claude Code:
-
Include an explicit agent-qualified sender in the default message envelope, for example:
From: codex:01900000-0000-7000-8000-000000000001 @ [email protected]and:
From: claude:documents-ed @ [email protected] -
Generate a reply target for either detected sender type (
<claude-name>orcodex:<thread-uuid>), while keeping--no-fromand--no-reply-tobehavior. -
Before an SSH-backed
list,send, orupdate, inspecttailscale status --jsonwhen available. If the supplied destination matches a known Tailscale peer by MagicDNS name, short DNS name, hostname, or Tailscale IP:- verify and report the peer's canonical MagicDNS FQDN;
- reject a peer that Tailscale reports offline instead of attempting a misleading send;
- preserve an explicitly supplied SSH username.
-
Keep the caller's original SSH destination as the SSH config alias, then override
HostNamewith the verified MagicDNS FQDN and retain the originalHostKeyAlias. This preserves matchingHost,User,Port,IdentityFile, andknown_hostsconfiguration while routing the connection to MagicDNS. -
Report the caller's original value as
sshHostalongside canonicalhostwhen they differ. -
Keep ordinary non-Tailscale SSH hosts working when no Tailscale peer matches.
-
Prefer this machine's MagicDNS name over its Tailscale IP in sender and reply metadata when MagicDNS is enabled.
-
Keep repository tests under
tests/and configure CI discovery explicitly from that directory.
Acceptance criteria
- Default envelopes identify
claudeorcodexexplicitly and include the sender session name/thread UUID. - Codex-originated messages can advertise a reply command targeting the originating Codex thread.
- Existing suppression flags still independently remove
From:andReply:. - Known Tailscale destinations are resolved from hostname, short name, or Tailscale IP to the current MagicDNS FQDN; usernames are preserved.
- SSH routes to the verified FQDN while existing destination-specific config and host-key lookup continue to apply.
- Known offline peers fail before SSH is invoked.
- Unknown/generic SSH destinations remain compatible.
- Human and JSON results report canonical
host, plussshHostwhen the supplied value differs. - Unit tests cover Claude, Codex, plain-shell, MagicDNS, offline, ambiguous, and generic-SSH paths without requiring a live tailnet.
- Tests are organized under
tests/, and both explicit and default unittest discovery work. - README and the bundled session-peer skill describe the sender envelope and MagicDNS resolution behavior.
Live verification note
During implementation, using the known peer's MagicDNS FQDN directly caused host-key verification to fail because the existing known_hosts entry was keyed by the supplied Tailscale IP. The final SSH invocation keeps that IP as the destination/config alias, adds the verified FQDN through HostName, and retains the IP through HostKeyAlias. A read-only remote list then succeeded and returned the canonical host and original sshHost.
Activity