rhost
by starfield17
README.md
# rhost
**Operate SSH-reachable Linux hosts from coding agents or scripts over standard OpenSSH.**
[](https://github.com/starfield17/rhost/actions/workflows/ci.yml)
[](https://github.com/starfield17/rhost/releases/latest)
[](LICENSE)
`rhost` gives coding agents (Claude Code, Codex, or any stdio MCP client) and CLI scripts local-like execution semantics over your existing OpenSSH setup: foreground commands, recoverable background Runs, compare-and-swap file edits with rollback, and persistent `tmux` sessions—backed by one capability layer (`CLI`, schema-v8 `JSON`, and stdio `MCP`), with zero remote daemon and zero remote Python.
```text
Claude Code / Codex / CLI / JSON (schema v8)
-> local OpenSSH (~/.ssh/config, ssh-agent, host keys, ControlMaster)
-> standalone C99 remote helper / tmux (recoverable Runs, CAS files, PTYs)
```
## Why it's built this way
- **OpenSSH instead of a custom SSH stack**: Reuses `~/.ssh/config` (aliases, `ProxyJump`, `Match`), `ssh-agent`, strict host-key verification, and `ControlMaster` (`ControlPersist=15m`). `rhost` never prompts for passwords, stores keys, or weakens host-key checks.
- **Survives disconnects and timeouts**: Long-running jobs (`run start` / `rhost_run`) execute under a standalone remote monitor with durable state under `~/.local/state/rhost/v5` (`RHOST_REMOTE_STATE`). Client timeouts or cancellations only stop local observation, and uncertain submissions deduplicate safely.
- **Bounded reads and safe file edits**: File reads default to **8 KiB** (`8192` bytes) and Run/session log previews default to **4 KiB** (`4096` bytes) with byte cursors (`run watch` follows both streams) instead of flooding agent context. File replacements verify whole-file SHA-256 and record changesets for rollback (`fs undo`).
- **C99 helper instead of remote Python**: Native file operations and recoverable Runs run through a standalone C99 binary (`helper/`) cached privately at `~/.cache/rhost/helper/`. Preparation reuses a valid cache, compiles with an existing remote C99 `cc`, or uploads a SHA-256-verified static Linux musl release binary (`linux-x86_64`, `linux-aarch64`), with no remote daemon and no package installs.
## Install
Release binaries (macOS and Linux on `amd64`/`arm64`; requires local Python 3.11+, verifies SHA-256 before atomic replacement):
```bash
curl -fsSL https://raw.githubusercontent.com/starfield17/rhost/main/scripts/install.sh | bash
```
Use `RHOST_VERSION` to pin a release or `RHOST_INSTALL_DIR` to set the binary directory (defaults to `~/.local/bin`, or an existing writable standalone `rhost` / Homebrew `bin` on macOS `PATH`). Run `rehash` or `hash -r` if an open shell cached a prior path.
From source (Rust `1.88.0+`):
```bash
git clone https://github.com/starfield17/rhost.git
cd rhost
make build-release
install -m 755 target/release/rhost ~/.local/bin/rhost
```
`make build-release` runs `cargo build --locked --release --bin rhost` and stamps commit/build date into `rhost version --json`; `make build` builds the debug binary.
## Connect an agent
Ensure noninteractive OpenSSH works first using an SSH alias, `user@example-host`, or hostname:
```bash
claude mcp add --transport stdio --scope local rhost -- rhost mcp
codex mcp add rhost -- rhost mcp
```
Generic stdio clients launch `rhost` with `["mcp"]` (use an absolute path if a GUI client's `PATH` differs). Filter advertised tools at startup with `rhost mcp --tools runs,files` (default `all`; groups: `runs`, `files`, `sessions`, `diagnostics`).
Install the optional Agent Skill to load workflow and recovery guidance on demand:
```bash
npx skills add starfield17/rhost --skill rhost
```
[plugin.json](plugin.json) and [.codex-plugin/plugin.json](.codex-plugin/plugin.json) package [skills/rhost/SKILL.md](skills/rhost/SKILL.md); they require the `rhost` CLI separately and do not register MCP. See [MCP setup guide](skills/rhost/references/MCP.md) for client configuration, `SSH_AUTH_SOCK`, tool schemas, and cancellation semantics.
## Quick examples
```bash
# Inspect host readiness (read-only) and read or patch a remote file with CAS protection
rhost brief gpu --json
rhost fs read gpu ~/work/project/config.toml --json
rhost fs patch gpu ~/work/project/config.toml --from - --json <<'EOF'
{"edits":[{"old_text":"batch_size = 16","new_text":"batch_size = 32"}]}
EOF
# Start a recoverable background Run and follow output across reconnects
rhost run start gpu --cwd '~/work/project' --command 'cargo test --locked' --json
rhost run watch gpu <run_id> --json
# Device Mode: push a local tree, run remotely, and pull artifacts without remote Git
rhost push ./project gpu --name demo
rhost run --at demo --hosts gpu --command 'make test'
rhost pull gpu output.json ./output.json --at demo
# Foreground command execution
rhost exec gpu --cwd '~/work/project' --command 'uname -a'
```
Single closed JSON requests (`schema_version: 8`, matching MCP `structuredContent`) work via stdin:
```bash
rhost request --from - <<'EOF'
{"schema_version":8,"operation":"fs.read","host":"gpu","params":{"path":"~/work/project/config.toml","max_bytes":4096}}
EOF
```
## Operations and references
| Need | Interface | Reference |
| --- | --- | --- |
| Bounded read/search, CAS edit, changesets | CLI, JSON, MCP `rhost_read`, `rhost_find`, `rhost_edit` | [FILES.md](skills/rhost/references/FILES.md) |
| Recoverable work surviving CLI/MCP exit | CLI, JSON, MCP `rhost_run` | [RUNS.md](skills/rhost/references/RUNS.md) |
| Stateful shell, REPL, debugger (`tmux`) | CLI, JSON, MCP `rhost_term` | [SESSIONS.md](skills/rhost/references/SESSIONS.md) |
| Foreground command, transfers, Device Mode, tunnels | CLI (`exec`, `fs put/get/sync/mirror`, `push/pull`, `tunnel`) | [CLI.md](skills/rhost/references/CLI.md) |
| Host brief, aliases, diagnosis, MCP setup | CLI, JSON, MCP | [MCP.md](skills/rhost/references/MCP.md#discover-and-call-tools) |
| Helper cache/build policy, `error.code` recovery, safety | Policy & recovery tables | [NATIVE.md](skills/rhost/references/NATIVE.md#preparation-policies), [RECOVERY.md](skills/rhost/references/RECOVERY.md), [SAFETY.md](skills/rhost/references/SAFETY.md) |
- **Diagnosis vs. preparation**: `rhost doctor` probes shell tools and resolved `command -v` paths (`ok:true` means the probe completed; inspect `capabilities`). Native `fs.*` and `run.*` prepare the C99 helper automatically; `rhost helper prepare` returns `generation`, `remote_time_unix`, and helper identity explicitly (`rhost helper status` reads an existing namespace without creating one).
- **Remote requirements**: `exec` and `doctor` require `/bin/sh`, `bash`, `ps`, `base64`, and either `setsid` or Perl with `POSIX::setsid`. `session` requires `bash`, `tmux`, `flock` (`session attach` is refused with `USAGE_ERROR`); resumable/checksum transfers require `rsync`; native `fs.*` and `run.*` require only POSIX `sh` utilities to bootstrap the C99 helper (no remote Python or `tmux`).
- **Schema and boundaries**: Public JSON uses schema v8 (`v7.1.0+`); branch on `error.code` and `error.recovery`, not prose. See [state discovery and retention](skills/rhost/references/FILES.md#state-discovery-and-retention) for `run.list`, `fs.changeset.list`, `state.list`, `state.usage`, and `state.prune`. `rhost` does not manage SSH credentials, system packages, Git branches/worktrees, or job scheduling.
## Docs, schemas, and verification
- [Architecture and ownership](docs/ARCHITECTURE.md)
- [Contract ledger](docs/CONTRACT.md)
- [Context-bounded observation (v5.3.0)](docs/architecture/context-v530.md)
- [Request schema v8](schemas/request-v8.schema.json) and [Result schema v8](schemas/result-v8.schema.json)
- [Agent skill](skills/rhost/SKILL.md)
- [Contributor rules](AGENTS.md) and [Maintenance policy](docs/MAINTENANCE.md)
```bash
make test-smoke # offline Rust black-box suite (no network)
make check # fmt, clippy, unit/contract/structure/portability/packaging checks
# Manual pre-release real-SSH suites (require an explicit target)
RHOST_TEST_HOST=<user>@<host> RHOST_BIN=./target/debug/rhost make test-live
RHOST_TEST_HOST=<user>@<host> RHOST_BIN=./target/debug/rhost make test-live-session
RHOST_TEST_HOST=<user>@<host> RHOST_BIN=./target/debug/rhost make test-live-all
```
`make test-smoke` and `make check` run offline; CI builds the shipping Linux helpers and verifies them against disposable strict-host-key `sshd` fixtures. Real-host `test-live*` and `test-live-helper` runs are optional manual pre-release verification; see [Maintenance policy](docs/MAINTENANCE.md).
## License
`rhost` is released under the [BSD 3-Clause License](LICENSE).
This server cannot be deployed
Maintenance
ActivityActive
ResponsivenessNo recent community issues