ssh_ensure_session
Return an existing SSH session or start a new one with a stable name, enabling persistent remote execution and state retention across agent tool calls.
Instructions
Return an existing running SSH session or start a new one. This is the recommended tool for agent workflows — always provide a descriptive session_name so the session can be reliably found across tool calls and conversations. When a session is reused (reused=true in response), the cwd, env, and shell parameters are ignored — they only apply when creating a new session. Check 'created' vs 'reused' in the response to know which happened.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| cwd | No | Remote directory to cd into (only when creating a new session). | |
| env | No | Remote environment variables (only when creating a new session). | |
| port | No | ||
| shell | No | Remote shell executable (only when creating a new session). | |
| target | Yes | OpenSSH target such as host, alias, or user@host. | |
| auto_close | No | When true, the session is automatically cleaned up after the remote shell or command exits. Only applies when creating a new session. Default: false. | |
| session_name | No | Stable name for this session, used for recovery and reuse across tool calls. Choose a short, descriptive kebab-case name reflecting the task, e.g. 'deploy-staging', 'tail-api-logs', 'debug-worker-3'. This name also appears in tmux session listings for human observers. Strongly recommended for any multi-step workflow. | |
| wait_seconds | No | Seconds to wait for initial output. Default: 1.0. | |
| identity_file | No | ||
| observer_mode | No | Observer mode to ensure on the reused or newly created session. Defaults to 'tmux' and falls back to transcript-only observation if tmux is unavailable. | |
| extra_ssh_args | No | Additional ssh(1) flags passed verbatim, e.g. ["-J", "jumphost"]. Prefer the dedicated port, identity_file, and strict_host_key_checking parameters. | |
| known_hosts_file | No | ||
| max_output_chars | No | ||
| strict_host_key_checking | No | Boolean or one of yes, no, ask, accept-new, off. |