Skip to content

feat: identify sender agent and canonicalize Tailscale SSH targets #57

Closed

Description

@abruption

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_SOCKET plus the matching session registry record.
    • Codex: CODEX_THREAD_ID, falling back to CODEX_SESSION_ID.
  • 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> or codex:<thread-uuid>), while keeping --no-from and --no-reply-to behavior.

  • Before an SSH-backed list, send, or update, inspect tailscale status --json when 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 HostName with the verified MagicDNS FQDN and retain the original HostKeyAlias. This preserves matching Host, User, Port, IdentityFile, and known_hosts configuration while routing the connection to MagicDNS.

  • Report the caller's original value as sshHost alongside canonical host when 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 claude or codex explicitly 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: and Reply:.
  • 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, plus sshHost when 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

  1. added
    enhancement
    on Sep 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions