feat(daemon): implement CustomPaneBackend JSON-RPC protocol (Phase 1)#515
Open
feat(daemon): implement CustomPaneBackend JSON-RPC protocol (Phase 1)#515
Conversation
Implements KILD's side of the CustomPaneBackend protocol proposed in anthropics/claude-code#26572. This gives Claude Code a clean socket-based pane management API without tmux impersonation, running in parallel with the existing shim (Phase 1 — no regressions). Protocol: - Daemon socket (`~/.kild/daemon.sock`) now routes connections based on the first message: JSON with a `"method"` key → pane backend handler, otherwise → existing ClientMessage JSONL handler - Handshake: `initialize` with optional `session_hint`; daemon responds with `protocol_version`, `capabilities`, `self_context_id` - Methods: `spawn_agent`, `write`, `capture`, `kill`, `list` - Push events (no id): `context_output` (base64 PTY data), `context_exited` - Context IDs: `ctx_0` (leader, pre-registered from `session_hint`), `ctx_1`, `ctx_2`, … for spawned agents New env vars injected into daemon PTYs: - `CLAUDE_PANE_BACKEND_SOCKET` — socket path for Claude Code to connect to - `CLAUDE_PANE_BACKEND_SESSION_ID` — echoed back as `session_hint` on init Changes: - `protocol/pane_backend.rs` — request/response/event types + ContextMap - `server/pane_backend.rs` — async connection handler with full dispatch - `server/connection.rs` — `route_connection` detects protocol on first line; `handle_connection_with_first_line` handles the KILD protocol path - `session/state.rs` — `parent_session_id` field + `subscribe_output_passive` - `session/manager.rs` — `parent_session_id` param on `create_session`, `list_sessions_by_parent`, `subscribe_output_passive` - `daemon_helpers.rs` — inject pane backend env vars alongside shim vars The tmux shim and all existing shim vars are kept unchanged in Phase 1.
Moves protocol/pane_backend.rs and server/pane_backend.rs into a cohesive src/pane_backend/ module directory with three focused files: pane_backend/protocol.rs — all wire types (request/response/event/params) pane_backend/context.rs — ContextMap (ctx_id ↔ session_id mapping) pane_backend/handler.rs — connection handler + dispatch_request Pure structural move — zero logic changes. Makes the protocol easier to link in the upstream issue (anthropics/claude-code#26572) and to review when Anthropic requests changes.
…rotocol spec Two corrections from review against anthropics/claude-code#26572: 1. capture response: return {"text": "<utf-8 string>"} instead of {"data": "<base64>"}. Scrollback is human-readable terminal output, not raw binary — base64 encoding was only used for context_output streaming where arbitrary bytes flow. 2. InitializeParams: add capabilities: Vec<String> with #[serde(default)]. Claude Code sends {"capabilities": ["events"]} in the initialize params; the field was previously silently dropped. Deserialized but not yet acted upon — future handlers can gate behaviour on declared capabilities. Also adds test_deserialize_initialize_with_capabilities to protocol tests.
7ae53d7 to
9de50e9
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements KILD's side of the CustomPaneBackend protocol proposed in
anthropics/claude-code#26572.
The daemon's Unix socket now speaks two protocols on the same path — the existing
KILD
ClientMessageJSONL protocol and a new JSON-RPC 2.0 pane backend protocol. Thefirst line from a new connection decides which handler is invoked:
This is Phase 1 (parallel support). The tmux shim and all shim env vars are kept
unchanged — no regressions.
Protocol
Changes
kild-daemonpane_backend/protocol.rs— wire types:PaneBackendRequest/Response/Event, params structs,JsonRpcErrorpane_backend/context.rs—ContextMapforctx_id ↔ daemon_session_idmappingpane_backend/handler.rs— async connection handler,dispatch_request, full method implementationserver/connection.rs—route_connectiondetects protocol on first linesession/state.rs—parent_session_idfield +subscribe_output_passivesession/manager.rs—parent_session_idparam oncreate_session,list_sessions_by_parent,subscribe_output_passivekild-coresessions/daemon_helpers.rs— injectsCLAUDE_PANE_BACKEND_SOCKETandCLAUDE_PANE_BACKEND_SESSION_IDinto daemon PTY env alongside existing shim varsNew env vars (injected into daemon PTYs)
CLAUDE_PANE_BACKEND_SOCKETCLAUDE_PANE_BACKEND_SESSION_IDsession_hintso daemon can correlate the connectionRelated
.claude/PRPs/plans/claude-code-teams-research/custom-pane-backend-protocol.md