Skip to content

feat(session): attach to running tools in other tmux sessions#74

Merged
folke merged 9 commits intomainfrom
sessions
Oct 7, 2025
Merged

feat(session): attach to running tools in other tmux sessions#74
folke merged 9 commits intomainfrom
sessions

Conversation

@folke
Copy link
Copy Markdown
Owner

@folke folke commented Oct 7, 2025

Session Management and Multi-Backend Support

This PR introduces a new session management system that allows Sidekick
to discover and attach to running CLI tools across different backends.

image

User-Facing Changes

Attach to Running Sessions

Sidekick can now detect and attach to CLI tools already running in other
tmux/zellij sessions:

  • When selecting a CLI tool, you'll see running sessions from other
    tmux/zellij windows
  • Simply select a running session to attach to it instead of creating a
    new one
  • Sessions are identified by tool name and working directory

Cross-Platform Process Discovery

Process detection now works across Linux, macOS, and BSD systems:

  • Linux: Uses /proc filesystem (fastest)
  • macOS/BSD: Falls back to lsof and ps commands
  • Automatically detects the best available method

OpenCode Integration (Experimental)

Added support for OpenCode as a
backend:

  • Automatically discovers running OpenCode instances
  • Send prompts via HTTP API
  • Works alongside traditional terminal-based tools

Internal Changes

Refactored Session Architecture

  • New Session abstraction: Unified interface for terminal, tmux,
    zellij, and HTTP-based backends
  • Backend registration system: Clean API for adding new session types
  • State management: Tracks session lifecycle (started, attached,
    running)
  • Process discovery: New Procs module for finding running processes

Reorganized CLI Module Structure

lua/sidekick/cli/
├── init.lua # Public API (simplified)
├── state.lua # Session state management
├── procs.lua # Process discovery (NEW)
├── terminal.lua # Terminal backend
├── session/
│ ├── init.lua # Session abstraction (NEW)
│ ├── tmux.lua # Tmux backend (refactored)
│ └── zellij.lua # Zellij backend (refactored)
└── ui/
├── prompt.lua # Prompt selection UI (NEW)
└── select.lua # Tool selection UI (NEW)

Platform Detection

  • Uses vim.uv.fs_stat("/proc/self") to detect /proc availability
  • Gracefully falls back to POSIX-compliant tools (ps, lsof)
  • Windows support remains unchanged (disabled for now)

Utilities

  • Util.curl(): Simple HTTP client wrapper for communicating with
    HTTP-based backends
  • Supports JSON encoding, custom headers, and different HTTP methods

Breaking Changes

None. The public API remains backward compatible.

Technical Details

Session Discovery Flow

  1. Each backend implements sessions() to return running instances
  2. Sessions are matched with process discovery to find PIDs, ports, etc.
  3. User selects a session from the unified list
  4. Backend-specific attach() creates the connection
  5. Unified send()/submit() API works across all backends

Backend Interface

Backends implement:

  • sessions(): Discover running instances
  • attach(): Connect to a session
  • send(text): Send text to the session
  • submit(): Submit/execute the current input

This makes it trivial to add new backends (HTTP APIs, other terminal
multiplexers, etc.).

@folke folke requested a review from Copilot October 7, 2025 15:45
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements functionality to attach to running CLI tools in other tmux sessions, enabling session discovery and management across multiple multiplexer sessions. The feature allows users to find and connect to existing CLI tool instances running in different tmux or zellij sessions.

Key changes include:

  • Complete rewrite of the CLI session management architecture with new state tracking
  • Added support for discovering and attaching to running CLI tools across multiplexer sessions
  • Replaced the old mux/terminal system with a unified session-based approach

Reviewed Changes

Copilot reviewed 28 out of 28 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
sk/cli/*.lua New CLI tool configuration files defining commands and process patterns for various AI coding tools
lua/sidekick/util.lua Enhanced utility functions to support string arrays in notifications and added state persistence
lua/sidekick/health.lua Updated health check to use new tool configuration system
lua/sidekick/config.lua Major config changes including new mux settings, tool management functions, and highlight groups
lua/sidekick/cli/ui/*.lua New UI components for tool selection and prompt selection with rich formatting
lua/sidekick/cli/tool.lua New tool abstraction layer with process matching capabilities
lua/sidekick/cli/terminal.lua Refactored terminal management to work with new session system
lua/sidekick/cli/state.lua New state management system for tracking CLI tool sessions and status
lua/sidekick/cli/session/*.lua New session backend implementations for tmux and zellij multiplexers
lua/sidekick/cli/procs.lua New process discovery and management system for finding running CLI tools
lua/sidekick/cli/init.lua Completely rewritten CLI interface using new state-based architecture

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread lua/sidekick/cli/terminal.lua Outdated
Comment thread lua/sidekick/cli/init.lua
Comment thread lua/sidekick/cli/init.lua
Comment thread lua/sidekick/cli/state.lua
@folke
Copy link
Copy Markdown
Owner Author

folke commented Oct 7, 2025

@copilot can you update the description of this PR with the most relevant changes?

@folke folke linked an issue Oct 7, 2025 that may be closed by this pull request
4 tasks
@folke folke merged commit 1de752c into main Oct 7, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants