Skip to content

Add OPENCODE_PORT environment variable for tmux integration - #75

Merged
alvinunreal merged 1 commit into
masterfrom
tmux-env
Jan 22, 2026
Merged

Add OPENCODE_PORT environment variable for tmux integration#75
alvinunreal merged 1 commit into
masterfrom
tmux-env

Conversation

@alvinunreal

Copy link
Copy Markdown
Owner

Summary

Changes

@greptile-apps

greptile-apps Bot commented Jan 22, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

Added support for configurable OpenCode server port via OPENCODE_PORT environment variable with default fallback to 4096. This enables multiple OpenCode instances to run simultaneously on different ports with proper tmux integration.

Changes:

  • Modified tmux session manager and utilities to read port from OPENCODE_PORT environment variable
  • Updated tests to respect the environment variable for consistent behavior
  • Enhanced documentation with clear setup instructions and examples for both default and custom port configurations

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • Simple, well-tested change that adds environment variable support with sensible defaults. All usages are consistent across codebase and tests, no breaking changes introduced
  • No files require special attention

Important Files Changed

Filename Overview
src/background/tmux-session-manager.ts Added OPENCODE_PORT environment variable support for configurable default port (lines 45-46)
src/utils/tmux.ts Added OPENCODE_PORT environment variable support for configurable port in error hint message (lines 202-205)
src/background/tmux-session-manager.test.ts Updated test mock to respect OPENCODE_PORT environment variable for consistent test behavior (lines 20-27)
README.md Updated documentation to reflect OPENCODE_PORT environment variable usage and improved setup instructions

Sequence Diagram

sequenceDiagram
    participant User
    participant Shell
    participant TmuxSessionManager
    participant TmuxUtils
    participant OpenCodeServer

    User->>Shell: export OPENCODE_PORT=5000
    User->>Shell: opencode --port 5000
    Shell->>OpenCodeServer: Start server on port 5000
    
    User->>TmuxSessionManager: Initialize plugin
    TmuxSessionManager->>TmuxSessionManager: Read OPENCODE_PORT env var (default: 4096)
    TmuxSessionManager->>TmuxSessionManager: Set serverUrl to http://localhost:5000
    
    TmuxSessionManager->>TmuxSessionManager: onSessionCreated(child session)
    TmuxSessionManager->>TmuxUtils: spawnTmuxPane(sessionId, config, serverUrl)
    
    TmuxUtils->>TmuxUtils: Check if server running at serverUrl
    TmuxUtils->>OpenCodeServer: GET /health
    OpenCodeServer-->>TmuxUtils: 200 OK
    
    TmuxUtils->>Shell: tmux split-window "opencode attach http://localhost:5000 --session <id>"
    Shell->>OpenCodeServer: Connect to session on port 5000
    OpenCodeServer-->>Shell: Stream session updates
    
    Note over TmuxUtils,Shell: Port from OPENCODE_PORT ensures<br/>correct server connection
Loading

@alvinunreal
alvinunreal merged commit 57f8380 into master Jan 22, 2026
2 checks passed
nghyane pushed a commit to nghyane/oh-my-opencode-slim that referenced this pull request Jan 31, 2026
@mhenke
mhenke deleted the tmux-env branch July 10, 2026 16:11
mhenke pushed a commit to mhenke/oh-my-opencode-slim that referenced this pull request Jul 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant