---
name: ssh-remote-dev
metadata:
  exposure: discoverable
description: Develop, inspect, test, and transfer files in a user-authorized remote working directory over SSH. Use when work must happen on a configured SSH host rather than only in the local workspace; prefer SSH config aliases and key-based authentication. Do not use for non-SSH services or as permission to access hosts the user has not placed in scope.
---

# SSH Remote Development

Operate remote repositories through the system `ssh` and `scp` clients. Treat the remote host and filesystem as external state: this skill supplies a workflow, not standing authorization for unrelated hosts or destructive actions.

## Establish the target

- Resolve the SSH destination from the user's named `~/.ssh/config` alias when possible. Never expose private-key contents, passwords, passphrases, tokens, or full SSH configuration in output.
- Establish one explicit remote working directory for the task. If the alias or directory is genuinely missing, ask for only that missing value.
- Prefer non-interactive key or SSH-agent authentication. Use `-o BatchMode=yes` and a short `-o ConnectTimeout=10` for probes so a command cannot hang on a password prompt.
- When the authorized host only supports a password, start `ssh` or `sftp` with a TTY and send the password only to the live prompt. Never place it in the command line, an environment variable, an askpass helper, a generated script, a project file, or the skill. Keep one bounded interactive session when practical instead of repeatedly handling the password, and close it when the task ends.
- Start with a read-only probe that prints the canonical directory, platform/shell information when relevant, and repository status. Verify that the canonical path is the intended target before any write.
- Each SSH invocation is stateless. Include the directory and required environment setup in every command, for example `cd -- '<remote-root>' && <command>`. Do not assume a previous `cd`, exported variable, virtual environment, or shell session persists.
- Default to a POSIX shell only when the probe confirms one. Adapt commands for a Windows/PowerShell remote instead of forcing Bash syntax.

## Work in the remote repository

- Inspect before changing: read the relevant files, repository instructions, current branch, `git status --short`, and focused diffs. Preserve pre-existing edits and untracked files as user work.
- Disable Git paging per invocation for captured output, for example `git -c core.pager=cat status --short` or `git -c core.pager=cat diff --stat`. An interactive pager can consume later commands as keystrokes; if one opens unexpectedly, quit it before sending anything else.
- Keep remote commands narrowly scoped and outputs bounded. Prefer targeted searches and `head`, `tail`, or equivalent over dumping large files or logs.
- Run the smallest useful verification after changes, then report the exact remote path, files changed, and test result.
- Never run `git reset --hard`, checkout-based discard, force push, recursive deletion, or broad cleanup unless the user explicitly requests that exact destructive outcome. Validate canonical targets immediately before an authorized destructive operation.
- For a recoverable removal, prefer moving the item under `<remote-root>/.codex-trash/<timestamp>/` and tell the user where it went. Do not claim this is recoverable if it crosses filesystems or the move failed.

## Edit files safely

For a trivial, deterministic change, a carefully quoted remote command is acceptable. For non-trivial source edits, use this conflict-aware workflow:

1. Record the remote file's identity and hash (`sha256sum` or platform equivalent), and whether it exists.
2. Download it to a task-specific staging directory inside the local writable workspace.
3. Edit the staged file with `apply_patch` and run any useful local checks.
4. Recheck the remote hash immediately before upload. If it changed, stop and reconcile instead of overwriting concurrent work.
5. Upload to a uniquely named temporary file in the same remote directory. Preserve the original mode when relevant, then atomically rename the temporary file over the destination.
6. Clean up only the temporary artifact created by this workflow. Re-read or hash the installed file and inspect `git diff` remotely.

For a new file, first verify the destination still does not exist. For multiple related files, use one task-specific staging tree and repeat the conflict check for every existing destination. Avoid brittle `sed`/regex rewrites for semantic code changes.

## Transfer files

- Use `scp -- <local-path> <alias>:<remote-path>` for uploads and the inverse for downloads. Quote local and remote paths independently; do not construct commands from untrusted remote output.
- Keep local downloads within the current workspace or another user-approved writable directory.
- Upload writes are external mutations. Use the temporary-upload-and-rename pattern for files that replace existing content.
- Do not add `StrictHostKeyChecking=no`. If host-key verification fails or a stored key changes, stop and ask the user to verify the fingerprint through a trusted channel.
- For a large read-only code review, a selective local mirror is acceptable: copy only first-party source, tests, manifests, and sanitized configuration examples into a clearly named task cache. Exclude dependency trees, build outputs, caches, logs, data, model weights, nested third-party repositories, and live secret files. Treat the mirror as non-authoritative, do not run Git operations from it, and re-read remote files before any later edit.

## Long-running work

- Do not hold one SSH call open indefinitely. For a user-requested service or long test on a POSIX host, use `nohup`/`setsid` with a task-specific log and PID file, return promptly, and verify it in a fresh SSH call.
- A timeout or disconnected channel does not prove whether a remote command stopped. Check the PID, log, process marker, or expected artifact before retrying so duplicate jobs are not started.
- Stop only the recorded PID after verifying its command line belongs to this task. Do not use broad `pkill` patterns when an exact PID is available.

## Permissions and failures

- Request host/network execution approval when the runtime requires it. A skill cannot bypass the sandbox or approval system.
- Do not install packages, change SSH server configuration, alter firewall rules, modify system services, or write outside the agreed remote working directory unless the user separately authorizes it.
- On authentication failure, report the alias and failure class without echoing credentials. On network failure, distinguish DNS, timeout, refusal, host-key, and authentication errors before retrying.
- Limit automatic retries to one for transient connection failures. Do not retry commands with uncertain side effects until their remote result has been checked.
