Metadata-Version: 2.5
Name: hatchway
Version: 0.0.7
Summary: A narrow, logged opening through which an outside agent reaches your tools: an SSH forced command that runs only an allowlist kept as data
Project-URL: Homepage, https://github.com/thorwhalen/hatchway
Project-URL: Repository, https://github.com/thorwhalen/hatchway
Project-URL: Issues, https://github.com/thorwhalen/hatchway/issues
Author: Thor Whalen
License-Expression: MIT
License-File: LICENSE
Keywords: agents,allowlist,claude-code,forced-command,gateway,mcp,ssh
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Operating System :: POSIX
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Security
Classifier: Topic :: Utilities
Requires-Python: >=3.11
Provides-Extra: dev
Requires-Dist: pytest>=7.0; extra == 'dev'
Requires-Dist: ruff>=0.1.0; extra == 'dev'
Provides-Extra: mcp
Requires-Dist: fastmcp>=2.10; extra == 'mcp'
Description-Content-Type: text/markdown

# hatchway

A narrow, logged opening through which an outside agent reaches your tools.

```bash
pip install hatchway
hatchway authorize "ssh-ed25519 AAAA... my-agent" --agent assistant   # one confined key
hatchway check "crowsnest triage"                                     # what the gate would do
```

An agent that lives somewhere else (a personal assistant on its own cloud VM, another machine's scheduler, a phone shortcut) gets one SSH key. That key can do exactly one thing: run `hatchway gate`, which reads the requested command line, checks it against a **profile** (an allowlist kept as a TOML file), logs the call, and runs the allowed command directly, never through a shell. Anything not in the profile is refused with a reason.

It is the "reach in" half of connecting an outside agent to the tools on your machine, with no new server, no open port and no new dependency: OpenSSH already has forced commands, and hatchway is the policy and the bookkeeping around one.

## What you get

- **An allowlist as data.** A rule names the words the agent sends, the command that actually runs (with fixed arguments the agent cannot remove, such as `--no-verify`), and exactly which flags and names it may add. Names are checked against a pattern and passed after `--`, so they can never be read as options. Shell characters are refused outright.
- **A confined key.** `hatchway authorize` writes one `authorized_keys` line with `command="hatchway gate --agent NAME"`, `restrict` (no shell, no port, agent or X11 forwarding, no pty), and by default `from="100.64.0.0/10,fd7a:115c:a1e0::/48"`, so the key works only from a Tailscale tailnet even if sshd is reachable elsewhere. It keeps every other line, backs the file up first, and is idempotent. `hatchway revoke --agent NAME` takes it out.
- **A log of every call** in `~/.local/share/hatchway/calls.jsonl`: when, which agent, from where, what was asked, allowed or refused, exit status. Never the output. `hatchway log` shows the tail.
- **Gated classes.** A rule can belong to a class that stays off until a flag file exists. The bundled profile's `dispatch` class (starting a Claude Code session) needs both `~/.config/hatchway/allow-dispatch` and a list of directories it may start sessions in.
- **A snapshot for pulling instead of waiting.** `hatchway snapshot` runs the profile's snapshot requests (through the same allowlist) and writes the answers atomically to `~/.local/share/hatchway/out/`, with an `index.json`. The agent reads them through the gate (`snapshot triage.md`) without waiting for anything to run. `hatchway schedule --every 300` keeps them fresh with launchd (macOS) or a systemd user timer (Linux).
- **Skills for the agents that set it up.** `hatchway install-skills` links the bundled skills into one or more Claude Code homes.

## The bundled profile: `claude-fleet`

For a machine running Claude Code sessions watched by [crowsnest](https://github.com/thorwhalen/crowsnest) (live sessions) and [openloops](https://github.com/thorwhalen/openloops) (what sessions left owed or blocked). `hatchway help` prints it, and it is what the agent gets when it sends `help`:

| Request | Runs |
|---|---|
| `crowsnest [--brief\|--json]` | the roster across every configured Claude home |
| `crowsnest triage [-q] [--json]` | what needs you, what is safe to close, what is working |
| `crowsnest show\|turns\|recap\|brief NAME` | one session (show and turns quote its transcript) |
| `crowsnest ledger [NAME...]`, `groups`, `synopsis GROUP`, `questions`, `lineage`, `report` | the rest of crowsnest's read side |
| `ol`, `ol owed`, `ol blocked`, `ol dashboard` | openloops, always with `--no-verify` (verify predicates are commands taken from issue bodies, and a remote request never runs them) |
| `snapshot [FILE]` | list or print the snapshot files |
| `crowsnest spawn NAME --cwd DIR --prompt TEXT` | **gated**: starts a session on `sonnet`, in a directory under the dispatch roots |

Nothing in it kills, reaps, messages or writes into a running session.

To change it for one machine, copy `hatchway/data/profiles/claude-fleet.toml` to `~/.config/hatchway/profiles/<name>.toml`, edit it, and set `profile = "<name>"` in `~/.config/hatchway/config.toml` (or pass `--profile <name>` to `authorize`, which puts it in that key's forced command).

## The second transport: MCP

The same profile can be served as MCP tools, for an agent that speaks MCP but cannot open SSH (a claude.ai custom connector, so also the Claude app's voice mode; Claude Desktop; another machine's MCP client). One tool per rule: its `tool` name, its flags and names as typed parameters, its `help` as the description. Every call is turned back into the request words and goes through the gate, so it is decided, logged and locked exactly as an SSH call is.

```bash
pip install 'hatchway[mcp]'
hatchway mcp --profile claude-ai --list                    # the tools, with their signatures
hatchway mcp --profile claude-ai --http 8799               # serve on 127.0.0.1:8799/mcp
hatchway mcp --profile claude-ai --ssh me@laptop --identity key   # each call through that machine's gate
```

```python
from hatchway.mcp import fan_out, mk_server, routed_runner, ssh_runner, with_fallback

server = ssh_runner("root@127.0.0.1", identity="key")  # this machine, as another user
laptop = ssh_runner(
    "me@127.0.0.1", identity="key", ssh=("ssh", "-T", "-p", "2222")
)  # through a tunnel
runner = routed_runner(server, {"crowsnest": with_fallback(laptop, server)})
# or ask every machine at once and merge, each row tagged [laptop] / [server]:
runner = routed_runner(server, {"crowsnest": fan_out({"laptop": laptop, "server": server})})
app = mk_server("claude-ai", runner=runner, auth=..., classes=("read", "handoff")).http_app()
```

The *runner* is the seam: `local_runner` runs the gate on this machine; `ssh_runner` sends the request to a key whose forced command is the gate, so a server process running as its own account reaches tools it holds no credentials for. `routed_runner` sends a request to the runner of the longest leading words it matches (`"crowsnest"`, `"crowsnest intent"`); `with_fallback` asks a second machine only when the first cannot be reached; `fan_out` asks several machines in parallel and merges their answers, each line tagged with its machine, and names on its own line any machine that did not answer, so a partial list never reads as a whole one. Use it for reads only: a request that changes something goes to one runner. A rule's `reply` (a template over `{out}`, the command's output) shapes a successful answer for these transports, as `post_handoff` does to return a line to paste into Claude Code. Authentication is the job of whoever serves it on a network (`auth=` goes to `FastMCP`). Only the classes you name are offered (default: `read`). Long answers are paged: every tool takes `offset`, and the answer says where to resume.

**The bundled `claude-ai` profile** is shaped for a conversation, typed or spoken: Claude Code sessions (`session_triage`, `session_roster`, `session_recap`, `session_turns`, `session_ledger`), open loops (`owed_by_owner`, `blocked_work`), GitHub read-only (`list_repos`, `repo_overview`, `read_repo_file`, `list_issues`, `read_issue`; a repository whose name contains `secret` is refused), and a handoff inbox shared with Claude Code through [annals](https://github.com/thorwhalen/annals) (`read_handoffs`, `read_document`, and `post_handoff` in the `handoff` class, whose text goes to the command's standard input, never its arguments). A machine adds what only it has in a private profile that starts with `extends = "claude-ai"`.

## Configuration

`~/.config/hatchway/config.toml`, every key optional:

```toml
profile = "claude-fleet"
path = ["~/.local/bin"]           # where the commands live (sshd's PATH is minimal)
timeout = 120
[roots]                           # extra directories file rules may serve, by name
[dispatch]
roots = ["~/projects"]            # where a gated spawn may start a session
[snapshot]
to = ""                           # optional private copy: a local dir or host:path
```

## The security model, in one paragraph

What the key can do is the profile, so read it before you authorise a key. Read commands still send what they read to wherever the agent runs: `crowsnest show` quotes your sessions' transcripts, so authorise only an agent you would show them to. Keep the `from=` restriction. If the agent joins your Tailscale tailnet, give it a policy that allows **only TCP port 22** to the machines it serves and **no Tailscale SSH rule**: Tailscale SSH authenticates by tailnet identity and never reads `authorized_keys`, so it would bypass the gate entirely. `100.64.0.0/10` is also ordinary carrier-grade NAT space, so once you know the agent's own tailnet address, narrow `--from` to it (`--from 100.x.y.z/32`). Leave dispatch off until you have watched the log for a while: a session it starts runs code as you. The bundled rule pins `--model sonnet` and `--permission-mode default` (the session asks before acting), refuses a prompt that starts with `-`, and starts sessions only under the directories you list.

Also built in: the commands run with an allowlisted environment (nothing the connecting client can set reaches them beyond `LANG`), in their own process group so a timeout stops their children too, one call at a time per agent (a concurrent call is refused with exit 75), and every allowed call is logged before it runs, so a dropped connection still leaves its line.

## Agents

- `hatchway` skill: install and verify a connection for an outside agent on this machine (the steps, the checks, the Tailscale policy).
- `hatchway-muse` skill: when a task would be better handed to a personal Muse agent (Meta), which integration pattern fits, and the exact prompt to give it.
