Principle:1jehuang Jcode Remote Attach Over SSH
| Knowledge Sources | |
|---|---|
| Domains | Networking, DevTools |
| Last Updated | 2026-10-18 00:00 GMT |
Overview
A remote development pattern where the TUI client runs locally while workspace, tools, model credentials, and agent execution live on a remote SSH host, connected through an SSH bridge.
Description
Remote attach over SSH is a pattern for running an agent tool's user interface locally while keeping all computation, file access, and credentials on a remote host. The local TUI connects to a remote jcode daemon through an SSH tunnel, so the agent's file operations, tool execution, and model API calls all happen on the remote host with the remote host's filesystem and network.
The problem solved is local-remote split: a developer may want to use a local terminal for the agent interface but need the agent to operate on a remote workspace (e.g., a powerful GPU server, a secured production environment, or a team's shared development box). Without remote attach, the developer must SSH into the remote host and run the TUI there, losing local terminal features and keyboard handling.
The design includes credential import: local jcode auth files can be uploaded to the remote host via /login --import-local, and remote OAuth flows can be completed through the SSH bridge. Session resume works across the bridge: --resume <session_id> reconnects to an existing remote session.
Usage
Use this principle when the agent needs to work on a remote host but the user wants a local TUI experience. The trigger is: "the workspace, credentials, or compute resources are on a remote SSH host." It is appropriate for: remote development, GPU servers, production debugging, and secured environments. It is not needed when everything is local.
Theoretical Basis
The SSH bridge pattern has five operations:
- Connection setup: The TUI is launched with
--ssh <host>,--remote-working-dir <dir>, and optional--ssh-binary <path>. An SSH tunnel is established. - Remote authentication: The
/logincommand runs the OAuth flow through the SSH bridge, storing tokens on the remote host. - Local import:
/login --import-localuploads local~/.jcode/auth.jsonand provider credential files to the remote host's jcode home. - Session resume:
--resume <session_id>reconnects to an existing remote session, streaming conversation history from the remote daemon. - Self-dev over SSH: The
jcode self-devcommand runs on the remote host, building and hot-reloading the remote daemon while the local TUI stays connected.
Pseudo-code logic:
# Abstract algorithm (NOT real implementation)
def ssh_connect(host, remote_dir, ssh_binary="ssh"):
# 1. Establish SSH tunnel
tunnel = ssh_binary.connect(host)
remote_socket = tunnel.forward(remote_dir + "/.jcode/jcode.sock")
# 2. Connect local TUI to remote daemon
tui = TUIClient()
tui.connect(remote_socket)
# 3. Authentication (if needed)
if not remote_has_credentials(tunnel):
local_creds = read("~/.jcode/auth.json")
tunnel.upload(local_creds, remote_dir + "/.jcode/auth.json")
# 4. Session management
tui.run()
def ssh_resume(host, session_id):
tunnel = ssh_binary.connect(host)
remote_session = tunnel.list_sessions().find(session_id)
tui = TUIClient()
tui.connect(remote_session.socket)
tui.stream_history(remote_session)