> built 2026-12-06 21:29 UTC from 6070869 (main) · xa 0.1.22. Details: build_info.json

# index.html.md

<!-- generated by epythet -->

# xa

**Manage Claude Code sessions across projects and machines.**

Claude Code’s built-in `/resume` picker is per-project, per-machine — sessions
on your laptop, your Mac, your server, and your phone live in separate silos.
`xa` treats sessions as first-class records you can list, search, spawn,
resume, and kill across every machine you use, from one CLI or one HTTPS
endpoint.

Works great on a headless server (tmux-hosted `claude`, phone URL via
`claude.ai/code/…` remote control). Works fine on a laptop too.

## What xa is for, now that Remote Control exists

Claude Code’s own [Remote Control](https://code.claude.com/docs/en/remote-control)
does the “start a session and pick it up on my phone” job natively — server
mode serves up to 32 sessions from one process, the claude.ai session list
shows them across machines, and mobile push tells you when one needs you.
**Use it.** Set `"remoteControlAtStartup": true` and xa gets out of the way.

`xa` is for the four things it doesn’t do:

1. **Launch in an arbitrary directory, from your phone.** A `claude remote-control` server is rooted at *one* directory (`--spawn worktree`
   means worktrees of that same repo). `xa spawn <any-cwd>` — and the web UI’s
   folder picker — is how you start a session in any one of a few hundred
   projects without being at the machine.
2. **See sessions that were never remote-controlled.** claude.ai lists only
   live Remote Control sessions. `xa list` reads the whole transcript tree,
   and `xa history --search` greps every prompt you have ever typed, across
   projects and machines.
3. **Find out what happened to a session that died.** `xa archive forensics`
   gives a death reason and the last tool call. Nothing upstream keeps one.
4. **Reconnect a session whose Remote Control dropped.** After a network
   change Claude Code retries, gives up, and leaves the session running but
   unreachable. `xa revive` finds those and reconnects them — carefully; see
   `xa revive --help`.

---

## Easiest path — let Claude Code set it up

`xa` ships with an **agent skill** that teaches any Claude Code instance how to
install, configure, and secure-by-default-set-up the package on your machine.
After `pip install xa`, a Claude Code session running on that machine can
guide you through the rest with zero docs-reading.

```bash
pip install 'xa[service]'          # service extra bundles the HTTP server
```

Then, in a Claude Code session on the target machine:

>  *“Set up xa on this server so I can manage Claude Code sessions from my phone.”*

The [`xa-install`]() skill will:

- verify system prerequisites (`tmux`, `claude`, `rsync`/`ssh` if needed);
- generate a strong password + captcha key (via `xa gen-secret`);
- write a secure `~/.config/xa/config.toml` and a systemd unit;
- **refuse to expose the HTTP service publicly without auth + TLS guidance**;
- run a health-check and confirm everything is wired up.

Two companion skills live in the repo:

- [`xa-install`]() — the consumer-facing
  setup skill, shipped inside the wheel so every `pip install xa` gets it.
- [`xa-dev`]() — for collaborators hacking on
  the codebase (architecture, test conventions, known pitfalls).

## Running `xa` as a phone-accessible server

**This is the highest-leverage use case.** A headless server runs
`xa serve`, you open `https://your-server/api/xa/sessions/{id}` (or a small
web UI) on your phone, and you can list / spawn / resume / kill Claude Code
sessions from anywhere. Each session exposes a `claude.ai/code/…` URL that
resumes the agent right in your phone’s browser.

### ⚠️ Security first — this is a code-execution endpoint

A live `xa` session runs `claude`, which can invoke arbitrary shell
commands via its `Bash` tool. Anyone who reaches your `xa` server with
valid credentials can execute code as the server user. Treat the server
like you would an SSH endpoint — **only more carefully**, because the
attack surface is a web request.

`xa` is **secure by default**. When running on a non-loopback interface,
it refuses to start without credentials. You have to pass
`--i-know-its-insecure` to bypass the check.

### The recommended recipe

```bash
# 1. Install (on the server).
pip install 'xa[service]'

# 2. Generate secrets. Don't copy passwords from a tutorial — use these.
export XA_PASSWORD=$(xa gen-secret)
export XA_CAPTCHA_KEY=$(xa gen-secret)

# 3. Start xa, bound locally, captcha-gated.
xa serve \
  --host 127.0.0.1 --port 8010 \
  --username $(whoami) --password-env XA_PASSWORD \
  --captcha
```

Then put a **TLS-terminating reverse proxy in front of port 8010**. Caddy,
nginx, Traefik, Coolify — any of them. Without TLS, HTTP Basic sends your
password in plaintext on every request.

A minimal Caddy block:

```caddy
xa.example.com {
    reverse_proxy 127.0.0.1:8010
}
```

### Defense in depth — things to add

1. **mTLS client certs.** Issue one per device (phone, laptop). Caddy’s
   `client_auth { mode require_and_verify }` rejects any connection without
   a valid cert. Removes the “shared password” problem entirely. Sketch:
   ```caddy
   xa.example.com {
       tls {
           client_auth {
               mode require_and_verify
               trusted_ca_cert_file /etc/caddy/xa_ca.pem
           }
       }
       reverse_proxy 127.0.0.1:8010
   }
   ```

   Generate a CA with `step-ca` or plain `openssl`; export per-device
   `.p12` bundles to install on each device. Once you have this, you can
   run `xa serve --i-know-its-insecure` (Basic auth becomes redundant —
   the proxy already authenticated the client) or keep Basic as a second
   factor.
2. **Obscure the hostname.** Don’t call it `xa.example.com`. Random
   subdomain + private DNS is cheap friction for bots.
3. **Systemd hardening.** Run as a non-privileged user with
   `ProtectSystem=strict`, `NoNewPrivileges=true`, and a tight
   `ReadWritePaths=` list.
4. **Firewall.** Bind only to loopback; let the reverse proxy be the only
   thing on a public interface.
5. **Rotate credentials.** `xa gen-secret` is a one-liner; rotate monthly
   and restart the service.

### Systemd unit

```ini
# /etc/systemd/system/xa.service
[Unit]
Description=xa Claude Code session server
After=network.target

[Service]
Type=simple
User=xa
WorkingDirectory=/home/xa
Environment="XA_PASSWORD=<paste the output of `xa gen-secret`>"
Environment="XA_CAPTCHA_KEY=<paste a second `xa gen-secret`>"
ExecStart=/path/to/venv/bin/xa serve \
  --host 127.0.0.1 --port 8010 \
  --username xa --password-env XA_PASSWORD \
  --captcha
Restart=on-failure
# Hardening — uncomment and tune if your setup allows:
# ProtectSystem=strict
# ProtectHome=true
# NoNewPrivileges=true
# PrivateTmp=true

[Install]
WantedBy=multi-user.target
```

```bash
sudo systemctl enable --now xa
curl -u xa:$XA_PASSWORD http://127.0.0.1:8010/health
```

### What happens if you try to skip the guardrails

```console
$ xa serve --host 0.0.0.0 --port 8010
error: refusing to bind to a non-loopback interface ('0.0.0.0') without
       --username/--password.
       Anyone who can reach this port could spawn arbitrary shell
       commands via Claude Code sessions on this host.

       Fix (recommended): add credentials + captcha.
         xa gen-secret                  # use for password + XA_CAPTCHA_KEY
         …

       Bypass (only when an outer layer already gates access,
       e.g. mTLS in the reverse proxy): --i-know-its-insecure
```

The flag exists, but it’s named so the error is honest.

---

## Reviving dropped Remote Control sessions

Remote Control gives up on its own. A network change — moving between
networks, toggling a VPN — produces a transient 403, Claude Code retries for
a few minutes and then stops, and the session keeps running locally while
becoming unreachable from claude.ai. `xa revive` finds those and reconnects
them.

```console
$ xa revive
reconnectable  work:@1.%1     would send /remote-control  [remote control disconnected]
held_elsewhere phone:@1.%1    not actionable              [ended or archived from another device]
connected      build:@2.%1    [/rc]

(dry run — re-run with --apply to send)
```

```bash
xa revive --apply                      # send /remote-control to the dropped ones
xa revive --include-held-elsewhere     # …also take back ones held on another device
xa revive --server-mode                # …also restart died `claude remote-control` servers
xa revive --json-out                   # machine-readable, one record per pane
```

**It only reaches tmux-hosted sessions.** `/remote-control` is a built-in
slash command with no CLI equivalent, so reconnecting means typing into the
pane — a session running in a plain terminal tab has to be reconnected by
hand.

Four refusals are deliberate, and each cost something to learn:

| It will not                                     | Because                                                                                                       |
|-------------------------------------------------|---------------------------------------------------------------------------------------------------------------|
| reconnect a session held on another device      | it would take the session back from your phone mid-sentence                                                   |
| type into a pane with unsent text in its prompt | `send-keys` *appends*, so it would submit your half-typed instruction with `/remote-control` glued to the end |
| touch a busy or API-stalled session             | the fix there is resending a prompt, which costs money and can duplicate work                                 |
| touch the same pane twice in ten minutes        | so a timer, a hook and an impatient human cannot add up to a keystroke storm                                  |

Detection reads the footer’s `/rc` pill, which is present while Remote
Control is **connected** and gone when it is not, and cross-checks it
against `bridgeSessionId` in the session’s own state file. Both were
verified against a live session rather than inferred — getting the pill
backwards would send `/remote-control` at healthy sessions, which opens a
modal menu inside them.

### Unattended: a report-only check

A drop happens at 03:00, when nobody is typing `xa revive`. The unattended form is **report-only**: it never sends a key. `xa revive-check` makes one tmux capture per pane, counts the consecutive ticks each pane stays `reconnectable`, prints nothing while everything is fine, and prints the offenders and exits 1 only once a pane has stayed reconnectable for two ticks (`--ticks`), so a drop that clears within a minute never pages anyone. Run it on the host that actually has the panes; a hook is the wrong shape (it fires in the session that is starting, and the sessions that need reviving are the ones doing nothing).

```ini
# ~/.config/systemd/user/xa-revive-check.service
[Unit]
Description=xa revive-check (report-only: sends nothing)
[Service]
Type=oneshot
ExecStart=%h/.local/bin/xa revive-check

# ~/.config/systemd/user/xa-revive-check.timer
[Unit]
Description=Run xa revive-check every 5 minutes
[Timer]
OnBootSec=5min
OnUnitActiveSec=5min
[Install]
WantedBy=timers.target
```

```bash
systemctl --user daemon-reload && systemctl --user enable --now xa-revive-check.timer
systemctl --user --failed          # a failed unit = a pane stayed dropped for two ticks
journalctl --user -u xa-revive-check -n 20
```

Moving to `xa revive --apply` on a timer is deliberately not offered here: the gates (held-elsewhere, unsent prompt text, busy/stalled) are verified against the TUI as it renders today, and unattended is the one configuration with no human to notice a redraw that makes a gate wrong. Run the report for a few weeks first; only when it has been right does `--apply` earn a timer. One gap is unverified: an *unclean* drop whose disconnect message has scrolled away and whose `bridgeSessionId` lingers would not be detected; it needs a real network-loss reproduction.

## The rest of the CLI

Already have some Claude Code sessions on this machine? List them:

```console
$ xa list
ID        HOST   STATE            MOD      TURNS  CWD                      URL / FIRST_MSG
--------  -----  ---------------  -------  -----  -----------------------  ---------------------------------------------------
7b875f44  local  live             2s ago   494    /root                    https://claude.ai/code/session_01ALoSc...
b3366c60  local  live             20h ago  725    /root/py/proj            https://claude.ai/code/session_012W14x...
4e738fb5  local  transcript_only  18h ago  15     /root                    my apps.thorwhalen.com has an admin level app…
```

Dig into one:

```bash
xa info 7b875f44                # full record + forensics
xa archive forensics 7b875f44   # what was it doing when it last ran a tool?
xa history --search "bridge URL"   # cross-project prompt grep
```

Or walk through them interactively:

```bash
xa pick
```

### Commands

| Command                                | Purpose                                                                              |
|----------------------------------------|--------------------------------------------------------------------------------------|
| `xa list`                              | Table of sessions across configured hosts                                            |
| `xa info <id>`                         | One session — metadata + forensics                                                   |
| `xa history [--search X]`              | Grep `~/.claude/history.jsonl`                                                       |
| `xa pick`                              | Interactive list → number → action                                                   |
| `xa spawn <cwd>`                       | Start `claude` in tmux, print phone URL                                              |
| `xa resume <id>…`                      | `claude --resume` in a new tmux pane, in the original cwd, model and permission mode |
| `xa resume --since-shutdown [--apply]` | List the sessions alive at the last shutdown; `--apply` resumes them all             |
| `xa kill <id>`                         | End a live session                                                                   |
| `xa archive list`                      | Postmortem of every session `xa` spawned                                             |
| `xa archive log <id>`                  | Raw pane log                                                                         |
| `xa archive forensics <id>`            | Death reason + last tool use                                                         |
| `xa sync [--host H]`                   | Refresh SSH-host caches                                                              |
| `xa serve …`                           | Run the HTTP service (secure-by-default)                                             |
| `xa gen-secret`                        | Cryptographically strong random hex string                                           |

Every command supports `--help`; every listing supports `--json-out`.

**Accounts.** `spawn` and `resume` take `--home <dir>` for a second Claude Code account (a non-default `CLAUDE_CONFIG_DIR`); without it xa uses `$XA_CLAUDE_HOME`, then `$CLAUDE_CONFIG_DIR`, then `~/.claude`. The pane runs claude under that account whatever the tmux server’s own environment holds: the command unsets every inherited session marker and either states `CLAUDE_CONFIG_DIR` or unsets it for the default home.

**After a reboot.** `xa resume --since-shutdown` is a dry run: it lists the transcripts whose last write landed at the last shutdown (from `last`), with the model and permission mode each will come back in. `--apply` starts them, all at once, and reports a verdict per session (`connected`, `needs_trust` for a folder the account has not trusted, `needs_login`, …). Sessions already running, or resumed since boot, are never listed, so running it twice starts nothing twice.

## Configuration

Config lives at `~/.config/xa/config.toml` (respects `$XDG_CONFIG_HOME`;
override with `$XA_CONFIG`). Missing file → implicit `LocalHost`.

```toml
[settings]
cache_dir = "~/.cache/xa/remotes"
stale_threshold_sec = 3600
claude_bin = "claude"
tmux_bin = "tmux"

[hosts.local]
kind = "local"

# Another machine via SSH. Uses your ~/.ssh/config.
[hosts.devbox]
kind = "ssh"
host = "devbox"
user = "deploy"
remote_claude_home = "~/.claude"

# Another xa server over HTTPS.
[hosts.phone_server]
kind = "http"
base_url = "https://xa.example.com"
auth = "basic"
username = "me"
password_env = "XA_PHONE_PW"   # secret stays in env, not TOML
```

After editing, `xa sync` pulls SSH hosts into the local cache.

### Trace export for a session (`--telemetry`)

`xa spawn --telemetry lab` (and `xa resume <id> --telemetry lab`) launches claude with OpenTelemetry trace export to the profile `[telemetry.lab]`. Off unless you ask.

```toml
[telemetry.lab]
endpoint = "https://otel.example.com/v1/traces"
headers_file = "~/.config/xa/lab.keys"   # KEY=VALUE lines that you keep, not xa
# content = true                         # also export prompts and tool output
# export_interval_ms = 5000
[telemetry.lab.resource]
team = "fleet"
[telemetry.lab.headers]                  # header name = template over the keys file
Authorization = "Bearer ${LAB_TOKEN}"
```

The credentials are never on a command line, in a file xa writes, or in a log: the pane’s own shell runs `xa telemetry-headers lab` when it starts and exports the result into claude’s environment, so tmux and `ps` show the expression only. A missing key or file fails the `xa spawn` that asked, naming the key. Local sessions only (a remote host reads its own config, and `resume` of a remote session refuses the flag); `resume --since-shutdown` does not take the flag and revived sessions do not keep it. Keys come from the file only (a pane’s environment is the tmux server’s, not yours), comments are whole lines. The headers are in claude’s own environment, so a tool the agent runs (`env`) can see them: use a write-only ingest token.

## Python API

Everything the CLI does is available as a library:

```python
import xa

# List all sessions on this machine.
for s in xa.list_sessions(limit=10):
    print(s.id[:8], s.state, s.cwd, s.url)

# Multi-host.
hosts = xa.load_hosts()
for s in xa.list_sessions(hosts=list(hosts.values())):
    print(s.host, s.id[:8], s.url)

# Spawn / resume / kill.
local = xa.LocalHost()
result = local.spawn("my-session", cwd="/tmp")
print(result.url)

# Read the archive.
events = xa.default_events_store()
panes = xa.default_pane_store()
for rec in xa.records(events, panes):
    print(rec.id, rec.gone_reason, rec.url)
```

For embedding the HTTP service in a larger app:

```python
from xa.service import build_api, make_basic_auth, Captcha
import os

api = build_api(
    auth=make_basic_auth("me", os.environ["XA_PASSWORD"]),
    captcha=Captcha(key=os.environ["XA_CAPTCHA_KEY"]),
)
outer_app.mount("/api/xa", api)
```

### Where a session’s terminal lives (pane providers)

`xa.panes` is the one seam between xa and a terminal: a `PaneProvider` creates a pane running a command, captures its text, and tears it down, and a `PaneAddress` (`provider` + `ref`) names a pane. tmux is the default (`TmuxPanes`); `ITermPanes` drives an iTerm2 tab on a Mac through `osascript` (values reach AppleScript as arguments, never in the script text). `Session.pane_address` reads the new `pane_provider` / `pane_ref` fields and falls back to the older `tmux_name` / `tmux_pane`, so existing session files and servers keep working. Spawning a session on a Mac host through this seam is not wired up yet.

## HTTP API surface

| Method   | Path                      | Purpose                                                      |
|----------|---------------------------|--------------------------------------------------------------|
| `GET`    | `/sessions`               | List (query: `project`, `state`, `include_forks`, `limit`)   |
| `POST`   | `/sessions`               | Create a tmux+claude session; up to 120 s for the bridge URL |
| `DELETE` | `/sessions/{name}`        | Kill (captcha-gated when `--captcha`)                        |
| `GET`    | `/sessions/{id}/info`     | Metadata + forensics + pane tail                             |
| `POST`   | `/sessions/{id}/resume`   | `claude --resume` in a new pane                              |
| `GET`    | `/archive`                | Postmortem list                                              |
| `GET`    | `/archive/{id}/forensics` | Rich forensics                                               |
| `GET`    | `/archive/{id}/log`       | Pane log (`?tail_kb=`)                                       |
| `GET`    | `/captcha`                | 4-letter challenge (only with `--captcha`)                   |
| `GET`    | `/health`                 | Liveness                                                     |

## How it compares

| Feature                       | `xa`           | [`cc-sessions`](https://github.com/chronologos/cc-sessions)   | `claude --resume`   | [`claude-history-viewer`](https://marketplace.visualstudio.com/items?itemName=agsoft.claude-history-viewer)   |
|-------------------------------|----------------|---------------------------------------------------------------|---------------------|---------------------------------------------------------------------------------------------------------------|
| Cross-project discovery       | ✓              | ✓                                                             | per-project         | ✓                                                                                                             |
| Cross-machine discovery       | ✓ (SSH + HTTP) | ✓ (SSH)                                                       | ✗                   | ✗                                                                                                             |
| Live tmux / spawn / kill      | ✓              | ✗                                                             | ✗                   | ✗                                                                                                             |
| Bridge URL resolution (phone) | ✓              | ✗                                                             | N/A                 | ✗                                                                                                             |
| Postmortem / death reason     | ✓              | ✗                                                             | ✗                   | ✗                                                                                                             |
| HTTP API surface              | ✓              | ✗                                                             | ✗                   | ✗                                                                                                             |
| Python library                | ✓              | ✗                                                             | —                   | ✗                                                                                                             |
| Language                      | Python         | Rust                                                          | —                   | TypeScript (VS Code)                                                                                          |

Short version: cc-sessions pioneered cross-machine listing; the VS Code
extension pioneered transcript search with a UI; `xa` unifies those with
live CRUD + bridge URL resolution + postmortem, and exposes all of it as
both a CLI and a Python library you can embed.

## How session data flows

```default
 ┌──────────── local machine ─────────────┐   ┌────────── remote machine ─────────┐
 │                                        │   │                                   │
 │  ~/.claude/projects/<slug>/*.jsonl     │   │  ~/.claude/projects/<slug>/*.jsonl│
 │  ~/.claude/sessions/<pid>.json         │   │  ~/.claude/sessions/<pid>.json    │
 │         │          │                   │   │            │                      │
 │         ▼          ▼                   │   │            ▼                      │
 │   xa.claude_fs   xa.tmux ─────┐        │   │      rsync (SSHHost) ─┐           │
 │         │         │           │        │   │      or HTTP (HTTPHost)│          │
 │         └────┬────┘           │        │   │                        │          │
 │              ▼                │        │   │                        ▼          │
 │       Session dataclass ◄─────┘        │   │                 cached ~/.claude/ │
 │              │                         │   │                        │          │
 │              ▼                         │   │                        ▼          │
 │       xa.list_sessions ◄───────────────┼───┤                  remote Sessions  │
 │              │                         │   │                                   │
 │              ▼                         │   └───────────────────────────────────┘
 │        CLI / API / phone URL           │
 └────────────────────────────────────────┘
```

## Development

Layered architecture in [`misc/docs/design.md`]();
phased plan in [`misc/docs/roadmap.md`](); research
on Claude Code internals in [`misc/docs/research.md`]().

```bash
git clone https://github.com/addaix/xa.git
cd xa
pip install -e '.[dev,service]'
pytest -q                              # ~100 tests, ~8 seconds
XA_RUN_INTEGRATION=1 pytest -q         # also runs the real-claude spawn test
```

The [`xa-dev`]() skill is picked up
automatically when you’re working on this repo (architecture overview,
testing conventions, known pitfalls).

## License

MIT

<p class="epythet-aggregates">This documentation as a single file: <a href="xa.md">xa.md</a> (Markdown, for agents).</p>


# _autosummary/xa.archive.html.md

# xa.archive

Postmortem archive of Claude Code sessions spawned by `xa`.

Every session that `xa` spawns emits `created` + `url_acquired` events
into an append-only JSONL log and its tmux pane is tee’d to a per-session
file via `tmux pipe-pane`. When a session disappears from the live list,
`reconcile()` appends a `gone` event with an inferred death time and a
classified reason.

Death-reason taxonomy (most specific wins):

- `replaced`    — same tmux name, different `tmux_created_ts` (the
  original died and got taken over by a new session of the same name).
- `missing`     — no pane log exists (session predates our logging or
  the log was cleaned up).
- `interrupted` — transcript shows the user-interrupt marker AND the
  pane tail shows a clean exit. **Ambiguous**: the same marker fires on
  bridge-WebSocket resets (phone standby, reconnect), not only on human
  ESC. Don’t derive user intent from this alone.
- `oom_killed`  — last tool exited with 137 (SIGKILL) AND the pane log
  tail contains a kernel/shell OOM marker (`Killed`, `Out of memory`,
  `MemoryError`). Strongest single signal we can derive without root —
  the kernel’s “Killed” message rides through the same tty bash uses to
  print SIGKILL notices, so it ends up in the tee’d pane log.
- `tool_crash`  — pane tail shows clean exit AND the last tool use
  exited with a non-zero code (and we couldn’t promote to `oom_killed`).
- `clean_exit`  — pane tail contains `"Resume this session with:"`.
- `abrupt`      — killed / crashed / bridge-dropped with no clean-exit
  marker.

### Functions

| `append_created`(events, \*, id, name, cwd, ...)                                                    |                                                                        |
|-----------------------------------------------------------------------------------------------------|------------------------------------------------------------------------|
| `append_gone`(events, \*, id, name, reason[, ...])                                                  |                                                                        |
| [`append_hidden`](_autosummary/xa.archive.html.md#xa.archive.append_hidden)(events, \*, id, hidden)              | Mark an archived session as hidden (or un-hide it).                    |
| [`append_label`](_autosummary/xa.archive.html.md#xa.archive.append_label)(events, \*, id, label)                | Set or clear a user-supplied display label for a session.              |
| `append_url_acquired`(events, \*, id, name[, ...])                                                  |                                                                        |
| [`classify_death`](_autosummary/xa.archive.html.md#xa.archive.classify_death)(pane_kind, \*[, replaced, ...])     | Pick the most specific death reason from available signals.            |
| [`overlays`](_autosummary/xa.archive.html.md#xa.archive.overlays)(events)                                   | Fold `labeled` / `hidden` events into `{id: {label, hidden}}`.         |
| [`reconcile`](_autosummary/xa.archive.html.md#xa.archive.reconcile)(events, panes, live_sessions, \*[, ...]) | Emit `gone` events for archived sessions missing from `live_sessions`. |
| [`records`](_autosummary/xa.archive.html.md#xa.archive.records)(events, panes)                             | Return per-session summaries, newest-first (by creation time).         |
| [`synthesize_diagnosis`](_autosummary/xa.archive.html.md#xa.archive.synthesize_diagnosis)(\*, state[, reason, ...])     | One-paragraph plain-English hint about what likely happened.           |

### Classes

| [`ArchiveRecord`](_autosummary/xa.archive.html.md#xa.archive.ArchiveRecord)(id, name, cwd, created, url, ...)   |                                                                 |
|----------------------------------------------------------------------------------------------------|-----------------------------------------------------------------|
| [`PaneInspection`](_autosummary/xa.archive.html.md#xa.archive.PaneInspection)(death_ts, kind, oom_markers, tail) | Read-once view of a pane log tail used by death classification. |

### *class* xa.archive.ArchiveRecord(id, name, cwd, created, url, gone, gone_detected, gone_reason, pane_log_bytes, claude_session_id, forensics, label=None, hidden=False)

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

### *class* xa.archive.PaneInspection(death_ts, kind, oom_markers, tail)

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

Read-once view of a pane log tail used by death classification.

### xa.archive.append_hidden(events, , id, hidden)

Mark an archived session as hidden (or un-hide it).

* **Return type:**
  [`None`](https://docs.python.org/3/builtins/constants.html#None)

### xa.archive.append_label(events, , id, label)

Set or clear a user-supplied display label for a session.

`id` can be an archive id, a tmux session name, or a
`claude_session_id` — whatever key the caller will use to look it
up later. Empty-string or `None` label clears any prior label.

* **Return type:**
  [`None`](https://docs.python.org/3/builtins/constants.html#None)

### xa.archive.classify_death(pane_kind, , replaced=False, forensics=None, oom_markers=())

Pick the most specific death reason from available signals.

`oom_markers` is the tuple of OOM-shaped strings observed in the
pane tail (see `_OOM_PANE_MARKERS`). When the last tool exited
with 137 and at least one marker is present, we promote the verdict
to `oom_killed` — that pair is the strongest single signal we can
get without reading kernel logs (which would need root and is not
portable).

* **Return type:**
  [`Literal`](https://docs.python.org/3/library/typing.html#typing.Literal)[`'clean_exit'`, `'abrupt'`, `'interrupted'`, `'tool_crash'`, `'oom_killed'`, `'replaced'`, `'missing'`]

### xa.archive.overlays(events)

Fold `labeled` / `hidden` events into `{id: {label, hidden}}`.

Later events win. Useful when rendering live sessions too — callers
look up by whatever id they know (archive id, claude_session_id,
tmux name) and apply the overlay if present.

* **Return type:**
  [`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict)]

### xa.archive.reconcile(events, panes, live_sessions, , claude_home=PosixPath('/home/runner/.claude'))

Emit `gone` events for archived sessions missing from `live_sessions`.

Returns the list of freshly-emitted events (handy for tests). Idempotent:
calling twice with the same live list produces no new events the
second time.

* **Return type:**
  [`list`](https://docs.python.org/3/builtins/stdtypes.html#list)[[`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict)]

### xa.archive.records(events, panes)

Return per-session summaries, newest-first (by creation time).

* **Return type:**
  [`list`](https://docs.python.org/3/builtins/stdtypes.html#list)[[`ArchiveRecord`](_autosummary/xa.archive.html.md#xa.archive.ArchiveRecord)]

### xa.archive.synthesize_diagnosis(, state, reason=None, forensics=None, oom_markers=())

One-paragraph plain-English hint about what likely happened.

Designed to be useful to both a human reading the UI and an LLM agent
deciding whether to retry or escalate. The hint surfaces the actionable
bit (e.g., “add swap”, “re-run with –resume”) rather than just naming
the verdict — the structured fields next to it already do that.

* **Return type:**
  [`str`](https://docs.python.org/3/builtins/stdtypes.html#str)


# _autosummary/xa.claude_cli.html.md

# xa.claude_cli

Spawn, resume, and URL-resolve Claude Code sessions.

Ties `xa.tmux` (pane / process control), `xa.claude_fs` (read the
ephemeral `~/.claude/sessions/<pid>.json` file) and the `claude` CLI
binary together. Everything here targets the *local* machine; remote-host
dispatch lives in `xa.hosts` (Phase 6+).

Bridge URL format: `https://claude.ai/code/<bridgeSessionId>`. The
`bridgeSessionId` already starts with `session_` — do not prepend
anything.

### Module Attributes

| [`ALL_FLAGS`](_autosummary/xa.claude_cli.html.md#xa.claude_cli.ALL_FLAGS)   | Every flag `_claude_argv()` can write, for a command composed without probing a binary.   |
|--------------------------------------------------------------|-------------------------------------------------------------------------------------------|

### Functions

| [`complete_spawn`](_autosummary/xa.claude_cli.html.md#xa.claude_cli.complete_spawn)(pending)                            | Blocking half of the spawn: wait for the URL, then report.                                                                                               |
|-----------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------|
| [`diagnose_bridgeless`](_autosummary/xa.claude_cli.html.md#xa.claude_cli.diagnose_bridgeless)(session_name, \*[, ...])       | Why has this session no bridge URL? Returns `(verdict, hint)`.                                                                                           |
| [`find_claude_pid`](_autosummary/xa.claude_cli.html.md#xa.claude_cli.find_claude_pid)(session_name, \*[, tmux_bin, ...]) | Return the PID of the claude process living in the pane (`session_name` is the pane provider's own reference: a tmux session name, an iTerm session id). |
| [`launch_command`](_autosummary/xa.claude_cli.html.md#xa.claude_cli.launch_command)(cwd, argv, \*, claude_home[, ...])  | The shell line that runs `argv` (claude) in `cwd` under `claude_home`'s account.                                                                         |
| [`new_archive_id`](_autosummary/xa.claude_cli.html.md#xa.claude_cli.new_archive_id)()                                   | Fresh 12-char hex id used as the key for pane logs + archive events.                                                                                     |
| [`pid_is_claude`](_autosummary/xa.claude_cli.html.md#xa.claude_cli.pid_is_claude)(pid)                                 | Portable positive identity check — used before ever signaling a pid.                                                                                     |
| [`prepare_spawn`](_autosummary/xa.claude_cli.html.md#xa.claude_cli.prepare_spawn)(name, \*, cwd[, resume_id, ...])     | Launch the session's pane and return without waiting for the URL.                                                                                        |
| [`resolve_bridge_url`](_autosummary/xa.claude_cli.html.md#xa.claude_cli.resolve_bridge_url)(session_name, \*[, ...])        | Return `(url, source)` for a live claude session hosted in a pane.                                                                                       |
| [`resume_session`](_autosummary/xa.claude_cli.html.md#xa.claude_cli.resume_session)(claude_session_id, \*, cwd[, ...])  | Launch `claude --resume <id>` in a new detached tmux session.                                                                                            |
| [`spawn_session`](_autosummary/xa.claude_cli.html.md#xa.claude_cli.spawn_session)(name, \*, cwd[, claude_bin, ...])    | Create a detached tmux session running `claude` in `cwd`.                                                                                                |
| [`supported_cli_flags`](_autosummary/xa.claude_cli.html.md#xa.claude_cli.supported_cli_flags)([claude_bin, ttl_sec])         | Long-form flags advertised by `<claude_bin> --help`, cached per binary.                                                                                  |
| [`tmux_session_dedicated_to`](_autosummary/xa.claude_cli.html.md#xa.claude_cli.tmux_session_dedicated_to)(session_name, ...)       | Is killing this whole tmux session equivalent to killing this claude?                                                                                    |
| [`wait_for_bridge_url`](_autosummary/xa.claude_cli.html.md#xa.claude_cli.wait_for_bridge_url)(session_name, \*, ...[, ...])  | Poll the ephemeral session file until a bridge URL appears.                                                                                              |

### Classes

| [`PendingSpawn`](_autosummary/xa.claude_cli.html.md#xa.claude_cli.PendingSpawn)(name, cwd, claude_home, ...[, ...])   | A launched tmux session whose bridge-URL handshake hasn't finished.   |
|-----------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------|
| [`SpawnResult`](_autosummary/xa.claude_cli.html.md#xa.claude_cli.SpawnResult)(name, cwd, claude_pid, ...[, ...])     | What `spawn_session` / `resume_session` return to the caller.         |

### xa.claude_cli.ALL_FLAGS *= frozenset({'--allow-dangerously-skip-permissions', '--dangerously-skip-permissions', '--effort', '--model', '--name', '--permission-mode', '--remote-control'})*

Every flag `_claude_argv()` can write, for a command composed without probing a binary.

### *class* xa.claude_cli.PendingSpawn(name, cwd, claude_home, tmux_bin, deadline, warning, archive_ctx, address=None, panes=None)

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

A launched tmux session whose bridge-URL handshake hasn’t finished.

Returned by [`prepare_spawn()`](_autosummary/xa.claude_cli.html.md#xa.claude_cli.prepare_spawn) — the fast, synchronous part (tmux
session exists, pane log piping, `created` archive event emitted).
Pass it to [`complete_spawn()`](_autosummary/xa.claude_cli.html.md#xa.claude_cli.complete_spawn) to run the slow part (URL wait,
prompt dismissal); services may do that from a background thread so
the caller gets an immediate acknowledgment.

### *class* xa.claude_cli.SpawnResult(name, cwd, claude_pid, claude_session_id, bridge_session_id, url, url_source, warning, attention=None)

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

What `spawn_session` / `resume_session` return to the caller.

### xa.claude_cli.complete_spawn(pending)

Blocking half of the spawn: wait for the URL, then report.

Safe to call from a background thread — all state it touches (tmux,
`~/.claude/sessions/`, the append-only events log) is shared
machine-wide, not per-process.

The URL wait, the pid walk and the failure diagnosis read the pane through the
provider that made it (`pending.panes`; tmux when absent), by the address’s own
reference: a tmux session name, an iTerm session id.

* **Return type:**
  [`SpawnResult`](_autosummary/xa.claude_cli.html.md#xa.claude_cli.SpawnResult)

### xa.claude_cli.diagnose_bridgeless(session_name, , claude_pid=None, tmux_bin='tmux', panes=None)

Why has this session no bridge URL? Returns `(verdict, hint)`.

One pane capture, classified by [`xa.revive.classify()`](_autosummary/xa.revive.html.md#xa.revive.classify) — the single
rule engine for reading a claude pane. Only meaningful for a session
with no bridge id: a connected session’s pane renders conversation text,
which may legitimately quote `/login`.

* **Return type:**
  [`tuple`](https://docs.python.org/3/builtins/stdtypes.html#tuple)[[`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)], [`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]]

### xa.claude_cli.find_claude_pid(session_name, , tmux_bin='tmux', panes=None)

Return the PID of the claude process living in the pane (`session_name` is the
pane provider’s own reference: a tmux session name, an iTerm session id).

Walks **every** pane’s process tree (a claude can live in any window
of a multi-window session, not just the first pane). Recognizes both
the native binary (`comm == "claude"`) and npm/bun installs.

* **Return type:**
  [`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`int`](https://docs.python.org/3/builtins/functions.html#int)]

### xa.claude_cli.launch_command(cwd, argv, , claude_home, telemetry=None)

The shell line that runs `argv` (claude) in `cwd` under `claude_home`’s account.

`cd <cwd> && exec env -u ... K=V ... claude ...`, each token quoted. Only the
account’s own variables go on the line ([`xa.claude_env.account_env_tokens()`](_autosummary/xa.claude_env.html.md#xa.claude_env.account_env_tokens)),
never a secret.

`telemetry` (a [`xa.telemetry.TelemetryProfile`](_autosummary/xa.telemetry.html.md#xa.telemetry.TelemetryProfile), default `None`) adds its
trace-export variables and, when it has headers, a pane-side `export` that reads
them from their file when the pane starts: the line holds the expression, not the value.

```pycon
>>> launch_command('/w', ['claude', '--resume', 'x'], claude_home=Path('/h/.claude'))[:12]
'cd /w && exe'
```

* **Return type:**
  [`str`](https://docs.python.org/3/builtins/stdtypes.html#str)

### xa.claude_cli.new_archive_id()

Fresh 12-char hex id used as the key for pane logs + archive events.

* **Return type:**
  [`str`](https://docs.python.org/3/builtins/stdtypes.html#str)

### xa.claude_cli.pid_is_claude(pid)

Portable positive identity check — used before ever signaling a pid.

Liveness ([`xa.claude_fs.ephemeral_session_alive()`](_autosummary/xa.claude_fs.html.md#xa.claude_fs.ephemeral_session_alive)) proves a
process exists; this proves it is actually a claude, so a stale
ephemeral file whose pid got recycled can never direct a kill at an
unrelated process. Uses `/proc` where available, `ps` otherwise.

* **Return type:**
  [`bool`](https://docs.python.org/3/builtins/functions.html#bool)

### xa.claude_cli.prepare_spawn(name, , cwd, resume_id=None, claude_bin='claude', claude_home=PosixPath('/home/runner/.claude'), tmux_bin='tmux', url_timeout_sec=120.0, auto_remote_control=True, claude_name=None, model=None, effort=None, permission_mode=None, allow_bypass=False, pane_log_path=None, archive_store=None, pane_store=None, archive_id=None, telemetry=None, panes=None)

Launch the session’s pane and return without waiting for the URL.

`panes` is the [`xa.panes.PaneProvider`](_autosummary/xa.panes.html.md#xa.panes.PaneProvider) that hosts the pane (default:
tmux, with `tmux_bin`).

Composes per-session claude flags (`--name` / `--model` /
`--effort` / `--remote-control`) when the installed binary
supports them; requested-but-unsupported flags are reported in
`PendingSpawn.warning` rather than failing the spawn.

`auto_remote_control` passes `--remote-control`, which is how xa
asks for Remote Control now — a documented CLI flag, not a keystroke
sent at a TUI. On a claude too old to advertise it, the host’s
`remoteControlAtStartup` setting is the remaining path, so the
warning says so rather than falling back to typing.

`claude_home` is also the session’s *account*: the pane runs claude
under it (`account_env_tokens()`), whatever the tmux server’s own
environment says. `permission_mode` / `allow_bypass` are passed to
`_claude_argv()`. `telemetry` is a [`xa.telemetry.TelemetryProfile`](_autosummary/xa.telemetry.html.md#xa.telemetry.TelemetryProfile)
(opt-in OTLP trace export; see [`launch_command()`](_autosummary/xa.claude_cli.html.md#xa.claude_cli.launch_command)).

* **Return type:**
  [`PendingSpawn`](_autosummary/xa.claude_cli.html.md#xa.claude_cli.PendingSpawn)

### xa.claude_cli.resolve_bridge_url(session_name, , claude_home=PosixPath('/home/runner/.claude'), tmux_bin='tmux', scrape_lines=400, panes=None)

Return `(url, source)` for a live claude session hosted in a pane.

Primary path: find the claude descendant pid → read
`~/.claude/sessions/<pid>.json` → take `bridgeSessionId`.
Fallback: regex-scrape `capture-pane` output for the full URL.

* **Return type:**
  [`tuple`](https://docs.python.org/3/builtins/stdtypes.html#tuple)[[`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)], [`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`Literal`](https://docs.python.org/3/library/typing.html#typing.Literal)[`'session_file'`, `'pane_capture'`]]]

### xa.claude_cli.resume_session(claude_session_id, , cwd, name=None, claude_bin='claude', claude_home=PosixPath('/home/runner/.claude'), tmux_bin='tmux', url_timeout_sec=120.0, auto_remote_control=True, model=None, effort=None, permission_mode=None, allow_bypass=False, pane_log_path=None, archive_store=None, pane_store=None, archive_id=None, telemetry=None)

Launch `claude --resume <id>` in a new detached tmux session.

A user-supplied `name` is also passed to `claude --name` (renaming
the resumed session’s display name); the auto-generated fallback name
is tmux-only so a resume never clobbers the session’s existing name.

* **Return type:**
  [`SpawnResult`](_autosummary/xa.claude_cli.html.md#xa.claude_cli.SpawnResult)

### xa.claude_cli.spawn_session(name, , cwd, claude_bin='claude', claude_home=PosixPath('/home/runner/.claude'), tmux_bin='tmux', url_timeout_sec=120.0, auto_remote_control=True, model=None, effort=None, permission_mode=None, pane_log_path=None, archive_store=None, pane_store=None, archive_id=None, telemetry=None)

Create a detached tmux session running `claude` in `cwd`.

Waits up to `url_timeout_sec` for the bridge URL to appear, dismissing
the “trust this folder” prompt and enabling remote control (via the
`--remote-control` flag on modern claude binaries, or the TUI
handshake on older ones). The session name is also passed to
`claude --name` so the Claude-side display name matches; `model`
and `effort` become per-session `--model` / `--effort` flags.

If `archive_store` (and optionally `pane_store`) are given, emits
`created` + `url_acquired` events to the archive and pipes the pane
output to a file under `pane_store`.

Services that want an immediate return should call
[`prepare_spawn()`](_autosummary/xa.claude_cli.html.md#xa.claude_cli.prepare_spawn) and run [`complete_spawn()`](_autosummary/xa.claude_cli.html.md#xa.claude_cli.complete_spawn) in the background
instead — this function is simply the composition of the two.

* **Return type:**
  [`SpawnResult`](_autosummary/xa.claude_cli.html.md#xa.claude_cli.SpawnResult)

### xa.claude_cli.supported_cli_flags(claude_bin='claude', , ttl_sec=900.0)

Long-form flags advertised by `<claude_bin> --help`, cached per binary.

Lets spawn compose modern per-session flags (`--remote-control`,
`--name`, `--model`, `--effort`) while degrading gracefully on
older installs. Empty set when the binary can’t be executed — callers
then omit every optional flag, matching pre-flag behavior. Only
successful probes are cached (for `ttl_sec`); failures are retried.

* **Return type:**
  [`frozenset`](https://docs.python.org/3/builtins/stdtypes.html#frozenset)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]

### xa.claude_cli.tmux_session_dedicated_to(session_name, claude_pid, , tmux_bin='tmux')

Is killing this whole tmux session equivalent to killing this claude?

True iff the session consists of a single pane whose claude is
`claude_pid`. xa-spawned sessions always qualify; a claude living in
one window of a user’s multi-window workspace never does — killing
the session there would destroy unrelated panes, so callers must fall
back to signaling the pid instead.

* **Return type:**
  [`bool`](https://docs.python.org/3/builtins/functions.html#bool)

### xa.claude_cli.wait_for_bridge_url(session_name, , claude_home, tmux_bin, deadline, poll_sec=0.5, panes=None)

Poll the ephemeral session file until a bridge URL appears.

Nothing is typed into the pane. Claude Code connects Remote Control by
itself — from the `--remote-control` flag `_claude_argv()` passes,
or from the host’s `remoteControlAtStartup` setting — and records the
`bridgeSessionId` when it does. This function’s whole job is to wait
for that write.

Until 0.1.10 this drove the TUI instead: dismissing the workspace-trust
prompt with a blind Enter and sending `/remote-control` once a prompt
glyph appeared. That emulated, by scraping and typing, what the flag and
the setting do properly — and every upstream redraw was a chance for it
to type into the wrong thing. See [`xa.revive`](_autosummary/xa.revive.html.md#module-xa.revive) for the pane reading
that *is* still warranted: reconnecting a session whose Remote Control
dropped is a gap Claude Code genuinely leaves open.

* **Return type:**
  [`tuple`](https://docs.python.org/3/builtins/stdtypes.html#tuple)[[`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)], [`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`Literal`](https://docs.python.org/3/library/typing.html#typing.Literal)[`'session_file'`, `'pane_capture'`]]]


# _autosummary/xa.claude_env.html.md

# xa.claude_env

The environment and flags a fresh `claude` process starts with: account and permissions.

No xa imports and no third-party ones: this is the lowest layer, so that any
launcher (xa’s tmux panes, crowsnest’s spawner, a future terminal-tab provider)
can import one copy of the rules instead of re-deriving them.

**Account.** Claude Code picks its account by `CLAUDE_CONFIG_DIR` (config,
credentials and transcripts all move with it), and reaches the *default* home
only by the variable’s absence. A command line handed to tmux runs in a shell
whose environment is the tmux *server’s*, which belongs to whoever started the
server: possibly another account, possibly a session long gone, whose identity
markers (`CLAUDECODE`, `CLAUDE_CODE_SESSION_ID`, its messaging socket, its
effort) would make the new process register as that dead session’s child.
[`env_prefix()`](_autosummary/xa.claude_env.html.md#xa.claude_env.env_prefix) therefore states every variable it controls either way round:
set when the child should have it, unset (`env -u`) when not. `tmux -e` can
only set, so it cannot express the default home.

**Permissions.** [`permission_args()`](_autosummary/xa.claude_env.html.md#xa.claude_env.permission_args) turns a mode into flags,
[`bypass_refused()`](_autosummary/xa.claude_env.html.md#xa.claude_env.bypass_refused) says where claude would refuse the bypass flags (root,
unless `IS_SANDBOX=1`; the refusal is invisible behind tmux), and
[`resume_permission()`](_autosummary/xa.claude_env.html.md#xa.claude_env.resume_permission) picks the mode a resumed session comes back in.

Moved here from `crowsnest.spawn` (thorwhalen/xa#23), whose tests and
derivation notes it keeps; crowsnest is to import it from here.

### Module Attributes

| [`HOME_ENV_VAR`](_autosummary/xa.claude_env.html.md#xa.claude_env.HOME_ENV_VAR)     | Claude Code's account variable, and the home it means when unset.                                                                                                                                                                                                                                                                                                    |
|-------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [`ACCOUNT_VARS`](_autosummary/xa.claude_env.html.md#xa.claude_env.ACCOUNT_VARS)     | The variables that select which account a session runs under.                                                                                                                                                                                                                                                                                                        |
| [`DROPPED_VARS`](_autosummary/xa.claude_env.html.md#xa.claude_env.DROPPED_VARS)     | they would override the account the home selects (an API key that bills elsewhere).                                                                                                                                                                                                                                                                                  |
| [`SESSION_VARS`](_autosummary/xa.claude_env.html.md#xa.claude_env.SESSION_VARS)     | The `CLAUDE*` variables that identify *one running session* -- who it is, what started it, how to talk to it -- named so that [`env_prefix()`](_autosummary/xa.claude_env.html.md#xa.claude_env.env_prefix) can unset them whether or not *this* process has them (a tmux server keeps the markers of the session that started it and hands them to every pane it opens afterwards). |
| [`SANDBOX_VAR`](_autosummary/xa.claude_env.html.md#xa.claude_env.SANDBOX_VAR)      | Under this variable (`"1"`) Claude Code accepts the bypass flag from root.                                                                                                                                                                                                                                                                                           |
| [`BYPASS_MODE`](_autosummary/xa.claude_env.html.md#xa.claude_env.BYPASS_MODE)      | Claude Code's name for "skip every permission check", and its aliases.                                                                                                                                                                                                                                                                                               |
| [`KNOWN_MODES`](_autosummary/xa.claude_env.html.md#xa.claude_env.KNOWN_MODES)      | The modes `claude --permission-mode` accepts (`default` is the older name of `manual`).                                                                                                                                                                                                                                                                              |
| [`OTLP_HEADERS_VAR`](_autosummary/xa.claude_env.html.md#xa.claude_env.OTLP_HEADERS_VAR) | The variable that carries OTLP request headers (credentials).                                                                                                                                                                                                                                                                                                        |

### Functions

| [`account_env_tokens`](_autosummary/xa.claude_env.html.md#xa.claude_env.account_env_tokens)(home, \*[, environ, telemetry])   | The `env` prefix that runs a command under `home`'s account, markers stripped.   |
|-------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------|
| [`bypass_refused`](_autosummary/xa.claude_env.html.md#xa.claude_env.bypass_refused)(\*[, euid, environ, ...])             | Would claude refuse the bypass flags here? Root, unsandboxed, not vouched for.   |
| [`canonical_permission_mode`](_autosummary/xa.claude_env.html.md#xa.claude_env.canonical_permission_mode)(mode)                      | `mode` spelled as claude spells it; `''` stays `''` (claude's own default).      |
| [`child_env`](_autosummary/xa.claude_env.html.md#xa.claude_env.child_env)([environ, home, drop])                     | `environ` (default `os.environ`) as a new session should inherit it.             |
| [`env_prefix`](_autosummary/xa.claude_env.html.md#xa.claude_env.env_prefix)(env, \*[, environ, drop, markers, ...])   | The <br/><br/>```<br/>``<br/>```<br/><br/>env -u .                               |
| [`permission_args`](_autosummary/xa.claude_env.html.md#xa.claude_env.permission_args)(mode, \*[, allow_bypass])            | The flags that start claude in permission `mode` (`''`/`None`: none).            |
| [`resume_permission`](_autosummary/xa.claude_env.html.md#xa.claude_env.resume_permission)(mode, \*, bypass_seen[, ...])      | `(mode, allow_bypass, warning)` for resuming a session last seen in `mode`.      |

### Classes

| [`OtlpTraces`](_autosummary/xa.claude_env.html.md#xa.claude_env.OtlpTraces)(endpoint[, protocol, headers, ...])   | An opt-in, per-launch OpenTelemetry trace export for one Claude Code session.   |
|---------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------|

### xa.claude_env.ACCOUNT_VARS *= ('CLAUDE_CONFIG_DIR', 'CLAUDE_PROFILE')*

The variables that select which account a session runs under. A shell profile
scheme commonly pairs `CLAUDE_CONFIG_DIR` with a `CLAUDE_PROFILE` label and
re-derives one from the other, so the two travel together or not at all.

### xa.claude_env.BYPASS_MODE *= 'bypassPermissions'*

Claude Code’s name for “skip every permission check”, and its aliases.

### xa.claude_env.DROPPED_VARS *= ('ANTHROPIC_API_KEY',)*

they would
override the account the home selects (an API key that bills elsewhere).

* **Type:**
  Variables a new session must not inherit whatever they are set to

### xa.claude_env.HOME_ENV_VAR *= 'CLAUDE_CONFIG_DIR'*

Claude Code’s account variable, and the home it means when unset.

### xa.claude_env.KNOWN_MODES *= frozenset({'acceptEdits', 'auto', 'bypassPermissions', 'default', 'dontAsk', 'manual', 'plan'})*

The modes `claude --permission-mode` accepts (`default` is the older name of
`manual`). A mode a newer claude adds goes here.

### xa.claude_env.OTLP_HEADERS_VAR *= 'OTEL_EXPORTER_OTLP_HEADERS'*

The variable that carries OTLP request headers (credentials). Never put on a command line.

### *class* xa.claude_env.OtlpTraces(endpoint, protocol='http/protobuf', headers=dict(), content=False, resource=dict(), export_interval_ms=None)

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

An opt-in, per-launch OpenTelemetry trace export for one Claude Code session.

Pass it as `env_prefix(..., telemetry=OtlpTraces(endpoint=...))`. `headers`
(an OTLP backend’s credentials) are never part of the command line
[`env_prefix()`](_autosummary/xa.claude_env.html.md#xa.claude_env.env_prefix) returns, and never in this object’s `repr`: they reach the
process only through [`env()`](_autosummary/xa.claude_env.html.md#xa.claude_env.OtlpTraces.env), for a launcher that starts claude with a process
environment of its own (`subprocess.run(..., env=...)`). The prefix then leaves
the variable to the shell, as it does every other token.

```pycon
>>> t = OtlpTraces('http://127.0.0.1:4318/v1/traces', headers={'Authorization': 'x'})
>>> 'Authorization' in repr(t)
False
>>> t.env(with_headers=False)['OTEL_TRACES_EXPORTER']
'otlp'
```

#### env(, with_headers=True)

The variables that turn trace export on; the headers one only when asked.

* **Return type:**
  [`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]

### xa.claude_env.SANDBOX_VAR *= 'IS_SANDBOX'*

Under this variable (`"1"`) Claude Code accepts the bypass flag from root.
[`env_prefix()`](_autosummary/xa.claude_env.html.md#xa.claude_env.env_prefix) hands it on and never unsets it: a launcher may set it.

### xa.claude_env.SESSION_VARS *= ('CLAUDECODE', 'CLAUDE_AGENT_SDK_VERSION', 'CLAUDE_BG_AUTH_SNAPSHOT_PATH', 'CLAUDE_BG_BACKEND', 'CLAUDE_BG_CLAIM_AUTH', 'CLAUDE_BG_DISPATCHER_RATE_LIMIT_TIER', 'CLAUDE_BG_DISPATCHER_SUBSCRIPTION_TYPE', 'CLAUDE_BG_ISOLATION', 'CLAUDE_BG_MEMORY_TOGGLED_OFF', 'CLAUDE_BG_POST_CLEAR_RESPAWN', 'CLAUDE_BG_PTY_AUTH', 'CLAUDE_BG_RENDEZVOUS_SOCK', 'CLAUDE_BG_RV_AUTH', 'CLAUDE_BG_SESSION_PERMISSION_RULES', 'CLAUDE_BG_SOCKET_TOKENS_PATH', 'CLAUDE_BG_SOURCE', 'CLAUDE_BG_STARTUP_WEDGE_MS', 'CLAUDE_BG_TCC_DISCLAIMED', 'CLAUDE_CODE_BRIDGE_SESSION_ID', 'CLAUDE_CODE_CHILD_SESSION', 'CLAUDE_CODE_CLOUD_SESSION_ID', 'CLAUDE_CODE_ENTRYPOINT', 'CLAUDE_CODE_EXECPATH', 'CLAUDE_CODE_MESSAGING_SOCKET', 'CLAUDE_CODE_MESSAGING_TOKEN', 'CLAUDE_CODE_REMOTE_SESSION_ID', 'CLAUDE_CODE_REMOTE_SESSION_ORIGIN', 'CLAUDE_CODE_REMOTE_SESSION_UUID', 'CLAUDE_CODE_SESSION_ACCESS_TOKEN', 'CLAUDE_CODE_SESSION_ATTENDED', 'CLAUDE_CODE_SESSION_ID', 'CLAUDE_CODE_SESSION_KIND', 'CLAUDE_CODE_SESSION_LOG', 'CLAUDE_CODE_SESSION_NAME', 'CLAUDE_CODE_SESSION_ORIGIN', 'CLAUDE_CODE_SPAWN_TIMESTAMP_MS', 'CLAUDE_CODE_SSE_PORT', 'CLAUDE_CODE_TRIGGER_ID', 'CLAUDE_CODE_WORKER_EPOCH', 'CLAUDE_EFFORT', 'CLAUDE_JOB_DIR', 'CLAUDE_PID', 'CLAUDE_PROJECT_DIR', 'CLAUDE_PROJECT_UUID', 'CLAUDE_SESSION_ID')*

The `CLAUDE*` variables that identify *one running session* – who it is, what
started it, how to talk to it – named so that [`env_prefix()`](_autosummary/xa.claude_env.html.md#xa.claude_env.env_prefix) can unset them
whether or not *this* process has them (a tmux server keeps the markers of the
session that started it and hands them to every pane it opens afterwards).

*Identity, not configuration.* Claude Code reads hundreds of `CLAUDE*`
variables, nearly all settings a person may deliberately export; those stay.
Derived by matching the identity families (session and background-job plumbing,
messaging and bridge sockets, job and project directories) against the name table
of the `claude` binary (`strings $(command -v claude) | grep -oE
'CLAUDE[A-Z0-9_]*'`), not typed out. Re-derive it when Claude Code grows a new
family; `test_session_vars_covers_every_marker_this_live_session_carries` is the
tripwire. Account variables are deliberately absent: see [`ACCOUNT_VARS`](_autosummary/xa.claude_env.html.md#xa.claude_env.ACCOUNT_VARS).

### xa.claude_env.account_env_tokens(home, , environ=None, telemetry=None)

The `env` prefix that runs a command under `home`’s account, markers stripped.

```pycon
>>> toks = account_env_tokens('/h/b', environ={'CLAUDECODE': '1'})
>>> toks[-1], ('-u', 'CLAUDECODE') in zip(toks, toks[1:])
('CLAUDE_CONFIG_DIR=/h/b', True)
```

* **Return type:**
  [`list`](https://docs.python.org/3/builtins/stdtypes.html#list)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]

### xa.claude_env.bypass_refused(, euid=None, environ=None, root_bypass_ok=False)

Would claude refuse the bypass flags here? Root, unsandboxed, not vouched for.

`root_bypass_ok` is for a launcher known to set `IS_SANDBOX` itself.

```pycon
>>> bypass_refused(euid=0, environ={}), bypass_refused(euid=0, environ={'IS_SANDBOX': '1'})
(True, False)
>>> bypass_refused(euid=501, environ={})
False
```

* **Return type:**
  [`bool`](https://docs.python.org/3/builtins/functions.html#bool)

### xa.claude_env.canonical_permission_mode(mode)

`mode` spelled as claude spells it; `''` stays `''` (claude’s own default).

Case-insensitive; every bypass alias is `'bypassPermissions'`. An unknown name
raises `ValueError` listing the known ones.

```pycon
>>> canonical_permission_mode('Bypass'), canonical_permission_mode('acceptedits')
('bypassPermissions', 'acceptEdits')
```

* **Return type:**
  [`str`](https://docs.python.org/3/builtins/stdtypes.html#str)

### xa.claude_env.child_env(environ=None, , home=None, drop=('ANTHROPIC_API_KEY',))

`environ` (default `os.environ`) as a new session should inherit it.

The spawning session’s identity markers ([`SESSION_VARS`](_autosummary/xa.claude_env.html.md#xa.claude_env.SESSION_VARS)) go; the account
and every `CLAUDE*` *setting* (`CLAUDE_CODE_OAUTH_TOKEN`,
`CLAUDE_CODE_USE_BEDROCK`, …) stay. With
`home` the child runs under that home instead: `CLAUDE_CONFIG_DIR` set to it,
or *unset* when it is the default home. The `CLAUDE_PROFILE` label travels only
with the account it labels. `drop` goes too (pass `()` to keep it).

```pycon
>>> child_env({'CLAUDECODE': '1', 'CLAUDE_CONFIG_DIR': '/h/b', 'PATH': '/bin'})
{'CLAUDE_CONFIG_DIR': '/h/b', 'PATH': '/bin'}
>>> child_env({'ANTHROPIC_API_KEY': 'sk-x', 'PATH': '/bin'})
{'PATH': '/bin'}
```

* **Return type:**
  [`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict)

### xa.claude_env.env_prefix(env, , environ=None, drop=('ANTHROPIC_API_KEY',), markers=('CLAUDECODE', 'CLAUDE_AGENT_SDK_VERSION', 'CLAUDE_BG_AUTH_SNAPSHOT_PATH', 'CLAUDE_BG_BACKEND', 'CLAUDE_BG_CLAIM_AUTH', 'CLAUDE_BG_DISPATCHER_RATE_LIMIT_TIER', 'CLAUDE_BG_DISPATCHER_SUBSCRIPTION_TYPE', 'CLAUDE_BG_ISOLATION', 'CLAUDE_BG_MEMORY_TOGGLED_OFF', 'CLAUDE_BG_POST_CLEAR_RESPAWN', 'CLAUDE_BG_PTY_AUTH', 'CLAUDE_BG_RENDEZVOUS_SOCK', 'CLAUDE_BG_RV_AUTH', 'CLAUDE_BG_SESSION_PERMISSION_RULES', 'CLAUDE_BG_SOCKET_TOKENS_PATH', 'CLAUDE_BG_SOURCE', 'CLAUDE_BG_STARTUP_WEDGE_MS', 'CLAUDE_BG_TCC_DISCLAIMED', 'CLAUDE_CODE_BRIDGE_SESSION_ID', 'CLAUDE_CODE_CHILD_SESSION', 'CLAUDE_CODE_CLOUD_SESSION_ID', 'CLAUDE_CODE_ENTRYPOINT', 'CLAUDE_CODE_EXECPATH', 'CLAUDE_CODE_MESSAGING_SOCKET', 'CLAUDE_CODE_MESSAGING_TOKEN', 'CLAUDE_CODE_REMOTE_SESSION_ID', 'CLAUDE_CODE_REMOTE_SESSION_ORIGIN', 'CLAUDE_CODE_REMOTE_SESSION_UUID', 'CLAUDE_CODE_SESSION_ACCESS_TOKEN', 'CLAUDE_CODE_SESSION_ATTENDED', 'CLAUDE_CODE_SESSION_ID', 'CLAUDE_CODE_SESSION_KIND', 'CLAUDE_CODE_SESSION_LOG', 'CLAUDE_CODE_SESSION_NAME', 'CLAUDE_CODE_SESSION_ORIGIN', 'CLAUDE_CODE_SPAWN_TIMESTAMP_MS', 'CLAUDE_CODE_SSE_PORT', 'CLAUDE_CODE_TRIGGER_ID', 'CLAUDE_CODE_WORKER_EPOCH', 'CLAUDE_EFFORT', 'CLAUDE_JOB_DIR', 'CLAUDE_PID', 'CLAUDE_PROJECT_DIR', 'CLAUDE_PROJECT_UUID', 'CLAUDE_SESSION_ID'), telemetry=None)

The `env -u ... K=V ...` tokens that make a fresh shell run a command under `env`.

Each name this controls – `markers`, the `CLAUDE*` names of `environ`
that `env` lacks, [`ACCOUNT_VARS`](_autosummary/xa.claude_env.html.md#xa.claude_env.ACCOUNT_VARS), `drop` and [`DROPPED_VARS`](_autosummary/xa.claude_env.html.md#xa.claude_env.DROPPED_VARS) – is
stated either way round: set when `env` has it, unset when it does not, because
the shell’s environment is not this process’s. Everything else (other settings,
and so any token) is left to the shell rather than written on a command line,
where `ps` and tmux would show it.

```pycon
>>> env_prefix({'CLAUDE_CONFIG_DIR': '/h/b'}, environ={}, markers=('CLAUDECODE',))
['env', '-u', 'CLAUDECODE', '-u', 'CLAUDE_PROFILE', '-u', 'ANTHROPIC_API_KEY', 'CLAUDE_CONFIG_DIR=/h/b']
>>> env_prefix({}, environ={}, markers=('CLAUDECODE',), drop=())
['env', '-u', 'CLAUDECODE', '-u', 'CLAUDE_CONFIG_DIR', '-u', 'CLAUDE_PROFILE', '-u', 'ANTHROPIC_API_KEY']
```

`telemetry` (default `None`: nothing changes) adds [`OtlpTraces`](_autosummary/xa.claude_env.html.md#xa.claude_env.OtlpTraces)’s variables,
without its headers:

```pycon
>>> toks = env_prefix({}, environ={}, markers=(), drop=(),
...     telemetry=OtlpTraces('http://h:4318/v1/traces', headers={'Authorization': 's3cret'}))
>>> 'OTEL_TRACES_EXPORTER=otlp' in toks, any('s3cret' in t for t in toks)
(True, False)
```

* **Return type:**
  [`list`](https://docs.python.org/3/builtins/stdtypes.html#list)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]

### xa.claude_env.permission_args(mode, , allow_bypass=False)

The flags that start claude in permission `mode` (`''`/`None`: none).

`allow_bypass` keeps bypass *reachable* (shift-tab) for a session that starts
in another mode.

```pycon
>>> permission_args('bypass')
['--dangerously-skip-permissions']
>>> permission_args('auto', allow_bypass=True)
['--allow-dangerously-skip-permissions', '--permission-mode', 'auto']
>>> permission_args('')
[]
```

* **Return type:**
  [`list`](https://docs.python.org/3/builtins/stdtypes.html#list)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]

### xa.claude_env.resume_permission(mode, , bypass_seen, euid=None, environ=None)

`(mode, allow_bypass, warning)` for resuming a session last seen in `mode`.

The session comes back in the mode it was last in. If it ever reached bypass
(`bypass_seen`) it was started with the bypass flag, so bypass stays reachable
even when it was last in another mode. Where claude would refuse the bypass flags
([`bypass_refused()`](_autosummary/xa.claude_env.html.md#xa.claude_env.bypass_refused)) they are dropped with a warning: the machine’s own
settings then decide, as they would for a person there. A mode this module does
not know (renamed in a newer claude) is dropped with a warning too, since claude
would refuse it at startup, invisibly, behind tmux.

```pycon
>>> resume_permission('auto', bypass_seen=True, euid=501)
('auto', True, None)
>>> resume_permission('bypassPermissions', bypass_seen=True, euid=0, environ={})[:2]
('', False)
```

* **Return type:**
  [`tuple`](https://docs.python.org/3/builtins/stdtypes.html#tuple)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`bool`](https://docs.python.org/3/builtins/functions.html#bool), [`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]]


# _autosummary/xa.claude_fs.html.md

# xa.claude_fs

Pure filesystem view of `~/.claude/`.

This layer reads Claude Code’s on-disk state and nothing else: no tmux, no
subprocess, no network. It is the substrate every higher layer of `xa`
reads from.

What lives under `~/.claude/` (as of Claude Code 2.x):

- `projects/<slug>/<uuid>.jsonl` — one file per session, full transcript.
  `<slug>` is the cwd with `/` replaced by `-` (leading `-` kept).
  `<uuid>` is the Claude `sessionId`.
- `sessions/<pid>.json` — per-process ephemeral metadata while a
  `claude` process is alive. Holds `pid`, `sessionId`,
  `bridgeSessionId`, `cwd`, `startedAt`, `version`. Deleted when
  the process exits.
- `history.jsonl` — global append-only log of every prompt sent. Each
  line carries `sessionId` + `cwd`.
- `sessions-index.json` — summary index (not yet consumed here).

All functions are read-only. All paths default to the account’s home
([`default_claude_home()`](_autosummary/xa.claude_fs.html.md#xa.claude_fs.default_claude_home): `$XA_CLAUDE_HOME`, else Claude Code’s own
`$CLAUDE_CONFIG_DIR`, else `~/.claude/`) and accept a `claude_home`
override. `XA_CLAUDE_HOME` is also how tests point xa at a fixture tree.

### Module Attributes

| [`CLAUDE_HOME_ENV_VAR`](_autosummary/xa.claude_fs.html.md#xa.claude_fs.CLAUDE_HOME_ENV_VAR)   | Claude Code's account variable ([`xa.claude_env`](_autosummary/xa.claude_env.html.md#module-xa.claude_env) owns it).   |
|------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------|

### Functions

| [`account_default_model`](_autosummary/xa.claude_fs.html.md#xa.claude_fs.account_default_model)(\*[, claude_home])       | The `model` the account's `settings.json` sets, or `None`.                   |
|-------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------|
| [`default_claude_home`](_autosummary/xa.claude_fs.html.md#xa.claude_fs.default_claude_home)([environ])                 | The Claude home xa reads (and launches sessions under) by default.           |
| [`encode_project_slug`](_autosummary/xa.claude_fs.html.md#xa.claude_fs.encode_project_slug)(cwd)                       | Encode a cwd into the `~/.claude/projects/` slug form.                       |
| [`ephemeral_session_alive`](_autosummary/xa.claude_fs.html.md#xa.claude_fs.ephemeral_session_alive)(eph, \*[, proc_root])  | Is the process behind an ephemeral session dict actually alive?              |
| [`history_iter`](_autosummary/xa.claude_fs.html.md#xa.claude_fs.history_iter)(\*[, claude_home])                | Yield entries from `~/.claude/history.jsonl` in file order (oldest first).   |
| [`iter_ephemeral_sessions`](_autosummary/xa.claude_fs.html.md#xa.claude_fs.iter_ephemeral_sessions)(\*[, claude_home])     | Yield all live ephemeral session dicts.                                      |
| [`iter_project_slugs`](_autosummary/xa.claude_fs.html.md#xa.claude_fs.iter_project_slugs)(\*[, claude_home])          | Yield slugs (directory names) under `~/.claude/projects/`.                   |
| [`iter_transcript_events`](_autosummary/xa.claude_fs.html.md#xa.claude_fs.iter_transcript_events)(path)                   | Yield every event from a transcript JSONL.                                   |
| [`iter_transcript_files`](_autosummary/xa.claude_fs.html.md#xa.claude_fs.iter_transcript_files)(\*[, claude_home, ...])  | Yield transcript JSONL paths, optionally restricted to one project.          |
| [`launch_facts`](_autosummary/xa.claude_fs.html.md#xa.claude_fs.launch_facts)(path)                             | Read one transcript for the cwd, mode, model and name it was launched with.  |
| [`parse_project_slug`](_autosummary/xa.claude_fs.html.md#xa.claude_fs.parse_project_slug)(slug)                       | Decode a `~/.claude/projects/` slug back to a cwd.                           |
| [`read_ephemeral_session`](_autosummary/xa.claude_fs.html.md#xa.claude_fs.read_ephemeral_session)(pid, \*[, claude_home]) | Read the per-process session file for `pid` if present.                      |
| [`remote_control_at_startup`](_autosummary/xa.claude_fs.html.md#xa.claude_fs.remote_control_at_startup)(\*[, claude_home])   | Is this host set to auto-connect Remote Control for every session?           |
| [`resume_model`](_autosummary/xa.claude_fs.html.md#xa.claude_fs.resume_model)(facts, \*[, claude_home])         | The `--model` that brings `facts` back on its own model, or `None` for none. |
| [`transcript_forensics`](_autosummary/xa.claude_fs.html.md#xa.claude_fs.transcript_forensics)(path)                     | Extract postmortem-relevant facts from the tail of a transcript.             |
| [`transcript_metadata`](_autosummary/xa.claude_fs.html.md#xa.claude_fs.transcript_metadata)(path)                      | Summarise a transcript without holding it all in memory.                     |
| [`transcript_path`](_autosummary/xa.claude_fs.html.md#xa.claude_fs.transcript_path)(cwd, session_id, \*[, ...])    | Return the transcript path for `(cwd, session_id)` if it exists.             |

### Classes

| [`HistoryEntry`](_autosummary/xa.claude_fs.html.md#xa.claude_fs.HistoryEntry)(cwd, project, display, ...)      | One line from `~/.claude/history.jsonl`.                             |
|------------------------------------------------------------------------------------------------|----------------------------------------------------------------------|
| [`LaunchFacts`](_autosummary/xa.claude_fs.html.md#xa.claude_fs.LaunchFacts)(session_id, transcript, cwd, ...) | What `claude --resume` needs to bring one session back as it was.    |
| [`TranscriptForensics`](_autosummary/xa.claude_fs.html.md#xa.claude_fs.TranscriptForensics)(transcript_path, ...)     | Postmortem facts extracted by walking a transcript from the end.     |
| [`TranscriptMeta`](_autosummary/xa.claude_fs.html.md#xa.claude_fs.TranscriptMeta)(path, session_id, cwd, ...)    | Summary of a transcript JSONL, cheap enough to compute for listings. |

### xa.claude_fs.CLAUDE_HOME_ENV_VAR *= 'CLAUDE_CONFIG_DIR'*

Claude Code’s account variable ([`xa.claude_env`](_autosummary/xa.claude_env.html.md#module-xa.claude_env) owns it).

### *class* xa.claude_fs.HistoryEntry(cwd, project, display, pasted_contents)

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

One line from `~/.claude/history.jsonl`.

### *class* xa.claude_fs.LaunchFacts(session_id, transcript, cwd, permission_mode, bypass_seen, model, effort, name, last_type, last_write, entrypoint=None)

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

What `claude --resume` needs to bring one session back as it was.

#### *property* headless *: [bool](https://docs.python.org/3/builtins/functions.html#bool)*

nothing to resume into a pane.

* **Type:**
  A `claude -p` / SDK run

### *class* xa.claude_fs.TranscriptForensics(transcript_path, line_count, last_tool_name, last_tool_command, last_tool_exit_code, last_tool_result_tail, final_assistant_text, user_interrupted)

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

Postmortem facts extracted by walking a transcript from the end.

`user_interrupted` is the raw marker presence — it is **ambiguous**
(also fires on phone-standby bridge drops), so do not derive user intent
from it alone. Callers should corroborate against pane-log tails.

### *class* xa.claude_fs.TranscriptMeta(path, session_id, cwd, project_slug, summary, custom_title, first_user_message, turn_count, forked_from, created, modified, size_bytes)

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

Summary of a transcript JSONL, cheap enough to compute for listings.

### xa.claude_fs.account_default_model(, claude_home=PosixPath('/home/runner/.claude'))

The `model` the account’s `settings.json` sets, or `None`.

* **Return type:**
  [`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]

### xa.claude_fs.default_claude_home(environ=None)

The Claude home xa reads (and launches sessions under) by default.

`$XA_CLAUDE_HOME` first (xa’s own override), then `$CLAUDE_CONFIG_DIR`
(so an xa run from a second account’s shell sees that account), then
`~/.claude`.

```pycon
>>> str(default_claude_home({'CLAUDE_CONFIG_DIR': '/h/second'}))
'/h/second'
>>> str(default_claude_home({'XA_CLAUDE_HOME': '/x', 'CLAUDE_CONFIG_DIR': '/h/second'}))
'/x'
```

* **Return type:**
  [`Path`](https://docs.python.org/3/library/pathlib.html#pathlib.Path)

### xa.claude_fs.encode_project_slug(cwd)

Encode a cwd into the `~/.claude/projects/` slug form.

Claude Code turns every character that is not a letter, digit or `-` into
`-` (`_` and `.` included), not only `/`.

```pycon
>>> encode_project_slug('/root/py/proj/tt/glossa')
'-root-py-proj-tt-glossa'
>>> encode_project_slug('/p/i/_zodals/tw_platform.v2')
'-p-i--zodals-tw-platform-v2'
>>> encode_project_slug('/')
'-'
```

* **Return type:**
  [`str`](https://docs.python.org/3/builtins/stdtypes.html#str)

### xa.claude_fs.ephemeral_session_alive(eph, , proc_root=PosixPath('/proc'))

Is the process behind an ephemeral session dict actually alive?

The mere presence of `~/.claude/sessions/<pid>.json` proves nothing:
claude removes it on clean exit, but crashes, SIGKILL, and host
reboots leave stale files behind — and a stale file must not surface
as a “live” session (with a dead URL, an unkillable card, and no
postmortem).

Checks, strongest first:

- newer claude versions write `procStart` (the kernel start-time
  ticks) into the file — when present, it must match
  `/proc/<pid>/stat`, which also defeats PID reuse;
- otherwise the pid must exist and look like a claude process
  (`comm == "claude"` for the native binary, or `claude` in the
  cmdline for npm installs running under `node`);
- on platforms without `/proc` (macOS), fall back to signal-0
  existence (no PID-reuse protection, best available).

* **Return type:**
  [`bool`](https://docs.python.org/3/builtins/functions.html#bool)

### xa.claude_fs.history_iter(, claude_home=PosixPath('/home/runner/.claude'))

Yield entries from `~/.claude/history.jsonl` in file order (oldest first).

Useful for cross-project full-text prompt search without loading
every transcript.

* **Return type:**
  [`Iterator`](https://docs.python.org/3/library/typing.html#typing.Iterator)[[`HistoryEntry`](_autosummary/xa.claude_fs.html.md#xa.claude_fs.HistoryEntry)]

### xa.claude_fs.iter_ephemeral_sessions(, claude_home=PosixPath('/home/runner/.claude'))

Yield all live ephemeral session dicts.

A session file disappears when claude exits, so this reflects
momentary state only. NB: claude deletes the file on *clean* exit
only — a crash / SIGKILL / reboot leaves a stale file behind, so
callers who care about actual liveness must validate each dict with
[`ephemeral_session_alive()`](_autosummary/xa.claude_fs.html.md#xa.claude_fs.ephemeral_session_alive) (or an equivalent predicate).

* **Return type:**
  [`Iterator`](https://docs.python.org/3/library/typing.html#typing.Iterator)[[`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict)]

### xa.claude_fs.iter_project_slugs(, claude_home=PosixPath('/home/runner/.claude'))

Yield slugs (directory names) under `~/.claude/projects/`.

* **Return type:**
  [`Iterator`](https://docs.python.org/3/library/typing.html#typing.Iterator)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]

### xa.claude_fs.iter_transcript_events(path)

Yield every event from a transcript JSONL.

Lines that fail to parse are silently skipped — transcripts are
append-only on a live process, so the tail can be partial.

* **Return type:**
  [`Iterator`](https://docs.python.org/3/library/typing.html#typing.Iterator)[[`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict)]

### xa.claude_fs.iter_transcript_files(, claude_home=PosixPath('/home/runner/.claude'), project_slug=None)

Yield transcript JSONL paths, optionally restricted to one project.

Only files whose stem is a valid UUID are yielded — this filters out
the `memory/` subfolder and other non-session artefacts Claude Code
stores alongside transcripts.

* **Return type:**
  [`Iterator`](https://docs.python.org/3/library/typing.html#typing.Iterator)[[`Path`](https://docs.python.org/3/library/pathlib.html#pathlib.Path)]

### xa.claude_fs.launch_facts(path)

Read one transcript for the cwd, mode, model and name it was launched with.

One forward pass; malformed lines are skipped like everywhere else in xa.

* **Return type:**
  [`LaunchFacts`](_autosummary/xa.claude_fs.html.md#xa.claude_fs.LaunchFacts)

### xa.claude_fs.parse_project_slug(slug)

Decode a `~/.claude/projects/` slug back to a cwd.

```pycon
>>> parse_project_slug('-root-py-proj-tt-glossa')
'/root/py/proj/tt/glossa'
>>> parse_project_slug('-Users-thorwhalen-tw-server')
'/Users/thorwhalen/tw/server'
```

NB: This transform is lossy — a cwd with literal `-` in segment names
round-trips to a different slug. Claude Code itself has the same
limitation, so we accept it.

* **Return type:**
  [`str`](https://docs.python.org/3/builtins/stdtypes.html#str)

### xa.claude_fs.read_ephemeral_session(pid, , claude_home=PosixPath('/home/runner/.claude'))

Read the per-process session file for `pid` if present.

* **Return type:**
  [`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict)]

### xa.claude_fs.remote_control_at_startup(, claude_home=PosixPath('/home/runner/.claude'))

Is this host set to auto-connect Remote Control for every session?

Reads `remoteControlAtStartup` from the user `settings.json`.
`None` means “can’t tell” — no file, unreadable, or the key absent
(in which case Claude Code follows its own default, which xa does not
get to observe).

Deliberately only the *user* settings file. Claude Code also honors
the key in project, local and managed settings, and a project-level
`false` outranks a user-level `true` — so a `True` here is
“configured on for this user”, not a guarantee about a given session.
xa uses it to explain a missing URL, never to decide behavior.

* **Return type:**
  [`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`bool`](https://docs.python.org/3/builtins/functions.html#bool)]

### xa.claude_fs.resume_model(facts, , claude_home=PosixPath('/home/runner/.claude'))

The `--model` that brings `facts` back on its own model, or `None` for none.

`None` when the transcript’s model is in the same family as the account’s
default: the default may carry what the transcript does not record (an
`opus[1m]` default runs a 1M-token window, its turns record only
`claude-opus-5-5`), so pinning the bare id would shrink the context of a
session that may already be past 200k. A different family (a sonnet session
on an opus account) is pinned, which is the case the flag exists for.

```pycon
>>> f = LaunchFacts('s', Path('t'), None, '', False, 'claude-sonnet-5-5', None, None, None, 0.0)
>>> resume_model(f, claude_home=Path('/no/such/home'))
'claude-sonnet-5-5'
```

* **Return type:**
  [`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]

### xa.claude_fs.transcript_forensics(path)

Extract postmortem-relevant facts from the tail of a transcript.

Walks from the *end* of the file so we find the most recent
`tool_use` / `tool_result` / assistant `text` without reparsing
the whole transcript.

* **Return type:**
  [`TranscriptForensics`](_autosummary/xa.claude_fs.html.md#xa.claude_fs.TranscriptForensics)

### xa.claude_fs.transcript_metadata(path)

Summarise a transcript without holding it all in memory.

Walks forward, counting turns and capturing the first user message /
summary / custom title / fork pointer / cwd / sessionId. Stops reading
content fields once it has what it needs, but still counts turns to
the end. For very large transcripts, callers who only need counts
should use `iter_transcript_events` directly.

* **Return type:**
  [`TranscriptMeta`](_autosummary/xa.claude_fs.html.md#xa.claude_fs.TranscriptMeta)

### xa.claude_fs.transcript_path(cwd, session_id, , claude_home=PosixPath('/home/runner/.claude'))

Return the transcript path for `(cwd, session_id)` if it exists.

```pycon
>>> from pathlib import Path
>>> import tempfile
>>> with tempfile.TemporaryDirectory() as td:
...     home = Path(td)
...     (home / 'projects' / '-foo-bar').mkdir(parents=True)
...     f = home / 'projects' / '-foo-bar' / 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee.jsonl'
...     _ = f.write_text('')
...     p = transcript_path('/foo/bar', 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee', claude_home=home)
...     p == f
True
```

* **Return type:**
  [`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`Path`](https://docs.python.org/3/library/pathlib.html#pathlib.Path)]


# _autosummary/xa.cli.html.md

# xa.cli

Command-line interface for `xa`.

Exposes subcommands via `cw`: `list`, `info`, `history`, `spawn`,
`resume`, `kill`, `serve`, `sync`, `pick`, `gen-secret`, `revive`, `revive-check`,
and the `archive` group (`list`, `log`, `forensics`).

Entry point: `xa` (see `[project.scripts]` in `pyproject.toml`).

### Functions

| [`archive_forensics_cmd`](_autosummary/xa.cli.html.md#xa.cli.archive_forensics_cmd)(archive_id)                | Print rich forensics for an archived session as JSON.                                                                                            |
|---------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------|
| [`archive_list_cmd`](_autosummary/xa.cli.html.md#xa.cli.archive_list_cmd)([limit, json_out])              | List archived sessions (`created` events, newest first).                                                                                         |
| [`archive_log_cmd`](_autosummary/xa.cli.html.md#xa.cli.archive_log_cmd)(archive_id[, tail_kb])           | Print the pane log for an archived session.                                                                                                      |
| [`gen_secret_cmd`](_autosummary/xa.cli.html.md#xa.cli.gen_secret_cmd)([length])                         | Print a cryptographically strong random hex secret.                                                                                              |
| [`history_cmd`](_autosummary/xa.cli.html.md#xa.cli.history_cmd)([search, limit, json_out])           | Grep over `~/.claude/history.jsonl`.                                                                                                             |
| [`info_cmd`](_autosummary/xa.cli.html.md#xa.cli.info_cmd)(session_id[, json_out])                 | Show full metadata + forensics for one session.                                                                                                  |
| [`kill_cmd`](_autosummary/xa.cli.html.md#xa.cli.kill_cmd)(session_id)                             | Kill the tmux session backing a live Claude Code session.                                                                                        |
| [`list_cmd`](_autosummary/xa.cli.html.md#xa.cli.list_cmd)([project, limit, include_forks, ...])   | List Claude Code sessions across configured hosts, newest first.                                                                                 |
| [`main`](_autosummary/xa.cli.html.md#xa.cli.main)()                                           | Entry point referenced by `pyproject.toml`'s `[project.scripts]`.                                                                                |
| [`mk_parser`](_autosummary/xa.cli.html.md#xa.cli.mk_parser)()                                      | The `xa` parser -- a plain [`argparse.ArgumentParser`](https://docs.python.org/3/library/argparse.html#argparse.ArgumentParser), built, not run. |
| [`pick_cmd`](_autosummary/xa.cli.html.md#xa.cli.pick_cmd)([project, limit, host])                 | Interactive session picker — pick a row by number, then choose an action.                                                                        |
| [`push_cmd`](_autosummary/xa.cli.html.md#xa.cli.push_cmd)(host[, as_name, home, keep_days])       | Mirror this machine's live sessions into `host`'s xa cache (the reverse of sync).                                                                |
| [`resume_cmd`](_autosummary/xa.cli.html.md#xa.cli.resume_cmd)(\*session_ids[, name, cwd, ...])      | Resume past sessions (`claude --resume`) in new tmux panes, as they were launched.                                                               |
| [`revive_check_cmd`](_autosummary/xa.cli.html.md#xa.cli.revive_check_cmd)([ticks, json_out])              | Report-only revive check for a timer: silent when quiet, exit 1 when a pane needs eyes.                                                          |
| [`revive_cmd`](_autosummary/xa.cli.html.md#xa.cli.revive_cmd)([apply, include_held_elsewhere, ...]) | Report — and optionally reconnect — panes whose Remote Control dropped.                                                                          |
| [`serve_cmd`](_autosummary/xa.cli.html.md#xa.cli.serve_cmd)([host, port, mount, username, ...])    | Run the xa HTTP service (requires the `xa[service]` extra).                                                                                      |
| [`spawn_cmd`](_autosummary/xa.cli.html.md#xa.cli.spawn_cmd)(cwd[, name, timeout, ...])             | Spawn a detached claude-in-tmux session and print its remote URL.                                                                                |
| [`sync_cmd`](_autosummary/xa.cli.html.md#xa.cli.sync_cmd)([host, force])                          | Refresh remote-host caches (SSH hosts; HTTP is always fresh).                                                                                    |
| [`telemetry_headers_cmd`](_autosummary/xa.cli.html.md#xa.cli.telemetry_headers_cmd)(profile)                   | Print a telemetry profile's `OTEL_EXPORTER_OTLP_HEADERS` value (a credential).                                                                   |

### xa.cli.archive_forensics_cmd(archive_id)

Print rich forensics for an archived session as JSON.

* **Parameters:**
  **archive_id** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Archive id from `xa archive list`.
* **Return type:**
  [`None`](https://docs.python.org/3/builtins/constants.html#None)

### xa.cli.archive_list_cmd(limit=30, json_out=False)

List archived sessions (`created` events, newest first).

* **Parameters:**
  * **limit** ([`int`](https://docs.python.org/3/builtins/functions.html#int)) – Maximum rows (0 = unlimited).
  * **json_out** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool)) – One JSON object per line.
* **Return type:**
  [`None`](https://docs.python.org/3/builtins/constants.html#None)

### xa.cli.archive_log_cmd(archive_id, tail_kb=64)

Print the pane log for an archived session.

* **Parameters:**
  * **archive_id** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – The archive id (first column of `xa archive list`).
  * **tail_kb** ([`int`](https://docs.python.org/3/builtins/functions.html#int)) – Only print the last N KB (0 = full log).
* **Return type:**
  [`None`](https://docs.python.org/3/builtins/constants.html#None)

### xa.cli.gen_secret_cmd(length=32)

Print a cryptographically strong random hex secret.

Useful for `XA_PASSWORD`, `XA_CAPTCHA_KEY`, bearer tokens. Output
is to stdout with a trailing newline; pipe it into anything.

* **Parameters:**
  **length** ([`int`](https://docs.python.org/3/builtins/functions.html#int)) – Byte length of the secret (hex output is 2x this).
* **Return type:**
  [`None`](https://docs.python.org/3/builtins/constants.html#None)

### xa.cli.history_cmd(search=None, limit=20, json_out=False)

Grep over `~/.claude/history.jsonl`.

* **Parameters:**
  * **search** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]) – Case-insensitive substring to filter on (display field).
  * **limit** ([`int`](https://docs.python.org/3/builtins/functions.html#int)) – Maximum rows to emit (0 = unlimited).
  * **json_out** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool)) – Emit one JSON object per line.
* **Return type:**
  [`None`](https://docs.python.org/3/builtins/constants.html#None)

### xa.cli.info_cmd(session_id, json_out=False)

Show full metadata + forensics for one session.

* **Parameters:**
  * **session_id** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Full UUID or unique prefix (e.g. first 8 chars).
  * **json_out** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool)) – Emit a single JSON object.
* **Return type:**
  [`None`](https://docs.python.org/3/builtins/constants.html#None)

### xa.cli.kill_cmd(session_id)

Kill the tmux session backing a live Claude Code session.

* **Parameters:**
  **session_id** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Full UUID or unique prefix, or a tmux session name.
* **Return type:**
  [`None`](https://docs.python.org/3/builtins/constants.html#None)

### xa.cli.list_cmd(project=None, limit=30, include_forks=True, no_live=False, state=None, host=None, json_out=False)

List Claude Code sessions across configured hosts, newest first.

* **Parameters:**
  * **project** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]) – Substring match against session cwd (case-insensitive).
  * **limit** ([`int`](https://docs.python.org/3/builtins/functions.html#int)) – Maximum rows to show (0 = unlimited).
  * **include_forks** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool)) – Include sessions spawned with `claude --resume`.
  * **no_live** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool)) – Skip the tmux/ephemeral scan (archive-only view).
  * **state** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]) – Restrict to ‘live’, ‘archived’, or ‘transcript_only’.
  * **host** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]) – Restrict to a single configured host by name.
  * **json_out** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool)) – Emit one JSON object per line instead of a table.
* **Return type:**
  [`None`](https://docs.python.org/3/builtins/constants.html#None)

### xa.cli.main()

Entry point referenced by `pyproject.toml`’s `[project.scripts]`.

* **Return type:**
  [`None`](https://docs.python.org/3/builtins/constants.html#None)

### xa.cli.mk_parser()

The `xa` parser – a plain [`argparse.ArgumentParser`](https://docs.python.org/3/library/argparse.html#argparse.ArgumentParser), built, not run.

Two calls rather than one `cw.dispatch(...)` because the `archive` group
carries `group_kwargs` (its one-line help in the top-level listing), and a
single mapping has nowhere to put those.

* **Return type:**
  [`ArgumentParser`](https://docs.python.org/3/library/argparse.html#argparse.ArgumentParser)

### xa.cli.pick_cmd(project=None, limit=30, host=None)

Interactive session picker — pick a row by number, then choose an action.

A pragmatic v1 picker without a TUI framework. Use **xa list**
for scripting; use **xa pick** when a human is at the keyboard.

* **Return type:**
  [`None`](https://docs.python.org/3/builtins/constants.html#None)

### xa.cli.push_cmd(host, as_name=None, home='~/.claude', keep_days=7)

Mirror this machine’s live sessions into `host`’s xa cache (the reverse of sync).

For a machine the hub cannot reach (a laptop behind NAT): the hub reads the mirror as a
crowsnest home with `liveness = "mirror"`. Run it every minute from a scheduler.

* **Parameters:**
  * **host** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – A configured SSH host, or any ssh target (`~/.ssh/config` alias, `user@host`).
  * **as_name** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]) – The name this machine has on the hub (default: this host’s short name).
  * **home** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – The Claude home to mirror.
  * **keep_days** ([`int`](https://docs.python.org/3/builtins/functions.html#int)) – Prune ended sessions’ transcripts on the hub after this many days.
* **Return type:**
  [`None`](https://docs.python.org/3/builtins/constants.html#None)

### xa.cli.resume_cmd(\*session_ids, name=None, cwd=None, timeout=120.0, model=None, effort=None, home=None, permission_mode=None, since_shutdown=False, apply=False, window=120.0, json_out=False, telemetry=None)

Resume past sessions (`claude --resume`) in new tmux panes, as they were launched.

Each comes back in its original cwd, under its account, with its model
(when its family differs from the account default) and permission mode
(`--dangerously-skip-permissions` included) read from its transcript;
any of these flags overrides the transcript.

`--since-shutdown` finds the sessions that were alive at the last
shutdown and lists them (a dry run); add `--apply` to resume them all.

* **Parameters:**
  * **session_ids** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Full UUIDs or unique prefixes (omit with –since-shutdown).
  * **name** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]) – Session name — tmux session and claude display name (one session only).
  * **cwd** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]) – Override cwd (defaults to the session’s original cwd).
  * **timeout** ([`float`](https://docs.python.org/3/builtins/functions.html#float)) – Seconds to wait for each bridge URL.
  * **model** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]) – Per-session `claude --model` (omitted → the transcript’s model).
  * **effort** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]) – Per-session `claude --effort` (omitted → the account’s default).
  * **home** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]) – Claude home (account) to resume from and run under (default: $XA_CLAUDE_HOME, $CLAUDE_CONFIG_DIR, ~/.claude).
  * **permission_mode** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]) – Override the transcript’s permission mode (`bypass`, `auto`, `default`…).
  * **since_shutdown** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool)) – Select the sessions alive at the last shutdown instead of ids.
  * **apply** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool)) – With –since-shutdown, actually resume them (default: list only).
  * **window** ([`float`](https://docs.python.org/3/builtins/functions.html#float)) – With –since-shutdown, seconds before the shutdown record a last write may land.
  * **json_out** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool)) – Emit one JSON object per session instead of text.
  * **telemetry** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]) – Name of a `[telemetry.<name>]` profile in the xa config: export the resumed sessions’ OTLP traces there (off by default; local sessions only).
* **Return type:**
  [`None`](https://docs.python.org/3/builtins/constants.html#None)

### xa.cli.revive_check_cmd(ticks=2, json_out=False)

Report-only revive check for a timer: silent when quiet, exit 1 when a pane needs eyes.

Sends nothing, ever. Counts consecutive ticks each pane stays reconnectable and
reports (and exits 1) only for panes at or past `--ticks`.

* **Parameters:**
  * **ticks** ([`int`](https://docs.python.org/3/builtins/functions.html#int)) – Consecutive reconnectable ticks before a pane is reported.
  * **json_out** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool)) – Emit JSON for the escalated panes instead of the table.
* **Return type:**
  [`None`](https://docs.python.org/3/builtins/constants.html#None)

### xa.cli.revive_cmd(apply=False, include_held_elsewhere=False, server_mode=False, min_interval=0.0, json_out=False)

Report — and optionally reconnect — panes whose Remote Control dropped.

Prints one line per live claude pane with its verdict, so “nothing to do”
is legible next to how much was looked at. Sends nothing without
`--apply`.

* **Parameters:**
  * **apply** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool)) – Actually send `/remote-control`. Off by default.
  * **include_held_elsewhere** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool)) – Also reconnect sessions taken over from
    another device. This steals them back — deliberate keystroke only.
  * **server_mode** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool)) – Also restart died `claude remote-control` servers.
  * **min_interval** ([`float`](https://docs.python.org/3/builtins/functions.html#float)) – Seconds before the same pane may be touched again
    (0 uses the default guard interval).
  * **json_out** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool)) – Emit JSON instead of the table.
* **Return type:**
  [`None`](https://docs.python.org/3/builtins/constants.html#None)

### xa.cli.serve_cmd(host='127.0.0.1', port=8010, mount='', username=None, password=None, password_env=None, captcha=False, webui=True, default_folder=None, i_know_its_insecure=False)

Run the xa HTTP service (requires the `xa[service]` extra).

**Secure by default.** Refuses to bind to a non-loopback interface
without HTTP Basic credentials. Override this guardrail with
`--i-know-its-insecure` only in locked-down deployments (e.g.
behind an mTLS-terminating proxy).

* **Parameters:**
  * **host** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Bind host. `127.0.0.1` by default — only this machine.
  * **port** ([`int`](https://docs.python.org/3/builtins/functions.html#int)) – Bind port.
  * **mount** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Optional mount prefix (e.g. `/api/xa`).
  * **username** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]) – HTTP Basic username.
  * **password** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]) – HTTP Basic password. Prefer `--password-env`.
  * **password_env** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]) – Name of env var to read the password from (recommended).
  * **captcha** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool)) – Enable captcha-gated deletes. Strongly recommended for
    any non-loopback deployment.
  * **webui** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool)) – Serve the bundled web UI at the mount root (default on).
    Pass `--no-webui` to run API-only.
  * **default_folder** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]) – Default working directory the webui prefills into
    the “new session” dialog and the folder chooser opens at. Falls back
    to `$XA_DEFAULT_FOLDER` or `$HOME` if unset.
  * **i_know_its_insecure** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool)) – Skip the public-bind-without-auth safety check.
* **Return type:**
  [`None`](https://docs.python.org/3/builtins/constants.html#None)

### xa.cli.spawn_cmd(cwd, name=None, timeout=120.0, no_remote_control=False, model=None, effort=None, home=None, permission_mode=None, telemetry=None)

Spawn a detached claude-in-tmux session and print its remote URL.

* **Parameters:**
  * **cwd** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Working directory to start claude in.
  * **name** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]) – Session name — tmux session and claude display name (auto if omitted).
  * **timeout** ([`float`](https://docs.python.org/3/builtins/functions.html#float)) – Seconds to wait for the bridge URL.
  * **no_remote_control** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool)) – Spawn without passing `--remote-control`.
  * **model** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]) – Per-session `claude --model` (omitted → claude’s default).
  * **effort** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]) – Per-session `claude --effort` (omitted → claude’s default).
  * **home** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]) – Claude home (account) to run under (default: $XA_CLAUDE_HOME, $CLAUDE_CONFIG_DIR, ~/.claude).
  * **permission_mode** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]) – `claude --permission-mode` (`bypass` → `--dangerously-skip-permissions`).
  * **telemetry** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]) – Name of a `[telemetry.<name>]` profile in the xa config: export this session’s OTLP traces there (off by default).
* **Return type:**
  [`None`](https://docs.python.org/3/builtins/constants.html#None)

### xa.cli.sync_cmd(host=None, force=False)

Refresh remote-host caches (SSH hosts; HTTP is always fresh).

* **Parameters:**
  * **host** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]) – Only sync this one host (default: all configured).
  * **force** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool)) – Sync even if the cache isn’t stale yet.
* **Return type:**
  [`None`](https://docs.python.org/3/builtins/constants.html#None)

### xa.cli.telemetry_headers_cmd(profile)

Print a telemetry profile’s `OTEL_EXPORTER_OTLP_HEADERS` value (a credential).

Run by a launched pane’s own shell, inside `$(...)`, so the value reaches claude’s
environment and never a command line. Not for typing at a terminal.

* **Parameters:**
  **profile** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Name of a `[telemetry.<name>]` profile.
* **Return type:**
  [`None`](https://docs.python.org/3/builtins/constants.html#None)


# _autosummary/xa.config.html.md

# xa.config

TOML config loader for `xa`.

Resolves a host registry and settings from `~/.config/xa/config.toml`
(respecting `$XDG_CONFIG_HOME`). Override the path via `$XA_CONFIG`.

### Example

```toml
[settings]
cache_dir = "~/.cache/xa/remotes"
stale_threshold_sec = 3600

[nav]                            # optional links to your other pages: label = address
Tasks = "/tasks/"
Docs = "https://docs.example.com/"

[hosts.local]
kind = "local"

[hosts.devbox]
kind = "ssh"
host = "devbox"

[hosts.phone_mirror]
kind = "http"
base_url = "https://apps.example.com/api/xa"
auth = "basic"
username = "me"
password_env = "XA_PHONE_PASSWORD"   # value read from env, not stored in TOML
```

The registry exposed by [`load_hosts()`](_autosummary/xa.config.html.md#xa.config.load_hosts) is `{name: Host}` and can be
passed directly to [`xa.sessions.list_sessions()`](_autosummary/xa.sessions.html.md#xa.sessions.list_sessions).

### Functions

| `default_config_path`()                                               |                                                                                       |
|-----------------------------------------------------------------------|---------------------------------------------------------------------------------------|
| [`load`](_autosummary/xa.config.html.md#xa.config.load)([path])         | Return `(settings, hosts_registry)` from a config file.                               |
| [`load_hosts`](_autosummary/xa.config.html.md#xa.config.load_hosts)([path])   | Shortcut: just the host registry.                                                     |
| [`load_nav`](_autosummary/xa.config.html.md#xa.config.load_nav)([path])     | The `[nav]` links of the config file; empty when there is no file or no table.        |
| [`nav_entries`](_autosummary/xa.config.html.md#xa.config.nav_entries)(raw_nav) | `(label, address)` pairs of a `[nav]` table, in file order, unsafe addresses dropped. |

### Classes

| [`Settings`](_autosummary/xa.config.html.md#xa.config.Settings)(cache_dir[, stale_threshold_sec, ...])   |    |
|----------------------------------------------------------------------------------------------------|----|

### *class* xa.config.Settings(cache_dir, stale_threshold_sec=3600, claude_bin='claude', tmux_bin='tmux')

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

### xa.config.load(path=None)

Return `(settings, hosts_registry)` from a config file.

Missing file → `(defaults, {"local": LocalHost()})`.

* **Return type:**
  [`tuple`](https://docs.python.org/3/builtins/stdtypes.html#tuple)[[`Settings`](_autosummary/xa.config.html.md#xa.config.Settings), [`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict)]

### xa.config.load_hosts(path=None)

Shortcut: just the host registry.

* **Return type:**
  [`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict)

### xa.config.load_nav(path=None)

The `[nav]` links of the config file; empty when there is no file or no table.

* **Return type:**
  [`list`](https://docs.python.org/3/builtins/stdtypes.html#list)[[`tuple`](https://docs.python.org/3/builtins/stdtypes.html#tuple)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]]

### xa.config.nav_entries(raw_nav)

`(label, address)` pairs of a `[nav]` table, in file order, unsafe addresses dropped.

An address is kept only when it is an `http(s)` URL or a path on the same host
(`/tasks/`, not `//elsewhere`): a `javascript:` or `data:` link in a config
must not become a link on the page.

```pycon
>>> nav_entries({'A': '/a/', 'B': 'https://b.example/', 'C': 'javascript:x', 'D': '//d'})
[('A', '/a/'), ('B', 'https://b.example/')]
```

* **Return type:**
  [`list`](https://docs.python.org/3/builtins/stdtypes.html#list)[[`tuple`](https://docs.python.org/3/builtins/stdtypes.html#tuple)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]]


# _autosummary/xa.hosts.html.md

# xa.hosts

Host abstraction — local, SSH, HTTP backends.

A `Host` is anything that can enumerate Claude Code sessions and
perform lifecycle actions on them (spawn / resume / kill). All transports
return the same [`xa.sessions.Session`](_autosummary/xa.sessions.html.md#xa.sessions.Session) shape so higher layers
don’t care whether sessions live on this machine, on another machine
over SSH, or behind another `xa` server over HTTPS.

The protocol is duck-typed (`runtime_checkable`), so user extensions
only need to implement the methods they actually use — unused methods
can raise `NotImplementedError`.

### Functions

| [`default_hosts`](_autosummary/xa.hosts.html.md#xa.hosts.default_hosts)()   | The out-of-the-box registry: one local host, nothing else.   |
|--------------------------------------------------------------------|--------------------------------------------------------------|

### Classes

| [`Host`](_autosummary/xa.hosts.html.md#xa.hosts.Host)(\*args, \*\*kwargs)                        | Duck-typed interface every transport satisfies.   |
|--------------------------------------------------------------------------------------------------|---------------------------------------------------|
| [`LocalHost`](_autosummary/xa.hosts.html.md#xa.hosts.LocalHost)([name, claude_home, claude_bin, ...]) | The machine `xa` is running on.                   |
| [`SSHHost`](_autosummary/xa.hosts.html.md#xa.hosts.SSHHost)(name, \*, host[, user, ...])            | Transcripts via rsync; actions via ssh exec.      |
| [`HTTPHost`](_autosummary/xa.hosts.html.md#xa.hosts.HTTPHost)(name, \*, base_url[, auth, ...])       | Client for a remote `xa serve` instance.          |

### *class* xa.hosts.HTTPHost(name, , base_url, auth=None, username=None, password=None, token=None, timeout=30.0)

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

Client for a remote `xa serve` instance.

#### sync(, force=False)

HTTP sessions are fetched fresh on each listing — no separate sync.

* **Return type:**
  [`None`](https://docs.python.org/3/builtins/constants.html#None)

### *class* xa.hosts.Host(\*args, \*\*kwargs)

Bases: [`Protocol`](https://docs.python.org/3/library/typing.html#typing.Protocol)

Duck-typed interface every transport satisfies.

### *class* xa.hosts.LocalHost(name='local', , claude_home=PosixPath('/home/runner/.claude'), claude_bin='claude', tmux_bin='tmux', alive_predicate=None)

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

The machine `xa` is running on.

#### sync(, force=False)

No-op — local has nothing to sync.

* **Return type:**
  [`None`](https://docs.python.org/3/builtins/constants.html#None)

### *class* xa.hosts.SSHHost(name, , host, user=None, remote_claude_home='~/.claude', cache_dir=PosixPath('/home/runner/.cache/xa/remotes'), stale_threshold_sec=3600, claude_bin='claude', tmux_bin='tmux', ssh_bin='ssh', rsync_bin='rsync')

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

Transcripts via rsync; actions via ssh exec.

* **Parameters:**
  * **name** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Logical name used in `Session.host` and elsewhere.
  * **host** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – SSH hostname / alias. Matches cc-sessions: either an
    `~/.ssh/config` alias (`devbox`) or a raw host (`1.2.3.4`).
  * **user** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]) – Optional SSH user for raw hosts.
  * **remote_claude_home** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Remote path to `~/.claude/`. Defaults to `~/.claude` which
    resolves relative to the SSH user’s home on the remote side.
  * **cache_dir** ([`Path`](https://docs.python.org/3/library/pathlib.html#pathlib.Path)) – Where to stage the rsync’d tree locally.
  * **stale_threshold_sec** ([`int`](https://docs.python.org/3/builtins/functions.html#int)) – Re-sync when the cached copy is older than this. `0` means
    always sync.

#### spawn(name, , cwd, \*\*opts)

Spawn `tmux new-session -d 's <name>' 'cd <cwd> && exec claude'` over SSH.

URL detection is left to the caller’s next [`sync()`](_autosummary/xa.hosts.html.md#xa.hosts.SSHHost.sync) + listing —
we don’t round-trip waiting for the bridge URL here (that would
hold an SSH connection open for up to 2 minutes).

* **Return type:**
  [`SpawnResult`](_autosummary/xa.claude_cli.html.md#xa.claude_cli.SpawnResult)

#### sync(, force=False)

Pull `<remote_claude_home>/projects/` and `/sessions/` into the cache.

Non-existent remote directories are tolerated (rsync returns 23).

* **Return type:**
  [`None`](https://docs.python.org/3/builtins/constants.html#None)

### xa.hosts.default_hosts()

The out-of-the-box registry: one local host, nothing else.

* **Return type:**
  [`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`Host`](_autosummary/xa.hosts.html.md#xa.hosts.Host)]

### Modules

| [`http`](_autosummary/xa.hosts.http.html.md#module-xa.hosts.http)   | HTTP host — a remote `xa serve` instance.   |
|------------------------------------------------------------------------------|---------------------------------------------|
| [`local`](_autosummary/xa.hosts.local.html.md#module-xa.hosts.local) | Local in-process host.                      |
| [`ssh`](_autosummary/xa.hosts.ssh.html.md#module-xa.hosts.ssh)     | SSH-backed host.                            |


# _autosummary/xa.hosts.http.html.md

# xa.hosts.http

HTTP host — a remote `xa serve` instance.

The remote must be running `xa serve` (or an API with the same
`/sessions` + `/archive` surface) and be reachable over HTTPS.
All discovery and actions are performed through the API; no SSH keys,
no rsync. Auth is pluggable:

- `auth="basic"` → HTTP Basic with `username` / `password`
- `auth="bearer"` → `Authorization: Bearer <token>`
- `auth=None`   → no auth (host is already gated upstream)

`urllib` is used for transport so there’s no hard dep on `httpx`
or `requests`; `xa.hosts.http` works in any Python 3.10+ install.

### Classes

| [`HTTPHost`](_autosummary/xa.hosts.http.html.md#xa.hosts.http.HTTPHost)(name, \*, base_url[, auth, ...])   | Client for a remote `xa serve` instance.   |
|----------------------------------------------------------------------------------------------|--------------------------------------------|

### *class* xa.hosts.http.HTTPHost(name, , base_url, auth=None, username=None, password=None, token=None, timeout=30.0)

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

Client for a remote `xa serve` instance.

#### sync(, force=False)

HTTP sessions are fetched fresh on each listing — no separate sync.

* **Return type:**
  [`None`](https://docs.python.org/3/builtins/constants.html#None)


# _autosummary/xa.hosts.local.html.md

# xa.hosts.local

Local in-process host.

All discovery and actions hit the local filesystem / tmux / `claude`
binary directly. Most `xa` users never instantiate any other host.

### Classes

| [`LocalHost`](_autosummary/xa.hosts.local.html.md#xa.hosts.local.LocalHost)([name, claude_home, claude_bin, ...])   | The machine `xa` is running on.   |
|----------------------------------------------------------------------------------------------------|-----------------------------------|

### *class* xa.hosts.local.LocalHost(name='local', , claude_home=PosixPath('/home/runner/.claude'), claude_bin='claude', tmux_bin='tmux', alive_predicate=None)

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

The machine `xa` is running on.

#### sync(, force=False)

No-op — local has nothing to sync.

* **Return type:**
  [`None`](https://docs.python.org/3/builtins/constants.html#None)


# _autosummary/xa.hosts.ssh.html.md

# xa.hosts.ssh

SSH-backed host.

Mirrors the cc-sessions transport pattern: pull the remote’s
`~/.claude/` tree into a local cache via `rsync -az --delete -e ssh`,
then read the cache with the same `claude_fs` code paths we use for
local discovery. Actions (`spawn` / `resume` / `kill` / tmux queries)
dispatch to the remote via `ssh <host> <cmd>`.

No Python SSH library is pulled in: we shell out to the system `ssh` /
`rsync` binaries, which means the user’s `~/.ssh/config`, agent, and
host keys Just Work. Install overhead: zero.

### Module Attributes

| [`SYNC_MARKER`](_autosummary/xa.hosts.ssh.html.md#xa.hosts.ssh.SYNC_MARKER)   | Written into the cache dir after a successful sync; staleness reads its mtime.   |
|----------------------------------------------------------------|----------------------------------------------------------------------------------|

### Classes

| [`SSHHost`](_autosummary/xa.hosts.ssh.html.md#xa.hosts.ssh.SSHHost)(name, \*, host[, user, ...])   | Transcripts via rsync; actions via ssh exec.   |
|-----------------------------------------------------------------------------------------|------------------------------------------------|

### *class* xa.hosts.ssh.SSHHost(name, , host, user=None, remote_claude_home='~/.claude', cache_dir=PosixPath('/home/runner/.cache/xa/remotes'), stale_threshold_sec=3600, claude_bin='claude', tmux_bin='tmux', ssh_bin='ssh', rsync_bin='rsync')

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

Transcripts via rsync; actions via ssh exec.

* **Parameters:**
  * **name** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Logical name used in `Session.host` and elsewhere.
  * **host** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – SSH hostname / alias. Matches cc-sessions: either an
    `~/.ssh/config` alias (`devbox`) or a raw host (`1.2.3.4`).
  * **user** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]) – Optional SSH user for raw hosts.
  * **remote_claude_home** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Remote path to `~/.claude/`. Defaults to `~/.claude` which
    resolves relative to the SSH user’s home on the remote side.
  * **cache_dir** ([`Path`](https://docs.python.org/3/library/pathlib.html#pathlib.Path)) – Where to stage the rsync’d tree locally.
  * **stale_threshold_sec** ([`int`](https://docs.python.org/3/builtins/functions.html#int)) – Re-sync when the cached copy is older than this. `0` means
    always sync.

#### spawn(name, , cwd, \*\*opts)

Spawn `tmux new-session -d 's <name>' 'cd <cwd> && exec claude'` over SSH.

URL detection is left to the caller’s next [`sync()`](_autosummary/xa.hosts.ssh.html.md#xa.hosts.ssh.SSHHost.sync) + listing —
we don’t round-trip waiting for the bridge URL here (that would
hold an SSH connection open for up to 2 minutes).

* **Return type:**
  [`SpawnResult`](_autosummary/xa.claude_cli.html.md#xa.claude_cli.SpawnResult)

#### sync(, force=False)

Pull `<remote_claude_home>/projects/` and `/sessions/` into the cache.

Non-existent remote directories are tolerated (rsync returns 23).

* **Return type:**
  [`None`](https://docs.python.org/3/builtins/constants.html#None)

### xa.hosts.ssh.SYNC_MARKER *= '.xa-synced-at'*

Written into the cache dir after a successful sync; staleness reads its mtime.


# _autosummary/xa.html.md

# xa

xa — tools for managing remote Claude Code sessions.

### Functions

| [`encode_project_slug`](_autosummary/xa.html.md#xa.encode_project_slug)(cwd)                           | Encode a cwd into the `~/.claude/projects/` slug form.                              |
|-----------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------|
| [`history_iter`](_autosummary/xa.html.md#xa.history_iter)(\*[, claude_home])                    | Yield entries from `~/.claude/history.jsonl` in file order (oldest first).          |
| [`iter_ephemeral_sessions`](_autosummary/xa.html.md#xa.iter_ephemeral_sessions)(\*[, claude_home])         | Yield all live ephemeral session dicts.                                             |
| [`iter_project_slugs`](_autosummary/xa.html.md#xa.iter_project_slugs)(\*[, claude_home])              | Yield slugs (directory names) under `~/.claude/projects/`.                          |
| [`iter_transcript_events`](_autosummary/xa.html.md#xa.iter_transcript_events)(path)                       | Yield every event from a transcript JSONL.                                          |
| [`iter_transcript_files`](_autosummary/xa.html.md#xa.iter_transcript_files)(\*[, claude_home, ...])      | Yield transcript JSONL paths, optionally restricted to one project.                 |
| [`parse_project_slug`](_autosummary/xa.html.md#xa.parse_project_slug)(slug)                           | Decode a `~/.claude/projects/` slug back to a cwd.                                  |
| [`read_ephemeral_session`](_autosummary/xa.html.md#xa.read_ephemeral_session)(pid, \*[, claude_home])     | Read the per-process session file for `pid` if present.                             |
| [`transcript_forensics`](_autosummary/xa.html.md#xa.transcript_forensics)(path)                         | Extract postmortem-relevant facts from the tail of a transcript.                    |
| [`transcript_metadata`](_autosummary/xa.html.md#xa.transcript_metadata)(path)                          | Summarise a transcript without holding it all in memory.                            |
| [`transcript_path`](_autosummary/xa.html.md#xa.transcript_path)(cwd, session_id, \*[, ...])        | Return the transcript path for `(cwd, session_id)` if it exists.                    |
| [`resolve_bridge_url`](_autosummary/xa.html.md#xa.resolve_bridge_url)(session_name, \*[, ...])        | Return `(url, source)` for a live claude session hosted in a pane.                  |
| [`resume_session`](_autosummary/xa.html.md#xa.resume_session)(claude_session_id, \*, cwd[, ...])  | Launch `claude --resume <id>` in a new detached tmux session.                       |
| [`spawn_session`](_autosummary/xa.html.md#xa.spawn_session)(name, \*, cwd[, claude_bin, ...])    | Create a detached tmux session running `claude` in `cwd`.                           |
| [`get_session`](_autosummary/xa.html.md#xa.get_session)(session_id, \*[, hosts, claude_home])  | Find one session by full ID or unique prefix.                                       |
| [`iter_local_sessions`](_autosummary/xa.html.md#xa.iter_local_sessions)(\*[, claude_home, ...])        | Legacy local-only iterator.                                                         |
| [`kill_session`](_autosummary/xa.html.md#xa.kill_session)(session, \*[, hosts])                 | Kill a live `Session`, scoped to what actually belongs to it.                       |
| [`list_sessions`](_autosummary/xa.html.md#xa.list_sessions)(\*[, hosts, project, ...])           | Return sessions sorted by recency (live first, then newest-modified).               |
| [`resume`](_autosummary/xa.html.md#xa.resume)(session, \*[, cwd, name, hosts])            | Resume a transcript / archived session on its originating host, as it was launched. |
| [`default_events_store`](_autosummary/xa.html.md#xa.default_events_store)([state_dir])                  | The event log at `<state_dir>/events.jsonl`.                                        |
| [`default_pane_store`](_autosummary/xa.html.md#xa.default_pane_store)([state_dir])                    | Per-session pane logs at `<state_dir>/panes/<id>.log`.                              |
| `append_created`(events, \*, id, name, cwd, ...)                                                    |                                                                                     |
| `append_gone`(events, \*, id, name, reason[, ...])                                                  |                                                                                     |
| [`append_hidden`](_autosummary/xa.html.md#xa.append_hidden)(events, \*, id, hidden)              | Mark an archived session as hidden (or un-hide it).                                 |
| [`append_label`](_autosummary/xa.html.md#xa.append_label)(events, \*, id, label)                | Set or clear a user-supplied display label for a session.                           |
| `append_url_acquired`(events, \*, id, name[, ...])                                                  |                                                                                     |
| [`classify_death`](_autosummary/xa.html.md#xa.classify_death)(pane_kind, \*[, replaced, ...])     | Pick the most specific death reason from available signals.                         |
| [`overlays`](_autosummary/xa.html.md#xa.overlays)(events)                                   | Fold `labeled` / `hidden` events into `{id: {label, hidden}}`.                      |
| [`reconcile`](_autosummary/xa.html.md#xa.reconcile)(events, panes, live_sessions, \*[, ...]) | Emit `gone` events for archived sessions missing from `live_sessions`.              |
| [`records`](_autosummary/xa.html.md#xa.records)(events, panes)                             | Return per-session summaries, newest-first (by creation time).                      |
| [`default_hosts`](_autosummary/xa.html.md#xa.default_hosts)()                                    | The out-of-the-box registry: one local host, nothing else.                          |
| `default_config_path`()                                                                             |                                                                                     |
| [`load`](_autosummary/xa.html.md#xa.load)([path])                                       | Return `(settings, hosts_registry)` from a config file.                             |
| [`load_hosts`](_autosummary/xa.html.md#xa.load_hosts)([path])                                 | Shortcut: just the host registry.                                                   |

### Classes

| [`HistoryEntry`](_autosummary/xa.html.md#xa.HistoryEntry)(cwd, project, display, ...)        | One line from `~/.claude/history.jsonl`.                             |
|--------------------------------------------------------------------------------------------------|----------------------------------------------------------------------|
| [`TranscriptForensics`](_autosummary/xa.html.md#xa.TranscriptForensics)(transcript_path, ...)       | Postmortem facts extracted by walking a transcript from the end.     |
| [`TranscriptMeta`](_autosummary/xa.html.md#xa.TranscriptMeta)(path, session_id, cwd, ...)      | Summary of a transcript JSONL, cheap enough to compute for listings. |
| [`SpawnResult`](_autosummary/xa.html.md#xa.SpawnResult)(name, cwd, claude_pid, ...[, ...])  | What `spawn_session` / `resume_session` return to the caller.        |
| [`Session`](_autosummary/xa.html.md#xa.Session)(id, claude_session_id, ...[, ...])      | Canonical session record — valid across hosts and states.            |
| [`FileStore`](_autosummary/xa.html.md#xa.FileStore)(root, \*[, suffix])                   | Directory of files, accessed by key.                                 |
| [`JsonLinesStore`](_autosummary/xa.html.md#xa.JsonLinesStore)(path)                            | Append-only JSONL file with an `Iterable` reader.                    |
| [`ArchiveRecord`](_autosummary/xa.html.md#xa.ArchiveRecord)(id, name, cwd, created, url, ...) |                                                                      |
| [`HTTPHost`](_autosummary/xa.html.md#xa.HTTPHost)(name, \*, base_url[, auth, ...])       | Client for a remote `xa serve` instance.                             |
| [`Host`](_autosummary/xa.html.md#xa.Host)(\*args, \*\*kwargs)                        | Duck-typed interface every transport satisfies.                      |
| [`LocalHost`](_autosummary/xa.html.md#xa.LocalHost)([name, claude_home, claude_bin, ...]) | The machine `xa` is running on.                                      |
| [`SSHHost`](_autosummary/xa.html.md#xa.SSHHost)(name, \*, host[, user, ...])            | Transcripts via rsync; actions via ssh exec.                         |
| [`Settings`](_autosummary/xa.html.md#xa.Settings)(cache_dir[, stale_threshold_sec, ...]) |                                                                      |

### *class* xa.ArchiveRecord(id, name, cwd, created, url, gone, gone_detected, gone_reason, pane_log_bytes, claude_session_id, forensics, label=None, hidden=False)

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

### *class* xa.FileStore(root, , suffix='')

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

Directory of files, accessed by key.

Values are `bytes`. Keys must match `[A-Za-z0-9_.-]+` — this
rejects path traversal attempts like `../etc/passwd`.

#### path_for(key)

Public path accessor (for callers that need to hand the path to tmux).

* **Return type:**
  [`Path`](https://docs.python.org/3/library/pathlib.html#pathlib.Path)

### *class* xa.HTTPHost(name, , base_url, auth=None, username=None, password=None, token=None, timeout=30.0)

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

Client for a remote `xa serve` instance.

#### sync(, force=False)

HTTP sessions are fetched fresh on each listing — no separate sync.

* **Return type:**
  [`None`](https://docs.python.org/3/builtins/constants.html#None)

### *class* xa.HistoryEntry(cwd, project, display, pasted_contents)

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

One line from `~/.claude/history.jsonl`.

### *class* xa.Host(\*args, \*\*kwargs)

Bases: [`Protocol`](https://docs.python.org/3/library/typing.html#typing.Protocol)

Duck-typed interface every transport satisfies.

### *class* xa.JsonLinesStore(path)

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

Append-only JSONL file with an `Iterable` reader.

```pycon
>>> import tempfile, pathlib
>>> with tempfile.TemporaryDirectory() as td:
...     s = JsonLinesStore(pathlib.Path(td) / 'log.jsonl')
...     s.append({'a': 1})
...     s.append({'b': 2})
...     list(s) == [{'a': 1}, {'b': 2}]
True
```

### *class* xa.LocalHost(name='local', , claude_home=PosixPath('/home/runner/.claude'), claude_bin='claude', tmux_bin='tmux', alive_predicate=None)

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

The machine `xa` is running on.

#### sync(, force=False)

No-op — local has nothing to sync.

* **Return type:**
  [`None`](https://docs.python.org/3/builtins/constants.html#None)

### *class* xa.SSHHost(name, , host, user=None, remote_claude_home='~/.claude', cache_dir=PosixPath('/home/runner/.cache/xa/remotes'), stale_threshold_sec=3600, claude_bin='claude', tmux_bin='tmux', ssh_bin='ssh', rsync_bin='rsync')

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

Transcripts via rsync; actions via ssh exec.

* **Parameters:**
  * **name** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Logical name used in `Session.host` and elsewhere.
  * **host** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – SSH hostname / alias. Matches cc-sessions: either an
    `~/.ssh/config` alias (`devbox`) or a raw host (`1.2.3.4`).
  * **user** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]) – Optional SSH user for raw hosts.
  * **remote_claude_home** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Remote path to `~/.claude/`. Defaults to `~/.claude` which
    resolves relative to the SSH user’s home on the remote side.
  * **cache_dir** ([`Path`](https://docs.python.org/3/library/pathlib.html#pathlib.Path)) – Where to stage the rsync’d tree locally.
  * **stale_threshold_sec** ([`int`](https://docs.python.org/3/builtins/functions.html#int)) – Re-sync when the cached copy is older than this. `0` means
    always sync.

#### spawn(name, , cwd, \*\*opts)

Spawn `tmux new-session -d 's <name>' 'cd <cwd> && exec claude'` over SSH.

URL detection is left to the caller’s next [`sync()`](_autosummary/xa.html.md#xa.SSHHost.sync) + listing —
we don’t round-trip waiting for the bridge URL here (that would
hold an SSH connection open for up to 2 minutes).

* **Return type:**
  [`SpawnResult`](_autosummary/xa.claude_cli.html.md#xa.claude_cli.SpawnResult)

#### sync(, force=False)

Pull `<remote_claude_home>/projects/` and `/sessions/` into the cache.

Non-existent remote directories are tolerated (rsync returns 23).

* **Return type:**
  [`None`](https://docs.python.org/3/builtins/constants.html#None)

### *class* xa.Session(id, claude_session_id, bridge_session_id, host, cwd, project_slug, state, live_pid, tmux_name, name, summary, first_user_message, turn_count, forked_from, created, modified, url, url_source, transcript_path, pre_first_turn=False, attention=None, attention_hint=None, tmux_pane=None, pane_provider=None, pane_ref=None)

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

Canonical session record — valid across hosts and states.

Fields that don’t apply to a given state are `None`. Discovery
functions return fresh instances; callers should treat it as
immutable.

#### *property* pane_address *: [Optional](https://docs.python.org/3/library/typing.html#typing.Optional)[[PaneAddress](_autosummary/xa.panes.html.md#xa.panes.PaneAddress)]*

Where this session’s pane is, or `None` (a session with no terminal).

### *class* xa.Settings(cache_dir, stale_threshold_sec=3600, claude_bin='claude', tmux_bin='tmux')

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

### *class* xa.SpawnResult(name, cwd, claude_pid, claude_session_id, bridge_session_id, url, url_source, warning, attention=None)

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

What `spawn_session` / `resume_session` return to the caller.

### *class* xa.TranscriptForensics(transcript_path, line_count, last_tool_name, last_tool_command, last_tool_exit_code, last_tool_result_tail, final_assistant_text, user_interrupted)

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

Postmortem facts extracted by walking a transcript from the end.

`user_interrupted` is the raw marker presence — it is **ambiguous**
(also fires on phone-standby bridge drops), so do not derive user intent
from it alone. Callers should corroborate against pane-log tails.

### *class* xa.TranscriptMeta(path, session_id, cwd, project_slug, summary, custom_title, first_user_message, turn_count, forked_from, created, modified, size_bytes)

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

Summary of a transcript JSONL, cheap enough to compute for listings.

### xa.append_hidden(events, , id, hidden)

Mark an archived session as hidden (or un-hide it).

* **Return type:**
  [`None`](https://docs.python.org/3/builtins/constants.html#None)

### xa.append_label(events, , id, label)

Set or clear a user-supplied display label for a session.

`id` can be an archive id, a tmux session name, or a
`claude_session_id` — whatever key the caller will use to look it
up later. Empty-string or `None` label clears any prior label.

* **Return type:**
  [`None`](https://docs.python.org/3/builtins/constants.html#None)

### xa.classify_death(pane_kind, , replaced=False, forensics=None, oom_markers=())

Pick the most specific death reason from available signals.

`oom_markers` is the tuple of OOM-shaped strings observed in the
pane tail (see `_OOM_PANE_MARKERS`). When the last tool exited
with 137 and at least one marker is present, we promote the verdict
to `oom_killed` — that pair is the strongest single signal we can
get without reading kernel logs (which would need root and is not
portable).

* **Return type:**
  [`Literal`](https://docs.python.org/3/library/typing.html#typing.Literal)[`'clean_exit'`, `'abrupt'`, `'interrupted'`, `'tool_crash'`, `'oom_killed'`, `'replaced'`, `'missing'`]

### xa.default_events_store(state_dir=PosixPath('/home/runner/.xa'))

The event log at `<state_dir>/events.jsonl`.

* **Return type:**
  [`JsonLinesStore`](_autosummary/xa.store.html.md#xa.store.JsonLinesStore)

### xa.default_hosts()

The out-of-the-box registry: one local host, nothing else.

* **Return type:**
  [`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`Host`](_autosummary/xa.hosts.html.md#xa.hosts.Host)]

### xa.default_pane_store(state_dir=PosixPath('/home/runner/.xa'))

Per-session pane logs at `<state_dir>/panes/<id>.log`.

* **Return type:**
  [`FileStore`](_autosummary/xa.store.html.md#xa.store.FileStore)

### xa.encode_project_slug(cwd)

Encode a cwd into the `~/.claude/projects/` slug form.

Claude Code turns every character that is not a letter, digit or `-` into
`-` (`_` and `.` included), not only `/`.

```pycon
>>> encode_project_slug('/root/py/proj/tt/glossa')
'-root-py-proj-tt-glossa'
>>> encode_project_slug('/p/i/_zodals/tw_platform.v2')
'-p-i--zodals-tw-platform-v2'
>>> encode_project_slug('/')
'-'
```

* **Return type:**
  [`str`](https://docs.python.org/3/builtins/stdtypes.html#str)

### xa.get_session(session_id, , hosts=None, claude_home=None)

Find one session by full ID or unique prefix.

Raises `LookupError` if the prefix is ambiguous.

* **Return type:**
  [`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`Session`](_autosummary/xa.sessions.html.md#xa.sessions.Session)]

### xa.history_iter(, claude_home=PosixPath('/home/runner/.claude'))

Yield entries from `~/.claude/history.jsonl` in file order (oldest first).

Useful for cross-project full-text prompt search without loading
every transcript.

* **Return type:**
  [`Iterator`](https://docs.python.org/3/library/typing.html#typing.Iterator)[[`HistoryEntry`](_autosummary/xa.claude_fs.html.md#xa.claude_fs.HistoryEntry)]

### xa.iter_ephemeral_sessions(, claude_home=PosixPath('/home/runner/.claude'))

Yield all live ephemeral session dicts.

A session file disappears when claude exits, so this reflects
momentary state only. NB: claude deletes the file on *clean* exit
only — a crash / SIGKILL / reboot leaves a stale file behind, so
callers who care about actual liveness must validate each dict with
`ephemeral_session_alive()` (or an equivalent predicate).

* **Return type:**
  [`Iterator`](https://docs.python.org/3/library/typing.html#typing.Iterator)[[`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict)]

### xa.iter_local_sessions(, claude_home=PosixPath('/home/runner/.claude'), project_slug=None, include_live=True, tmux_bin=None)

Legacy local-only iterator.

Retained for backward compatibility and because some tests construct
sessions directly from a fake `~/.claude/`. Wraps a fresh
[`LocalHost`](_autosummary/xa.html.md#xa.LocalHost).

* **Return type:**
  [`Iterator`](https://docs.python.org/3/library/typing.html#typing.Iterator)[[`Session`](_autosummary/xa.sessions.html.md#xa.sessions.Session)]

### xa.iter_project_slugs(, claude_home=PosixPath('/home/runner/.claude'))

Yield slugs (directory names) under `~/.claude/projects/`.

* **Return type:**
  [`Iterator`](https://docs.python.org/3/library/typing.html#typing.Iterator)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]

### xa.iter_transcript_events(path)

Yield every event from a transcript JSONL.

Lines that fail to parse are silently skipped — transcripts are
append-only on a live process, so the tail can be partial.

* **Return type:**
  [`Iterator`](https://docs.python.org/3/library/typing.html#typing.Iterator)[[`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict)]

### xa.iter_transcript_files(, claude_home=PosixPath('/home/runner/.claude'), project_slug=None)

Yield transcript JSONL paths, optionally restricted to one project.

Only files whose stem is a valid UUID are yielded — this filters out
the `memory/` subfolder and other non-session artefacts Claude Code
stores alongside transcripts.

* **Return type:**
  [`Iterator`](https://docs.python.org/3/library/typing.html#typing.Iterator)[[`Path`](https://docs.python.org/3/library/pathlib.html#pathlib.Path)]

### xa.kill_session(session, , hosts=None)

Kill a live `Session`, scoped to what actually belongs to it.

Kills the backing tmux session only when it is *dedicated* to this
claude (single pane, claude verified in it) — a claude living in one
window of a shared multi-window workspace must not take the whole
workspace down, so there we SIGTERM the identity-verified pid
instead. Remote hosts keep the name-kill contract (their server
applies its own scoping). Returns a short description of what was
killed (e.g. `"tmux:mysess"` / `"pid:1234"`).

* **Return type:**
  [`str`](https://docs.python.org/3/builtins/stdtypes.html#str)

### xa.list_sessions(, hosts=None, project=None, include_forks=True, include_live=True, state=None, limit=None, claude_home=None, tmux_bin=None)

Return sessions sorted by recency (live first, then newest-modified).

When `hosts` is `None` we default to a single [`LocalHost`](_autosummary/xa.html.md#xa.LocalHost).
If `claude_home` or `tmux_bin` are given, they’re forwarded into
that default [`LocalHost`](_autosummary/xa.html.md#xa.LocalHost) — handy for fixture-based tests.

Filters:

- `project` — substring match against `cwd` (case-insensitive)
- `include_forks=False` — drop sessions with a `forked_from`
- `include_live=False` — skip live discovery (per host)
- `state` — one of `"live"` / `"archived"` / `"transcript_only"`

* **Return type:**
  [`list`](https://docs.python.org/3/builtins/stdtypes.html#list)[[`Session`](_autosummary/xa.sessions.html.md#xa.sessions.Session)]

### xa.load(path=None)

Return `(settings, hosts_registry)` from a config file.

Missing file → `(defaults, {"local": LocalHost()})`.

* **Return type:**
  [`tuple`](https://docs.python.org/3/builtins/stdtypes.html#tuple)[[`Settings`](_autosummary/xa.config.html.md#xa.config.Settings), [`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict)]

### xa.load_hosts(path=None)

Shortcut: just the host registry.

* **Return type:**
  [`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict)

### xa.overlays(events)

Fold `labeled` / `hidden` events into `{id: {label, hidden}}`.

Later events win. Useful when rendering live sessions too — callers
look up by whatever id they know (archive id, claude_session_id,
tmux name) and apply the overlay if present.

* **Return type:**
  [`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict)]

### xa.parse_project_slug(slug)

Decode a `~/.claude/projects/` slug back to a cwd.

```pycon
>>> parse_project_slug('-root-py-proj-tt-glossa')
'/root/py/proj/tt/glossa'
>>> parse_project_slug('-Users-thorwhalen-tw-server')
'/Users/thorwhalen/tw/server'
```

NB: This transform is lossy — a cwd with literal `-` in segment names
round-trips to a different slug. Claude Code itself has the same
limitation, so we accept it.

* **Return type:**
  [`str`](https://docs.python.org/3/builtins/stdtypes.html#str)

### xa.read_ephemeral_session(pid, , claude_home=PosixPath('/home/runner/.claude'))

Read the per-process session file for `pid` if present.

* **Return type:**
  [`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict)]

### xa.reconcile(events, panes, live_sessions, , claude_home=PosixPath('/home/runner/.claude'))

Emit `gone` events for archived sessions missing from `live_sessions`.

Returns the list of freshly-emitted events (handy for tests). Idempotent:
calling twice with the same live list produces no new events the
second time.

* **Return type:**
  [`list`](https://docs.python.org/3/builtins/stdtypes.html#list)[[`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict)]

### xa.records(events, panes)

Return per-session summaries, newest-first (by creation time).

* **Return type:**
  [`list`](https://docs.python.org/3/builtins/stdtypes.html#list)[[`ArchiveRecord`](_autosummary/xa.archive.html.md#xa.archive.ArchiveRecord)]

### xa.resolve_bridge_url(session_name, , claude_home=PosixPath('/home/runner/.claude'), tmux_bin='tmux', scrape_lines=400, panes=None)

Return `(url, source)` for a live claude session hosted in a pane.

Primary path: find the claude descendant pid → read
`~/.claude/sessions/<pid>.json` → take `bridgeSessionId`.
Fallback: regex-scrape `capture-pane` output for the full URL.

* **Return type:**
  [`tuple`](https://docs.python.org/3/builtins/stdtypes.html#tuple)[[`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)], [`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`Literal`](https://docs.python.org/3/library/typing.html#typing.Literal)[`'session_file'`, `'pane_capture'`]]]

### xa.resume(session, , cwd=None, name=None, hosts=None, \*\*opts)

Resume a transcript / archived session on its originating host, as it was launched.

Whatever the caller leaves unset comes from the transcript
(`launch_opts()`): the cwd it was started in, its model when that differs
from the account default’s family, and its permission mode, so a session
started with `--dangerously-skip-permissions` comes back with it.
`permission_mode=''` asks for claude’s default explicitly. When a launch
fact had to be dropped (bypass refused to root), the result’s `warning`
says so.

Only for a local host: a remote one gets exactly what the caller set, and
its own xa reads its own transcript the same way.

* **Return type:**
  [`SpawnResult`](_autosummary/xa.claude_cli.html.md#xa.claude_cli.SpawnResult)

### xa.resume_session(claude_session_id, , cwd, name=None, claude_bin='claude', claude_home=PosixPath('/home/runner/.claude'), tmux_bin='tmux', url_timeout_sec=120.0, auto_remote_control=True, model=None, effort=None, permission_mode=None, allow_bypass=False, pane_log_path=None, archive_store=None, pane_store=None, archive_id=None, telemetry=None)

Launch `claude --resume <id>` in a new detached tmux session.

A user-supplied `name` is also passed to `claude --name` (renaming
the resumed session’s display name); the auto-generated fallback name
is tmux-only so a resume never clobbers the session’s existing name.

* **Return type:**
  [`SpawnResult`](_autosummary/xa.claude_cli.html.md#xa.claude_cli.SpawnResult)

### xa.spawn_session(name, , cwd, claude_bin='claude', claude_home=PosixPath('/home/runner/.claude'), tmux_bin='tmux', url_timeout_sec=120.0, auto_remote_control=True, model=None, effort=None, permission_mode=None, pane_log_path=None, archive_store=None, pane_store=None, archive_id=None, telemetry=None)

Create a detached tmux session running `claude` in `cwd`.

Waits up to `url_timeout_sec` for the bridge URL to appear, dismissing
the “trust this folder” prompt and enabling remote control (via the
`--remote-control` flag on modern claude binaries, or the TUI
handshake on older ones). The session name is also passed to
`claude --name` so the Claude-side display name matches; `model`
and `effort` become per-session `--model` / `--effort` flags.

If `archive_store` (and optionally `pane_store`) are given, emits
`created` + `url_acquired` events to the archive and pipes the pane
output to a file under `pane_store`.

Services that want an immediate return should call
`prepare_spawn()` and run `complete_spawn()` in the background
instead — this function is simply the composition of the two.

* **Return type:**
  [`SpawnResult`](_autosummary/xa.claude_cli.html.md#xa.claude_cli.SpawnResult)

### xa.transcript_forensics(path)

Extract postmortem-relevant facts from the tail of a transcript.

Walks from the *end* of the file so we find the most recent
`tool_use` / `tool_result` / assistant `text` without reparsing
the whole transcript.

* **Return type:**
  [`TranscriptForensics`](_autosummary/xa.claude_fs.html.md#xa.claude_fs.TranscriptForensics)

### xa.transcript_metadata(path)

Summarise a transcript without holding it all in memory.

Walks forward, counting turns and capturing the first user message /
summary / custom title / fork pointer / cwd / sessionId. Stops reading
content fields once it has what it needs, but still counts turns to
the end. For very large transcripts, callers who only need counts
should use `iter_transcript_events` directly.

* **Return type:**
  [`TranscriptMeta`](_autosummary/xa.claude_fs.html.md#xa.claude_fs.TranscriptMeta)

### xa.transcript_path(cwd, session_id, , claude_home=PosixPath('/home/runner/.claude'))

Return the transcript path for `(cwd, session_id)` if it exists.

```pycon
>>> from pathlib import Path
>>> import tempfile
>>> with tempfile.TemporaryDirectory() as td:
...     home = Path(td)
...     (home / 'projects' / '-foo-bar').mkdir(parents=True)
...     f = home / 'projects' / '-foo-bar' / 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee.jsonl'
...     _ = f.write_text('')
...     p = transcript_path('/foo/bar', 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee', claude_home=home)
...     p == f
True
```

* **Return type:**
  [`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`Path`](https://docs.python.org/3/library/pathlib.html#pathlib.Path)]

### Modules

| [`archive`](_autosummary/xa.archive.html.md#module-xa.archive)       | Postmortem archive of Claude Code sessions spawned by `xa`.                                         |
|----------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------|
| [`claude_cli`](_autosummary/xa.claude_cli.html.md#module-xa.claude_cli) | Spawn, resume, and URL-resolve Claude Code sessions.                                                |
| [`claude_env`](_autosummary/xa.claude_env.html.md#module-xa.claude_env) | The environment and flags a fresh `claude` process starts with: account and permissions.            |
| [`claude_fs`](_autosummary/xa.claude_fs.html.md#module-xa.claude_fs)   | Pure filesystem view of `~/.claude/`.                                                               |
| [`cli`](_autosummary/xa.cli.html.md#module-xa.cli)               | Command-line interface for `xa`.                                                                    |
| [`config`](_autosummary/xa.config.html.md#module-xa.config)         | TOML config loader for `xa`.                                                                        |
| [`hosts`](_autosummary/xa.hosts.html.md#module-xa.hosts)           | Host abstraction — local, SSH, HTTP backends.                                                       |
| [`panes`](_autosummary/xa.panes.html.md#module-xa.panes)           | Pane providers: where a session's terminal lives (tmux on a server, iTerm on a Mac).                |
| [`push`](_autosummary/xa.push.html.md#module-xa.push)             | `xa push`: mirror this machine's live sessions into another host's xa cache.                        |
| [`recovery`](_autosummary/xa.recovery.html.md#module-xa.recovery)     | Bring back the sessions a shutdown killed, each as it was launched.                                 |
| [`revive`](_autosummary/xa.revive.html.md#module-xa.revive)         | Detect — and reconnect — Claude Code panes whose Remote Control dropped.                            |
| [`service`](_autosummary/xa.service.html.md#module-xa.service)       | FastAPI service for `xa`.                                                                           |
| [`sessions`](_autosummary/xa.sessions.html.md#module-xa.sessions)     | The unified `Session` domain model and multi-host discovery.                                        |
| [`store`](_autosummary/xa.store.html.md#module-xa.store)           | Minimal key-value and append-log storage.                                                           |
| [`telemetry`](_autosummary/xa.telemetry.html.md#module-xa.telemetry)   | Named telemetry profiles: where a session's OTLP trace export goes, and where its credentials live. |
| [`tmux`](_autosummary/xa.tmux.html.md#module-xa.tmux)             | Pure tmux wrappers.                                                                                 |


# _autosummary/xa.panes.html.md

# xa.panes

Pane providers: where a session’s terminal lives (tmux on a server, iTerm on a Mac).

Everything xa does with a session’s terminal is four verbs: **create** a pane running a
command, **capture** its text, **address** it later, **tear it down**. A
[`PaneProvider`](_autosummary/xa.panes.html.md#xa.panes.PaneProvider) is that, and a [`PaneAddress`](_autosummary/xa.panes.html.md#xa.panes.PaneAddress) (`provider` + `ref`) is the
provider-neutral way to name a pane, so `Session` need not carry tmux-shaped fields.

- [`TmuxPanes`](_autosummary/xa.panes.html.md#xa.panes.TmuxPanes): the default; a thin layer over [`xa.tmux`](_autosummary/xa.tmux.html.md#module-xa.tmux). Its `ref` is the
  tmux session name or a full pane ref (`session:@window.%pane`). Panes survive
  disconnection.
- [`ITermPanes`](_autosummary/xa.panes.html.md#xa.panes.ITermPanes): an iTerm2 tab on a Mac, driven through an injected `osascript`
  runner. Its `ref` is the iTerm session id, valid while iTerm runs. Every value
  reaches AppleScript through `on run argv`, never spliced into the script text, so a
  directory or name containing a quote cannot break out.

```pycon
>>> TmuxPanes().address("work").ref, TmuxPanes().address("work").provider
('work', 'tmux')
>>> str(PaneAddress("iterm", "ABC-1"))
'iterm:ABC-1'
```

### Module Attributes

| [`Runner`](_autosummary/xa.panes.html.md#xa.panes.Runner)         | runs AppleScript with `args` as `argv`.                                                                                                                                                                                               |
|-----------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [`NO_GUI_SESSION`](_autosummary/xa.panes.html.md#xa.panes.NO_GUI_SESSION) | What `osascript` says when the caller is outside the GUI's launchd namespace (an SSH login): only then is the `launchctl asuser` retry made, so a failure that already did something (a tab opened, then an error) is never repeated. |
| [`PROVIDERS`](_autosummary/xa.panes.html.md#xa.panes.PROVIDERS)      | Provider name -> factory (keyword arguments are the provider's own options).                                                                                                                                                          |

### Functions

| [`osascript_runner`](_autosummary/xa.panes.html.md#xa.panes.osascript_runner)(\*[, run, uid, osascript, ...])   | A [`Runner`](_autosummary/xa.panes.html.md#xa.panes.Runner) for `osascript`: directly first, and through `launchctl asuser <uid>` (which needs root) only when the direct call says the caller has no GUI session ([`NO_GUI_SESSION`](_autosummary/xa.panes.html.md#xa.panes.NO_GUI_SESSION)).   |
|-----------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [`pane_provider`](_autosummary/xa.panes.html.md#xa.panes.pane_provider)([name])                              | The provider called `name` (`tmux` or `iterm`), built with `options`.                                                                                                                                                                                                                |

### Classes

| [`ITermPanes`](_autosummary/xa.panes.html.md#xa.panes.ITermPanes)(\*[, profile, run, known_profiles, ps])   | iTerm2 tabs on a Mac.                                                                                                          |
|-------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------|
| [`PaneAddress`](_autosummary/xa.panes.html.md#xa.panes.PaneAddress)(provider, ref)                           | Provider-neutral name of one pane: which provider, and its own reference.                                                      |
| [`PaneProvider`](_autosummary/xa.panes.html.md#xa.panes.PaneProvider)(\*args, \*\*kwargs)                     | Where panes live.                                                                                                              |
| [`TmuxPanes`](_autosummary/xa.panes.html.md#xa.panes.TmuxPanes)(\*[, binary])                              | tmux panes, through [`xa.tmux`](_autosummary/xa.tmux.html.md#module-xa.tmux) (`binary` is the tmux executable). |

### Exceptions

| [`PaneUnsupported`](_autosummary/xa.panes.html.md#xa.panes.PaneUnsupported)   | The provider cannot do this (e.g. stream a pane to a file).   |
|--------------------------------------------------------------------|---------------------------------------------------------------|

### *class* xa.panes.ITermPanes(, profile='Default', run=None, known_profiles=None, ps=None)

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

iTerm2 tabs on a Mac. `run` is the AppleScript runner (default:
[`osascript_runner()`](_autosummary/xa.panes.html.md#xa.panes.osascript_runner)); `known_profiles` optionally lists the profile names
iTerm has, so a typo is an error before the GUI is touched (a typo otherwise opens
a Default tab and looks like it worked).

#### pane_pids(ref)

The pids on the tab’s tty (its login shell and what it runs), found through
iTerm’s `tty` and `ps -t`; `[]` when iTerm no longer has the tab.

* **Return type:**
  [`list`](https://docs.python.org/3/builtins/stdtypes.html#list)[[`int`](https://docs.python.org/3/builtins/functions.html#int)]

### xa.panes.NO_GUI_SESSION *= ('-609', '-600', 'Connection is invalid')*

What `osascript` says when the caller is outside the GUI’s launchd namespace
(an SSH login): only then is the `launchctl asuser` retry made, so a failure that
already did something (a tab opened, then an error) is never repeated.

### xa.panes.PROVIDERS *: [Mapping](https://docs.python.org/3/library/collections.abc.html#collections.abc.Mapping)[[str](https://docs.python.org/3/builtins/stdtypes.html#str), [Callable](https://docs.python.org/3/library/collections.abc.html#collections.abc.Callable)[..., [PaneProvider](_autosummary/xa.panes.html.md#xa.panes.PaneProvider)]]* *= {'iterm': <class 'xa.panes.ITermPanes'>, 'tmux': <class 'xa.panes.TmuxPanes'>}*

Provider name -> factory (keyword arguments are the provider’s own options).

### *class* xa.panes.PaneAddress(provider, ref)

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

Provider-neutral name of one pane: which provider, and its own reference.

### *class* xa.panes.PaneProvider(\*args, \*\*kwargs)

Bases: [`Protocol`](https://docs.python.org/3/library/typing.html#typing.Protocol)

Where panes live. Implementations: [`TmuxPanes`](_autosummary/xa.panes.html.md#xa.panes.TmuxPanes), [`ITermPanes`](_autosummary/xa.panes.html.md#xa.panes.ITermPanes).

#### address(ref)

The [`PaneAddress`](_autosummary/xa.panes.html.md#xa.panes.PaneAddress) of a pane of this provider.

* **Return type:**
  [`PaneAddress`](_autosummary/xa.panes.html.md#xa.panes.PaneAddress)

#### capture(ref, , lines=200)

The last `lines` of the pane’s text, or “” when it cannot be read.

* **Return type:**
  [`str`](https://docs.python.org/3/builtins/stdtypes.html#str)

#### create(name, , command, cwd=None)

Start a pane named `name` running the shell `command`; return its address.

* **Return type:**
  [`PaneAddress`](_autosummary/xa.panes.html.md#xa.panes.PaneAddress)

#### kill(ref)

Tear the pane down.

* **Return type:**
  [`None`](https://docs.python.org/3/builtins/constants.html#None)

#### pane_pids(ref)

The pids of the programs running in the pane (a root of each process tree; the
claude process is one of them or below one). `[]` when the pane is gone.

* **Return type:**
  [`list`](https://docs.python.org/3/builtins/stdtypes.html#list)[[`int`](https://docs.python.org/3/builtins/functions.html#int)]

#### stream_to_file(ref, path)

Append the pane’s output to `path` as it appears (may raise
[`PaneUnsupported`](_autosummary/xa.panes.html.md#xa.panes.PaneUnsupported)).

* **Return type:**
  [`None`](https://docs.python.org/3/builtins/constants.html#None)

### *exception* xa.panes.PaneUnsupported

Bases: [`RuntimeError`](https://docs.python.org/3/builtins/exceptions.html#RuntimeError)

The provider cannot do this (e.g. stream a pane to a file).

### xa.panes.Runner

runs AppleScript with `args` as `argv`.

* **Type:**
  `Runner(script, args) -> stdout`

alias of [`Callable`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Callable)[[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`Sequence`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]], [`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]

### *class* xa.panes.TmuxPanes(, binary='tmux')

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

tmux panes, through [`xa.tmux`](_autosummary/xa.tmux.html.md#module-xa.tmux) (`binary` is the tmux executable).

#### kill(ref)

A bare session name closes that session; a pane ref
(`session:@window.%pane`) closes only that pane, never the workspace.

* **Return type:**
  [`None`](https://docs.python.org/3/builtins/constants.html#None)

### xa.panes.osascript_runner(\*, run=<function run>, uid=None, osascript='osascript', timeout=30.0)

A [`Runner`](_autosummary/xa.panes.html.md#xa.panes.Runner) for `osascript`: directly first, and through
`launchctl asuser <uid>` (which needs root) only when the direct call says the
caller has no GUI session ([`NO_GUI_SESSION`](_autosummary/xa.panes.html.md#xa.panes.NO_GUI_SESSION)). `run` is the subprocess seam.

* **Return type:**
  [`Callable`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Callable)[[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`Sequence`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]], [`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]

### xa.panes.pane_provider(name='tmux', \*\*options)

The provider called `name` (`tmux` or `iterm`), built with `options`.

```pycon
>>> pane_provider("tmux", binary="tmux").name
'tmux'
```

* **Return type:**
  [`PaneProvider`](_autosummary/xa.panes.html.md#xa.panes.PaneProvider)


# _autosummary/xa.push.html.md

# xa.push

`xa push`: mirror this machine’s live sessions into another host’s xa cache.

`xa sync` pulls a remote home down, which needs this machine to reach the other one. A
laptop behind NAT can reach a server but not the reverse, so the server cannot pull it.
`push` is the other direction: it writes a *mirror* of the local home into
`<host>:<cache_dir>/<as_name>/`, the same place the server’s own `xa sync` would put it:

- `sessions/`: the registry records whose process is alive here, and nothing else
  (`--delete`, so a session that ended disappears from the mirror);
- `projects/<slug>/<session-id>.jsonl`: the transcript of each of those sessions;
- `.mirrored-at`: a stamp, written last, whose mtime says when the mirror was complete.

A reader on the hub (crowsnest, a home with `liveness = "mirror"`) counts every record in
it as live while the stamp is fresh, so an idle session still shows and a machine that
stops pushing drops out. Transcripts of ended sessions are pruned on the hub after
`keep_days`.

### Module Attributes

| [`MIRROR_STAMP`](_autosummary/xa.push.html.md#xa.push.MIRROR_STAMP)      | The stamp's name.                                                                           |
|--------------------------------------------------------------------|---------------------------------------------------------------------------------------------|
| [`DFLT_REMOTE_CACHE`](_autosummary/xa.push.html.md#xa.push.DFLT_REMOTE_CACHE) | ssh and rsync both start there, and a quoted `~` would not be expanded by the remote shell. |

### Functions

| [`live_records`](_autosummary/xa.push.html.md#xa.push.live_records)(home, \*[, is_alive])                 | The registry records under `home` whose pid is alive, with their transcripts.                                               |
|-----------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------|
| [`push`](_autosummary/xa.push.html.md#xa.push.push)(host, \*, as_name[, home, remote_cache, ...]) | Mirror `home`'s live sessions to `host` (an [`SSHHost`](_autosummary/xa.hosts.ssh.html.md#xa.hosts.ssh.SSHHost)). |
| [`push_commands`](_autosummary/xa.push.html.md#xa.push.push_commands)(records, \*, home, target, ...)      | The commands one push runs, in order.                                                                                       |

### Classes

| [`LiveRecord`](_autosummary/xa.push.html.md#xa.push.LiveRecord)(record, transcript)   | One registry record whose process is alive here, and its transcript (if found).   |
|-----------------------------------------------------------------------------------|-----------------------------------------------------------------------------------|

### xa.push.DFLT_REMOTE_CACHE *= '.cache/xa/remotes'*

ssh and rsync both start there, and a quoted `~` would
not be expanded by the remote shell.

* **Type:**
  Relative to the remote home

### *class* xa.push.LiveRecord(record, transcript)

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

One registry record whose process is alive here, and its transcript (if found).

### xa.push.MIRROR_STAMP *= '.mirrored-at'*

The stamp’s name. crowsnest reads the same name (crowsnest.registry.MIRROR_STAMP).

### xa.push.live_records(home, \*, is_alive=<function \_pid_alive>)

The registry records under `home` whose pid is alive, with their transcripts.

* **Return type:**
  [`Iterator`](https://docs.python.org/3/library/typing.html#typing.Iterator)[[`LiveRecord`](_autosummary/xa.push.html.md#xa.push.LiveRecord)]

### xa.push.push(host, \*, as_name, home='~/.claude', remote_cache='.cache/xa/remotes', keep_days=7, run=<function run>, timeout=300.0)

Mirror `home`’s live sessions to `host` (an [`SSHHost`](_autosummary/xa.hosts.ssh.html.md#xa.hosts.ssh.SSHHost)).

Returns how many live sessions were pushed. Raises `RuntimeError` naming the step
that failed.

* **Return type:**
  [`int`](https://docs.python.org/3/builtins/functions.html#int)

### xa.push.push_commands(records, , home, target, dest, staging, keep_days=7, rsync_bin='rsync', ssh_bin='ssh')

The commands one push runs, in order. Pure apart from writing into `staging`.

Transcripts go first and the registry plus stamp last, so a fresh stamp always comes
with the transcripts its records name.

* **Return type:**
  [`list`](https://docs.python.org/3/builtins/stdtypes.html#list)[[`list`](https://docs.python.org/3/builtins/stdtypes.html#list)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]]


# _autosummary/xa.recovery.html.md

# xa.recovery

Bring back the sessions a shutdown killed, each as it was launched.

Two questions, answered from the transcripts alone (the processes are gone):

1. **Which sessions were alive at the last shutdown?** When a machine shuts
   down, every running claude writes a final `cost-state` entry on its way
   out, so its transcript’s last write lands within seconds of the shutdown.
   [`sessions_alive_at_shutdown()`](_autosummary/xa.recovery.html.md#xa.recovery.sessions_alive_at_shutdown) returns the transcripts whose last write
   > falls in `[shutdown - window, boot)`. The shutdown time comes from
   > `last` ([`last_shutdown_time()`](_autosummary/xa.recovery.html.md#xa.recovery.last_shutdown_time)), the boot time from the kernel
   > ([`boot_time()`](_autosummary/xa.recovery.html.md#xa.recovery.boot_time)), and the record counts only when it belongs to this
   > boot. Sessions resumed since then, running now, or already sitting in a tmux
   > pane started with `--resume <id>` are never candidates, so applying twice
   > resumes nothing twice. Headless runs (`claude -p`, the SDK) are skipped.
2. **How was each one launched?** [`xa.claude_fs.launch_facts()`](_autosummary/xa.claude_fs.html.md#xa.claude_fs.launch_facts) reads one transcript
   for what `claude --resume` needs in order to come back the same:
   - the **cwd**: the *first* `cwd` whose slug is the transcript’s project
     folder. A session that `cd`-ed elsewhere records later cwds too, and
     resuming in the last one puts it in the wrong folder (thorwhalen/xa#23);
   - the **permission mode**: the last one recorded, plus whether bypass was
     ever reached (only a session started with the bypass flag can reach it);
   - the **model** of the last assistant turn, pinned only when its family
     differs from the account default’s ([`xa.claude_fs.resume_model()`](_autosummary/xa.claude_fs.html.md#xa.claude_fs.resume_model)).

What a shutdown with no clean exit (a power cut, a kernel panic) leaves is not
covered: no process wrote anything at the moment it died, so there is nothing
to time it by.

### Module Attributes

| [`DFLT_WINDOW_SEC`](_autosummary/xa.recovery.html.md#xa.recovery.DFLT_WINDOW_SEC)   | How long before the shutdown record a session's last write may land and still count as "alive at shutdown".   |
|--------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------|

### Functions

| [`boot_time`](_autosummary/xa.recovery.html.md#xa.recovery.boot_time)(\*[, run])                               | Unix time the machine last booted, or `None` when it cannot be read.        |
|-----------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------|
| [`last_shutdown_time`](_autosummary/xa.recovery.html.md#xa.recovery.last_shutdown_time)(\*[, before, run])              | Unix time of the shutdown that preceded the current boot, or `None`.        |
| [`live_session_ids`](_autosummary/xa.recovery.html.md#xa.recovery.live_session_ids)(\*, claude_home[, tmux_bin])      | Session ids running right now: a live claude, or a tmux pane resuming them. |
| [`parse_last_stamp`](_autosummary/xa.recovery.html.md#xa.recovery.parse_last_stamp)(text, \*, before)                 | The first `Tue Nov 10 09:50`-style stamp in `text`, as unix time.           |
| [`resume_all`](_autosummary/xa.recovery.html.md#xa.recovery.resume_all)(candidates, \*[, claude_home, ...])     | Resume every candidate in its own tmux session, each as it was launched.    |
| [`sessions_alive_at_shutdown`](_autosummary/xa.recovery.html.md#xa.recovery.sessions_alive_at_shutdown)(\*[, claude_home, ...]) | The sessions of `claude_home` whose last write fell at the last shutdown.   |
| [`tmux_name_for`](_autosummary/xa.recovery.html.md#xa.recovery.tmux_name_for)(facts, \*[, taken])                  | A tmux session name for `facts`: its own name, sanitised, made unique.      |

### Classes

| [`Resumed`](_autosummary/xa.recovery.html.md#xa.recovery.Resumed)(facts, result[, skipped, warning])    | One candidate's outcome: a [`SpawnResult`](_autosummary/xa.claude_cli.html.md#xa.claude_cli.SpawnResult), or why not.   |
|------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------|
| [`ShutdownScan`](_autosummary/xa.recovery.html.md#xa.recovery.ShutdownScan)(candidates, shutdown, boot, ...) | The candidates, and the times they were picked by (for the dry run).                                                             |

### xa.recovery.DFLT_WINDOW_SEC *= 120.0*

How long before the shutdown record a session’s last write may land and
still count as “alive at shutdown”. `last` has minute resolution, so this
has to cover at least the minute it rounds down.

### *class* xa.recovery.Resumed(facts, result, skipped=None, warning=None)

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

One candidate’s outcome: a [`SpawnResult`](_autosummary/xa.claude_cli.html.md#xa.claude_cli.SpawnResult), or why not.

### *class* xa.recovery.ShutdownScan(candidates, shutdown, boot, anchor_source, lo, hi)

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

The candidates, and the times they were picked by (for the dry run).

### xa.recovery.boot_time(\*, run=<function \_run>)

Unix time the machine last booted, or `None` when it cannot be read.

`/proc/stat`’s `btime` on Linux, `sysctl kern.boottime` elsewhere.

* **Return type:**
  [`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`float`](https://docs.python.org/3/builtins/functions.html#float)]

### xa.recovery.last_shutdown_time(\*, before=None, run=<function \_run>)

Unix time of the shutdown that preceded the current boot, or `None`.

Read from `last` (minute resolution), newest record first: the current
boot’s `reboot` line, then its shutdown. A second `reboot` line before
any shutdown means this boot followed a crash (no clean shutdown), and an
older record must not stand in for it. `last -x reboot shutdown` on
Linux; macOS prints both kinds under `last reboot`.

* **Return type:**
  [`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`float`](https://docs.python.org/3/builtins/functions.html#float)]

### xa.recovery.live_session_ids(, claude_home, tmux_bin=None)

Session ids running right now: a live claude, or a tmux pane resuming them.

The pane scan covers a resume that has not written anything yet (it is
still at a trust or login prompt), which the session files cannot show.

* **Return type:**
  [`set`](https://docs.python.org/3/builtins/stdtypes.html#set)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]

### xa.recovery.parse_last_stamp(text, , before)

The first `Tue Nov 10 09:50`-style stamp in `text`, as unix time.

`last` prints no year, so the year is the latest one that puts the stamp
at or before `before` (local time).

```pycon
>>> import time as t
>>> before = t.mktime((2026, 11, 10, 10, 0, 0, 0, 0, -1))
>>> ts = parse_last_stamp('shutdown time   Tue Nov 10 09:50', before=before)
>>> t.localtime(ts)[:5]
(2026, 11, 10, 9, 50)
```

* **Return type:**
  [`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`float`](https://docs.python.org/3/builtins/functions.html#float)]

### xa.recovery.resume_all(candidates, , claude_home=PosixPath('/home/runner/.claude'), claude_bin=None, tmux_bin=None, url_timeout_sec=120.0, auto_remote_control=True, permission_mode=None, euid=None)

Resume every candidate in its own tmux session, each as it was launched.

All panes are launched first and only then waited on, so the whole batch
takes about one `url_timeout_sec`, not one per session. A pane that comes
up without a Remote Control URL gets the [`xa.revive`](_autosummary/xa.revive.html.md#module-xa.revive) verdict for what
it is showing (`needs_trust` for a folder the account has not trusted,
`needs_login`, …) in `result.attention`, rather than a hang.
`permission_mode` overrides every candidate’s recorded mode (`''`:
claude’s default).

* **Return type:**
  [`list`](https://docs.python.org/3/builtins/stdtypes.html#list)[[`Resumed`](_autosummary/xa.recovery.html.md#xa.recovery.Resumed)]

### xa.recovery.sessions_alive_at_shutdown(, claude_home=PosixPath('/home/runner/.claude'), window_sec=120.0, shutdown=None, boot=None, live_ids=None, tmux_bin=None)

The sessions of `claude_home` whose last write fell at the last shutdown.

The window is `[shutdown - window_sec, boot)`. With no shutdown record
for this boot (a crash, or `last` unreadable), the anchor is the latest
transcript write before boot instead, and the window is
`[anchor - window_sec, anchor]`: the dry run says which was used.
`shutdown` / `boot` / `live_ids` default to what this machine reports.
Sessions in `live_ids` (running now) and headless runs are never candidates.

* **Return type:**
  [`ShutdownScan`](_autosummary/xa.recovery.html.md#xa.recovery.ShutdownScan)

### xa.recovery.tmux_name_for(facts, , taken=())

A tmux session name for `facts`: its own name, sanitised, made unique.

```pycon
>>> f = LaunchFacts('0123456789', Path('t'), None, '', False, None, None, 'my session', None, 0.0)
>>> tmux_name_for(f), tmux_name_for(f, taken={'my-session'})
('my-session', 'my-session-2')
```

* **Return type:**
  [`str`](https://docs.python.org/3/builtins/stdtypes.html#str)


# _autosummary/xa.revive.html.md

# xa.revive

Detect — and reconnect — Claude Code panes whose Remote Control dropped.

Remote Control gives up on its own: after a few minutes of failed reconnects,
or roughly thirty minutes of failed presence heartbeats, it stops trying and
leaves the local session running but unreachable from claude.ai. The usual
cause is a network change (moving between networks, toggling a VPN) that
produces a transient HTTP 403 — the same change that clears it, usually
within a minute or two.

Two facts shape everything below, and both were verified rather than assumed:

- \*\*Two observables, and both were checked against a live session rather
  than assumed.\*\* The footer carries a `/rc` *pill* that is present while
  Remote Control is connected (`/rc`, or `/rc active` when verbose) and
  **disappears** when it is not — so the pill’s absence, not its presence,
  is what marks a dropped session. The ephemeral session file
  (`~/.claude/sessions/<pid>.json`) agrees from the other side: its
  `bridgeSessionId` is a real id while connected and `null` once it is
  not. The transcript JSONL never mentions Remote Control at all, so there
  is no third source.
- **\`\`tmux send-keys\`\` is the only way to act.** `/remote-control` is a
  built-in slash command; the CLI exposes no subcommand and no control
  request that reconnects a *running* session (checked against
  `claude --help` and `claude remote-control --help`, 2.1.251 — the only
  session-shaped verbs there are `agents`/`attach`/`logs`/`stop`/
  `rm`/`respawn`, all of which are about background agents).

The detection phrases in [`MARKERS`](_autosummary/xa.revive.html.md#xa.revive.MARKERS) are transcribed from the strings
embedded in the `claude` 2.1.251 binary, not guessed from screenshots.
They are data, and [`DEFAULT_RULES`](_autosummary/xa.revive.html.md#xa.revive.DEFAULT_RULES) is injectable, so a wording change
upstream is a one-line edit rather than a rewrite.

Four things this module refuses to do, each deliberate:

- **It never revives a session held elsewhere.** When a session was taken
  over or ended from another device, the TUI says so (WebSocket close code
  4090) and *omits* its “run /remote-control” advice. Sending the command
  > anyway would steal the session back from the user’s phone mid-sentence.

  [`HELD_ELSEWHERE`](_autosummary/xa.revive.html.md#xa.revive.HELD_ELSEWHERE) is therefore tested before [`RECONNECTABLE`](_autosummary/xa.revive.html.md#xa.revive.RECONNECTABLE)
  : and acting on it stays opt-in.
- **It never resends a prompt.** An API-stalled pane is reported and left
  alone: the fix there is a real model call that can duplicate work.
- **It never types into a pane waiting on a human.** A permission dialog or
  a `/login` prompt consumes keystrokes as *answers* — sending
  `/remote-control` into an open “Do you want to proceed?” selector would
  answer it. Those panes classify as [`NEEDS_HUMAN`](_autosummary/xa.revive.html.md#xa.revive.NEEDS_HUMAN) and are skipped.
- **It does nothing at all unless asked.** `apply=True` is explicit;
  every entry point is a dry run by default.

Typical use:

```default
from xa.revive import SessionPanes, revive

for action in revive(panes=SessionPanes()):      # dry run
    print(action.target, action.verdict, action.skipped)
```

Discovery does **not** enumerate tmux and guess which pane holds a claude.
It reads the live ephemeral session files, each of which records its own
pane as `"tmux": "session:@window.%pane"`, so the pane refs are exact and
`pane_current_command` never enters the decision. See [`local_panes()`](_autosummary/xa.revive.html.md#xa.revive.local_panes).

### Module Attributes

| [`NO_CLAUDE`](_autosummary/xa.revive.html.md#xa.revive.NO_CLAUDE)             | No claude process behind the pane — a shell prompt, or a session that died.                                                                                    |
|------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [`HELD_ELSEWHERE`](_autosummary/xa.revive.html.md#xa.revive.HELD_ELSEWHERE)        | Taken over or ended from another device.                                                                                                                       |
| [`CONNECTED`](_autosummary/xa.revive.html.md#xa.revive.CONNECTED)             | Remote Control is up.                                                                                                                                          |
| [`RECONNECTING`](_autosummary/xa.revive.html.md#xa.revive.RECONNECTING)          | Remote Control is retrying right now.                                                                                                                          |
| [`NEEDS_HUMAN`](_autosummary/xa.revive.html.md#xa.revive.NEEDS_HUMAN)           | Blocked on a human — an open permission dialog, or anything else that is eating keystrokes.                                                                    |
| [`NEEDS_LOGIN`](_autosummary/xa.revive.html.md#xa.revive.NEEDS_LOGIN)           | claude on this host is logged out.                                                                                                                             |
| [`NEEDS_TRUST`](_autosummary/xa.revive.html.md#xa.revive.NEEDS_TRUST)           | the workspace-trust prompt is open.                                                                                                                            |
| [`API_STALLED`](_autosummary/xa.revive.html.md#xa.revive.API_STALLED)           | The API call is wedged.                                                                                                                                        |
| [`SERVER_MODE`](_autosummary/xa.revive.html.md#xa.revive.SERVER_MODE)           | A `claude remote-control` *server* died.                                                                                                                       |
| [`RECONNECTABLE`](_autosummary/xa.revive.html.md#xa.revive.RECONNECTABLE)         | Dropped and recoverable — the one verdict [`revive()`](_autosummary/xa.revive.html.md#xa.revive.revive) acts on.                                                   |
| [`UNKNOWN`](_autosummary/xa.revive.html.md#xa.revive.UNKNOWN)               | The pane says nothing either way.                                                                                                                              |
| [`VERDICTS`](_autosummary/xa.revive.html.md#xa.revive.VERDICTS)              | Every verdict [`DEFAULT_RULES`](_autosummary/xa.revive.html.md#xa.revive.DEFAULT_RULES) can produce.                                                                      |
| [`BLOCKED_ON_HUMAN`](_autosummary/xa.revive.html.md#xa.revive.BLOCKED_ON_HUMAN)      | Verdicts that mean "a human must act on the host".                                                                                                             |
| [`ACTIONABLE`](_autosummary/xa.revive.html.md#xa.revive.ACTIONABLE)            | Verdicts [`revive()`](_autosummary/xa.revive.html.md#xa.revive.revive) will send `/remote-control` to.                                                             |
| [`MARKERS`](_autosummary/xa.revive.html.md#xa.revive.MARKERS)               | Substring markers per verdict.                                                                                                                                 |
| [`RC_PILL`](_autosummary/xa.revive.html.md#xa.revive.RC_PILL)               | The footer *pill*.                                                                                                                                             |
| [`DEFAULT_RULES`](_autosummary/xa.revive.html.md#xa.revive.DEFAULT_RULES)         | Ordered `(verdict, predicate)` pairs; **first match wins**.                                                                                                    |
| [`PROMPT_LINE`](_autosummary/xa.revive.html.md#xa.revive.PROMPT_LINE)           | the prompt glyph, then U+00A0, then whatever the user has typed. <br/><br/>```<br/>``<br/>```<br/><br/>> \`\` is the plain-ASCII rendering some terminals get. |
| [`TYPEABLE_STATUS`](_autosummary/xa.revive.html.md#xa.revive.TYPEABLE_STATUS)       | Statuses in which a keystroke is a *command*.                                                                                                                  |
| [`DFLT_MIN_INTERVAL_SEC`](_autosummary/xa.revive.html.md#xa.revive.DFLT_MIN_INTERVAL_SEC) | Long enough that a cron tick can never turn into a keystroke storm, short enough that a real network change is followed within one settling period.            |
| [`RECONNECT_KEYS`](_autosummary/xa.revive.html.md#xa.revive.RECONNECT_KEYS)        | The keystrokes that reconnect a REPL session.                                                                                                                  |
| [`REPORT_ORDER`](_autosummary/xa.revive.html.md#xa.revive.REPORT_ORDER)          | Verdicts worth a human's eye, in the order a report should present them.                                                                                       |
| [`DFLT_CHECK_TICKS`](_autosummary/xa.revive.html.md#xa.revive.DFLT_CHECK_TICKS)      | Consecutive ticks a pane must stay reconnectable before the check escalates.                                                                                   |

### Functions

| [`check`](_autosummary/xa.revive.html.md#xa.revive.check)(\*[, panes, store, ticks, actionable])      | Report-only revive check, meant for a timer: **sends nothing, ever.**                                        |
|----------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------|
| [`classify`](_autosummary/xa.revive.html.md#xa.revive.classify)(probe, \*[, rules])                      | Return the verdict for `probe`.                                                                              |
| [`evidence_for`](_autosummary/xa.revive.html.md#xa.revive.evidence_for)(probe, verdict, \*[, rules])         | The marker that earned `verdict`, for a report a human has to trust.                                         |
| [`format_actions`](_autosummary/xa.revive.html.md#xa.revive.format_actions)(actions)                           | One line per pane, most actionable first.                                                                    |
| [`has_live_claude`](_autosummary/xa.revive.html.md#xa.revive.has_live_claude)(ref)                              | Default relevance test: the recorded pid is a *claude* that still exists.                                    |
| [`hint_for`](_autosummary/xa.revive.html.md#xa.revive.hint_for)(verdict, \*[, tmux_name])                | Human fix-it line for a verdict, or `None` when there is nothing to say.                                     |
| [`local_panes`](_autosummary/xa.revive.html.md#xa.revive.local_panes)(\*[, claude_home])                    | Yield one [`PaneRef`](_autosummary/xa.revive.html.md#xa.revive.PaneRef) per live claude that records a tmux pane. |
| [`prompt_is_clear`](_autosummary/xa.revive.html.md#xa.revive.prompt_is_clear)(tail)                             | True when the pane's input line is empty and safe to type into.                                              |
| [`refusal_to_type`](_autosummary/xa.revive.html.md#xa.revive.refusal_to_type)(state)                            | Why typing into `state` would be unsafe, or `None` if it is fine.                                            |
| [`restart_server_mode`](_autosummary/xa.revive.html.md#xa.revive.restart_server_mode)(state, \*[, cwd, apply, ...]) | Restart a died `claude remote-control` server in its own directory.                                          |
| [`revive`](_autosummary/xa.revive.html.md#xa.revive.revive)(\*[, panes, apply, ...])                   | Reconnect every dropped pane.                                                                                |
| [`server_mode_command`](_autosummary/xa.revive.html.md#xa.revive.server_mode_command)(cwd)                          | Keystrokes that restart a Remote Control *server* in `cwd`.                                                  |

### Classes

| [`CheckResult`](_autosummary/xa.revive.html.md#xa.revive.CheckResult)(looked_at, streaks, escalate)         | One tick of [`check()`](_autosummary/xa.revive.html.md#xa.revive.check): every pane looked at, and the ones to escalate.   |
|----------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------|
| [`PaneRef`](_autosummary/xa.revive.html.md#xa.revive.PaneRef)(target[, host, claude_pid, cwd, ...])     | Identity of one candidate pane — everything known *without* reading it.                                                 |
| [`PaneState`](_autosummary/xa.revive.html.md#xa.revive.PaneState)(ref, tail, verdict[, evidence])         | A pane, as read and judged.                                                                                             |
| [`Probe`](_autosummary/xa.revive.html.md#xa.revive.Probe)(text[, ref])                                | The complete, pure input to a classification rule.                                                                      |
| [`RateGuard`](_autosummary/xa.revive.html.md#xa.revive.RateGuard)(\*[, store, min_interval_sec, clock])   | Refuses to touch the same pane twice inside `min_interval_sec`.                                                         |
| [`ReviveAction`](_autosummary/xa.revive.html.md#xa.revive.ReviveAction)(target, verdict[, keys, sent, ...])  | What was (or would be) done to one pane, and why.                                                                       |
| [`SessionPanes`](_autosummary/xa.revive.html.md#xa.revive.SessionPanes)(\*[, panes, is_relevant, tail, ...]) | Live view of the panes worth judging: `{tmux target: PaneState}`.                                                       |

### xa.revive.ACTIONABLE *= frozenset({'reconnectable'})*

Verdicts [`revive()`](_autosummary/xa.revive.html.md#xa.revive.revive) will send `/remote-control` to. `HELD_ELSEWHERE`
is deliberately absent — it is reachable only via `include_held_elsewhere`.

### xa.revive.API_STALLED *= 'api_stalled'*

The API call is wedged. Reported, never acted on (the fix is a new prompt).

### xa.revive.BLOCKED_ON_HUMAN *= frozenset({'needs_human', 'needs_login', 'needs_trust'})*

Verdicts that mean “a human must act on the host”. All are blocked on a
person, none are actionable by [`revive()`](_autosummary/xa.revive.html.md#xa.revive.revive), and each has a fix-it line
in [`hint_for()`](_autosummary/xa.revive.html.md#xa.revive.hint_for).

### xa.revive.CONNECTED *= 'connected'*

Remote Control is up. Nothing to do.

### *class* xa.revive.CheckResult(looked_at, streaks, escalate)

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

One tick of [`check()`](_autosummary/xa.revive.html.md#xa.revive.check): every pane looked at, and the ones to escalate.

### xa.revive.DEFAULT_RULES *: [tuple](https://docs.python.org/3/builtins/stdtypes.html#tuple)[[tuple](https://docs.python.org/3/builtins/stdtypes.html#tuple)[[str](https://docs.python.org/3/builtins/stdtypes.html#str), [Callable](https://docs.python.org/3/library/typing.html#typing.Callable)[[[Probe](_autosummary/xa.revive.html.md#xa.revive.Probe)], [bool](https://docs.python.org/3/builtins/functions.html#bool)]], ...]* *= (('no_claude', <function \_no_claude>), ('held_elsewhere', <function \_any_of.<locals>._pred>), ('reconnecting', <function \_any_of.<locals>._pred>), ('connected', <function \_pill_present>), ('connected', <function \_any_of.<locals>._pred>), ('needs_login', <function \_any_of.<locals>._pred>), ('needs_trust', <function \_any_of.<locals>._pred>), ('needs_human', <function \_any_of.<locals>._pred>), ('api_stalled', <function \_any_of.<locals>._pred>), ('server_mode', <function \_any_of.<locals>._pred>), ('reconnectable', <function \_any_of.<locals>._pred>), ('reconnectable', <function \_bridge_down>), ('unknown', <function \_always>))*

Ordered `(verdict, predicate)` pairs; **first match wins**.

The order is the policy, not a style choice, and two things decide it.

*Safety*: `NO_CLAUDE` leads, so a dead session’s scrollback can never be
read as live state — the pane this was written against still showed a
permission dialog and a disconnect notice above a shell prompt, all true
once and none true now. `HELD_ELSEWHERE` precedes every reconnect
verdict, per the rule that a session picked up on another device is never
taken back without asking.

*Freshness*: the pill rules are **live** state and the phrase rules are
**history**. A session that dropped and recovered still carries
“Remote Control disconnected” in its scrollback for as long as it stays on
screen, so a text rule placed above the pill would report a healthy
session as broken until the line scrolled away.

### xa.revive.DFLT_CHECK_TICKS *= 2*

Consecutive ticks a pane must stay reconnectable before the check escalates. One tick can
be a transient (the drop that a VPN toggle clears within a minute); two cannot.

### xa.revive.DFLT_MIN_INTERVAL_SEC *= 600.0*

Long enough that a cron tick can never turn into a keystroke storm, short
enough that a real network change is followed within one settling period.

### xa.revive.HELD_ELSEWHERE *= 'held_elsewhere'*

Taken over or ended from another device. Never reconnect without opt-in.

### xa.revive.MARKERS *: [dict](https://docs.python.org/3/builtins/stdtypes.html#dict)[[str](https://docs.python.org/3/builtins/stdtypes.html#str), [tuple](https://docs.python.org/3/builtins/stdtypes.html#tuple)[[str](https://docs.python.org/3/builtins/stdtypes.html#str), ...]]* *= {'api_stalled': ('api error', 'retrying in ', 'overloaded'), 'connected': ('remote control active',), 'held_elsewhere': ('ended or archived from another device', 'no longer the active worker for the session', 'already has remote control for this conversation', 'run /remote-control to move it to this terminal'), 'needs_human': ('do you want to proceed?', 'esc to cancel'), 'needs_login': ('run /login', 'please log in', 'select login method', 'oauth token has expired', 'invalid api key', 'unknown command: /remote-control'), 'needs_trust': ('trust this folder', 'do you trust the files'), 'reconnectable': ('remote control disconnected', 'remote control not started here', 'run /remote-control to retry', '/remote-control is no longer active', '/rc failed'), 'reconnecting': ('/rc reconnecting',), 'server_mode': ('re-run \`claude remote-control\` to try again',)}*

Substring markers per verdict. Lowercase; matched against a lowered tail.

### xa.revive.NEEDS_HUMAN *= 'needs_human'*

Blocked on a human — an open permission dialog, or anything else that is
eating keystrokes. See [`NEEDS_LOGIN`](_autosummary/xa.revive.html.md#xa.revive.NEEDS_LOGIN) / [`NEEDS_TRUST`](_autosummary/xa.revive.html.md#xa.revive.NEEDS_TRUST) for the
two causes specific enough to tell the user how to fix.

### xa.revive.NEEDS_LOGIN *= 'needs_login'*

claude on this host is logged out.
Login state is per-machine, so one `/login` fixes every session on it.

* **Type:**
  Blocked on a human, specifically

### xa.revive.NEEDS_TRUST *= 'needs_trust'*

the workspace-trust prompt is open.

* **Type:**
  Blocked on a human, specifically

### xa.revive.NO_CLAUDE *= 'no_claude'*

No claude process behind the pane — a shell prompt, or a session that died.

### xa.revive.PROMPT_LINE *= re.compile('(?m)^(?:❯|>)[\\xa0 ](.\*)$', re.MULTILINE)*

the prompt glyph, then U+00A0, then whatever the user
has typed. 

```
``
```

> \`\` is the plain-ASCII rendering some terminals get.

* **Type:**
  The TUI’s input line

### *class* xa.revive.PaneRef(target, host='local', claude_pid=None, cwd=None, session_id=None, bridge_session_id=None, name=None, status=None)

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

Identity of one candidate pane — everything known *without* reading it.

`target` is a tmux target: a full pane ref (`session:@window.%pane`,
which is what the ephemeral session file records) or a bare session name.

#### status *: [Optional](https://docs.python.org/3/library/typing.html#typing.Optional)[[str](https://docs.python.org/3/builtins/stdtypes.html#str)]* *= None*

`idle` / `busy` / `waiting` as the session last reported it.
`None` on a claude too old to record one.

### *class* xa.revive.PaneState(ref, tail, verdict, evidence=None)

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

A pane, as read and judged. The value type of [`SessionPanes`](_autosummary/xa.revive.html.md#xa.revive.SessionPanes).

### *class* xa.revive.Probe(text, ref=<factory>)

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

The complete, pure input to a classification rule.

`text` is the pane tail, lowercased once so every rule can use a plain
substring test.

### xa.revive.RC_PILL *= re.compile('(?m)^.\*(?<![\\\\w/])/rc(?: active)?\\\\s\*$', re.MULTILINE)*

The footer *pill*. Present while Remote Control is connected — `/rc` on
its own right-aligned line, or `/rc active` in verbose mode — and gone
the moment it is not. Anchored to a line end because a bare `"/rc" in
text` would also match a file path ending in `src/rc`.

The direction matters and is easy to get backwards: the pill is evidence
of *health*. Verified by disconnecting a live session and watching the
line vanish (claude 2.1.251).

### xa.revive.RECONNECTABLE *= 'reconnectable'*

Dropped and recoverable — the one verdict [`revive()`](_autosummary/xa.revive.html.md#xa.revive.revive) acts on.

### xa.revive.RECONNECTING *= 'reconnecting'*

Remote Control is retrying right now. Leave it alone; it may well succeed.

### xa.revive.RECONNECT_KEYS *= ('/remote-control', 'Enter')*

The keystrokes that reconnect a REPL session. `Enter` submits.

### xa.revive.REPORT_ORDER *= ('reconnectable', 'server_mode', 'held_elsewhere', 'needs_human', 'api_stalled', 'reconnecting', 'no_claude', 'unknown', 'connected')*

Verdicts worth a human’s eye, in the order a report should present them.

### *class* xa.revive.RateGuard(\*, store=None, min_interval_sec=600.0, clock=<built-in function time>)

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

Refuses to touch the same pane twice inside `min_interval_sec`.

Without this a cron tick, a hook and an impatient human can each send
`/remote-control` into the same pane seconds apart. Backed by any
`{key: bytes}` mapping — the default is xa’s on-disk
[`FileStore`](_autosummary/xa.store.html.md#xa.store.FileStore), so the interval survives process exit,
which is the entire point.

```pycon
>>> clock = iter([100.0, 200.0, 800.0]).__next__
>>> guard = RateGuard(store={}, min_interval_sec=600.0, clock=clock)
>>> guard.allow('work:@1.%1')     # never attempted
True
>>> guard.record('work:@1.%1')    # stamped at t=100
>>> guard.allow('work:@1.%1')     # t=200 — 100s later, still held off
False
>>> guard.allow('work:@1.%1')     # t=800 — 700s later, released
True
```

#### wait_remaining(target)

Seconds left before `target` may be touched again (0.0 if now).

* **Return type:**
  [`float`](https://docs.python.org/3/builtins/functions.html#float)

### *class* xa.revive.ReviveAction(target, verdict, keys=(), sent=False, skipped=None, evidence=None, cwd=None)

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

What was (or would be) done to one pane, and why.

#### *property* would_send *: [bool](https://docs.python.org/3/builtins/functions.html#bool)*

True when only `apply=False` stood in the way.

### xa.revive.SERVER_MODE *= 'server_mode'*

A `claude remote-control` *server* died. See [`restart_server_mode()`](_autosummary/xa.revive.html.md#xa.revive.restart_server_mode).

### *class* xa.revive.SessionPanes(\*, panes=<function local_panes>, is_relevant=<function has_live_claude>, tail=<function \_capture>, rules=(('no_claude', <function \_no_claude>), ('held_elsewhere', <function \_any_of.<locals>._pred>), ('reconnecting', <function \_any_of.<locals>._pred>), ('connected', <function \_pill_present>), ('connected', <function \_any_of.<locals>._pred>), ('needs_login', <function \_any_of.<locals>._pred>), ('needs_trust', <function \_any_of.<locals>._pred>), ('needs_human', <function \_any_of.<locals>._pred>), ('api_stalled', <function \_any_of.<locals>._pred>), ('server_mode', <function \_any_of.<locals>._pred>), ('reconnectable', <function \_any_of.<locals>._pred>), ('reconnectable', <function \_bridge_down>), ('unknown', <function \_always>)))

Bases: [`Mapping`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Mapping)

Live view of the panes worth judging: `{tmux target: PaneState}`.

Every source of truth is injected, which is what lets the whole
classification path be tested without a tmux server:

- `panes` — callable returning [`PaneRef`](_autosummary/xa.revive.html.md#xa.revive.PaneRef) objects (default:
  [`local_panes()`](_autosummary/xa.revive.html.md#xa.revive.local_panes));
- `is_relevant` — per-ref filter (default: [`has_live_claude()`](_autosummary/xa.revive.html.md#xa.revive.has_live_claude));
- `tail` — callable reading a ref’s pane text (default: tmux capture);
- `rules` — the classification table (default: [`DEFAULT_RULES`](_autosummary/xa.revive.html.md#xa.revive.DEFAULT_RULES)).

Pane text is read lazily and cached, so building the mapping costs
nothing and iterating it costs one capture per pane.

```pycon
>>> refs = [PaneRef(target='w:@1.%1', claude_pid=7, bridge_session_id='s_1')]
>>> panes = SessionPanes(
...     panes=lambda: refs,
...     is_relevant=lambda ref: True,
...     tail=lambda ref: 'Remote Control disconnected',
... )
>>> list(panes)
['w:@1.%1']
>>> panes['w:@1.%1'].verdict
'reconnectable'
>>> panes.by_verdict()['reconnectable']
['w:@1.%1']
```

#### by_verdict()

`{verdict: [target, ...]}` — reads every pane.

* **Return type:**
  [`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`list`](https://docs.python.org/3/builtins/stdtypes.html#list)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]]

#### refresh()

Drop every cached ref and pane read. Returns self, for chaining.

* **Return type:**
  [`SessionPanes`](_autosummary/xa.revive.html.md#xa.revive.SessionPanes)

### xa.revive.TYPEABLE_STATUS *= frozenset({'idle', None})*

Statuses in which a keystroke is a *command*. Anything else — `busy`,
`waiting` — means the session is mid-turn or holding a dialog, and typed
text would be queued into it. `None` is a claude too old to say.

### xa.revive.UNKNOWN *= 'unknown'*

The pane says nothing either way. Never acted on.

### xa.revive.VERDICTS *= frozenset({'api_stalled', 'connected', 'held_elsewhere', 'needs_human', 'needs_login', 'needs_trust', 'no_claude', 'reconnectable', 'reconnecting', 'server_mode', 'unknown'})*

Every verdict [`DEFAULT_RULES`](_autosummary/xa.revive.html.md#xa.revive.DEFAULT_RULES) can produce. Custom rules may add more.

### xa.revive.check(, panes=None, store=None, ticks=2, actionable=frozenset({'reconnectable'}))

Report-only revive check, meant for a timer: **sends nothing, ever.**

Looks at each live pane once (one tmux capture per pane) and counts, per pane, the
consecutive ticks it has been reconnectable. A pane is escalated only once that count
reaches `ticks`; a pane that recovers, or is no longer there, loses its streak. Panes
that are reconnectable but that [`revive()`](_autosummary/xa.revive.html.md#xa.revive.revive) would refuse to type into (unsent prompt
text, busy) are still reported, with the reason, since a human may need to look. There
is deliberately no `apply` here: moving to unattended `--apply` is a separate,
later decision (#11).

```pycon
>>> refs = [PaneRef(target='a:@1.%1', claude_pid=1)]
>>> panes = SessionPanes(panes=lambda: refs, is_relevant=lambda r: True,
...                      tail=lambda r: '/rc failed\n\u276f ')
>>> state = {}
>>> [check(panes=panes, store=state).quiet for _ in range(2)]
[True, False]
```

* **Return type:**
  [`CheckResult`](_autosummary/xa.revive.html.md#xa.revive.CheckResult)

### xa.revive.classify(probe, \*, rules=(('no_claude', <function \_no_claude>), ('held_elsewhere', <function \_any_of.<locals>._pred>), ('reconnecting', <function \_any_of.<locals>._pred>), ('connected', <function \_pill_present>), ('connected', <function \_any_of.<locals>._pred>), ('needs_login', <function \_any_of.<locals>._pred>), ('needs_trust', <function \_any_of.<locals>._pred>), ('needs_human', <function \_any_of.<locals>._pred>), ('api_stalled', <function \_any_of.<locals>._pred>), ('server_mode', <function \_any_of.<locals>._pred>), ('reconnectable', <function \_any_of.<locals>._pred>), ('reconnectable', <function \_bridge_down>), ('unknown', <function \_always>)))

Return the verdict for `probe`. Pure — no I/O, no tmux, no clock.

A session whose footer pill is gone and whose session file records no
bridge id has dropped:

```pycon
>>> dropped = PaneRef(target='w:@1.%1', claude_pid=42)
>>> classify(Probe(text='conversation text\n❯ ', ref=dropped))
'reconnectable'
```

One still carrying the pill has not, whatever its scrollback remembers:

```pycon
>>> live = PaneRef(target='w:@1.%1', claude_pid=42, bridge_session_id='s')
>>> classify(Probe(text='remote control disconnected\n     /rc', ref=live))
'connected'
```

A session someone picked up on their phone is never reconnectable, even
though the pane also says it disconnected:

```pycon
>>> taken = 'remote control disconnected\nended or archived from another device'
>>> classify(Probe(text=taken, ref=dropped))
'held_elsewhere'
```

Neither is one sitting on a permission dialog:

```pycon
>>> classify(Probe(text='/rc failed\ndo you want to proceed?', ref=live))
'needs_human'
```

And a healthy, quiet, connected pane is simply left alone:

```pycon
>>> classify(Probe(text='just some conversation\n  /rc', ref=live))
'connected'
```

* **Return type:**
  [`str`](https://docs.python.org/3/builtins/stdtypes.html#str)

### xa.revive.evidence_for(probe, verdict, \*, rules=(('no_claude', <function \_no_claude>), ('held_elsewhere', <function \_any_of.<locals>._pred>), ('reconnecting', <function \_any_of.<locals>._pred>), ('connected', <function \_pill_present>), ('connected', <function \_any_of.<locals>._pred>), ('needs_login', <function \_any_of.<locals>._pred>), ('needs_trust', <function \_any_of.<locals>._pred>), ('needs_human', <function \_any_of.<locals>._pred>), ('api_stalled', <function \_any_of.<locals>._pred>), ('server_mode', <function \_any_of.<locals>._pred>), ('reconnectable', <function \_any_of.<locals>._pred>), ('reconnectable', <function \_bridge_down>), ('unknown', <function \_always>)))

The marker that earned `verdict`, for a report a human has to trust.

```pycon
>>> ref = PaneRef(target='w:@1.%1', claude_pid=1)
>>> evidence_for(Probe(text='/rc failed', ref=ref), 'reconnectable')
'/rc failed'
```

* **Return type:**
  [`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]

### xa.revive.format_actions(actions)

One line per pane, most actionable first.

```pycon
>>> print(format_actions([
...     ReviveAction('a:@1.%1', RECONNECTABLE, keys=RECONNECT_KEYS,
...                  skipped='dry-run', evidence='/rc failed'),
...     ReviveAction('b:@1.%1', CONNECTED),
... ]))
reconnectable  a:@1.%1  would send /remote-control  [/rc failed]
connected      b:@1.%1
```

* **Return type:**
  [`str`](https://docs.python.org/3/builtins/stdtypes.html#str)

### xa.revive.has_live_claude(ref)

Default relevance test: the recorded pid is a *claude* that still exists.

Identity, not just liveness — a stale ephemeral file whose pid got
recycled must never direct keystrokes at an unrelated process.

* **Return type:**
  [`bool`](https://docs.python.org/3/builtins/functions.html#bool)

### xa.revive.hint_for(verdict, , tmux_name=None)

Human fix-it line for a verdict, or `None` when there is nothing to say.

SSOT for the wording shown by the CLI, the web UI and the HTTP API, so
the three can’t drift. Only the verdicts a person can actually clear get
a line; `connected`/`unknown`/`reconnectable` return `None`
(nothing to do, nothing known, or xa’s own job respectively).

```pycon
>>> hint_for(CONNECTED) is None
True
>>> hint_for(NEEDS_TRUST, tmux_name='sess').startswith('Claude is waiting')
True
```

* **Return type:**
  [`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]

### xa.revive.local_panes(, claude_home=PosixPath('/home/runner/.claude'))

Yield one [`PaneRef`](_autosummary/xa.revive.html.md#xa.revive.PaneRef) per live claude that records a tmux pane.

Derived from the ephemeral session files rather than from
`tmux list-panes`: each file names its own pane, so no heuristic has
to decide whether a pane holds a claude. A session not under tmux (every
session on a machine that runs claude in terminal tabs) simply has no
`tmux` key and is skipped — there is no pane to send keys to.

* **Return type:**
  [`Iterator`](https://docs.python.org/3/library/typing.html#typing.Iterator)[[`PaneRef`](_autosummary/xa.revive.html.md#xa.revive.PaneRef)]

### xa.revive.prompt_is_clear(tail)

True when the pane’s input line is empty and safe to type into.

This is the difference between reconnecting a session and destroying the
instruction its owner left half-typed: `send-keys` appends to whatever
is already in the buffer, so `/remote-control` sent at a pane whose
prompt reads `yes, port it into the repo` submits
`yes, port it into the repo/remote-control`.

Conservative by construction — a pane whose prompt line cannot be found
is reported as not clear, because “I could not see the buffer” and “the
buffer is empty” must never collapse into the same answer.

```pycon
>>> prompt_is_clear('---\n❯ \n---')
True
>>> prompt_is_clear('❯ yes, port it into the repo')
False
>>> prompt_is_clear('no prompt line here at all')
False
```

* **Return type:**
  [`bool`](https://docs.python.org/3/builtins/functions.html#bool)

### xa.revive.refusal_to_type(state)

Why typing into `state` would be unsafe, or `None` if it is fine.

Two independent gates, because each catches what the other misses: the
reported status catches a session mid-turn whose buffer happens to be
empty, and the buffer check catches an idle session holding text the
status knows nothing about.

```pycon
>>> ref = PaneRef(target='t', claude_pid=1, status='idle')
>>> refusal_to_type(PaneState(ref=ref, tail='❯ ', verdict=RECONNECTABLE))
>>> busy = replace(ref, status='busy')
>>> refusal_to_type(PaneState(ref=busy, tail='❯ ', verdict=RECONNECTABLE))
'session is busy'
```

* **Return type:**
  [`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]

### xa.revive.restart_server_mode(state, , cwd=None, apply=False, rate_guard=None, send=None, resolve_cwd=None)

Restart a died `claude remote-control` server in its own directory.

The directory is **not** recorded by this package. It is read back from
what already knows it — the pane’s own working directory via tmux, or
the ephemeral session file when a claude is still alive — and the
session identity is left to `claude remote-control -c`, which keeps
its own per-directory record. Adding a fourth place to write it down
would only create something to drift.

Refuses whenever a live claude still owns the pane: this sends a *shell*
command, and a running TUI would take it as prompt text.

```pycon
>>> ref = PaneRef(target='srv:@1.%1', cwd='/srv/app')
>>> state = PaneState(ref=ref, tail='', verdict=SERVER_MODE)
>>> keyed = []
>>> action = restart_server_mode(
...     state,
...     apply=True,
...     rate_guard=RateGuard(store={}, clock=lambda: 0.0),
...     send=lambda target, *keys: keyed.append((target, keys)),
... )
>>> action.sent, keyed
(True, [('srv:@1.%1', ('cd /srv/app && claude remote-control -c', 'Enter'))])
```

```pycon
>>> live = PaneState(ref=replace(ref, claude_pid=9), tail='', verdict=SERVER_MODE)
>>> restart_server_mode(live, apply=True).skipped
'a claude still owns this pane — keystrokes would land in its prompt'
```

* **Return type:**
  [`ReviveAction`](_autosummary/xa.revive.html.md#xa.revive.ReviveAction)

### xa.revive.revive(, panes=None, apply=False, include_held_elsewhere=False, rate_guard=None, send=None, actionable=frozenset({'reconnectable'}))

Reconnect every dropped pane. \*\*Dry run unless `apply=True`.\*\*

Returns one [`ReviveAction`](_autosummary/xa.revive.html.md#xa.revive.ReviveAction) per pane examined — including the ones
left alone, each carrying the reason, because “nothing happened” is only
useful next to what was looked at.

`include_held_elsewhere=True` opts into reconnecting sessions that were
taken over from another device. That steals the session back from
whatever device holds it; it is off by default and should stay a
deliberate keystroke.

```pycon
>>> refs = [
...     PaneRef(target='a:@1.%1', claude_pid=1),
...     PaneRef(target='b:@1.%1', claude_pid=2, bridge_session_id='s'),
... ]
>>> tails = {'a:@1.%1': '/rc failed\n❯ ', 'b:@1.%1': 'all quiet\n❯ \n   /rc'}
>>> panes = SessionPanes(
...     panes=lambda: refs,
...     is_relevant=lambda ref: True,
...     tail=lambda ref: tails[ref.target],
... )
>>> sent = []
>>> actions = revive(
...     panes=panes,
...     apply=True,
...     rate_guard=RateGuard(store={}, clock=lambda: 0.0),
...     send=lambda target, *keys: sent.append((target, keys)),
... )
>>> [(a.target, a.verdict, a.sent) for a in actions]
[('a:@1.%1', 'reconnectable', True), ('b:@1.%1', 'connected', False)]
>>> sent
[('a:@1.%1', ('/remote-control', 'Enter'))]
```

* **Return type:**
  [`list`](https://docs.python.org/3/builtins/stdtypes.html#list)[[`ReviveAction`](_autosummary/xa.revive.html.md#xa.revive.ReviveAction)]

### xa.revive.server_mode_command(cwd)

Keystrokes that restart a Remote Control *server* in `cwd`.

`claude remote-control -c` reattaches the session the command last
recorded **for that directory** (within ~4h), which is why the directory
— and nothing else — is what a restart needs to know.

```pycon
>>> server_mode_command('/root/py/proj')
('cd /root/py/proj && claude remote-control -c', 'Enter')
>>> server_mode_command(None)
('claude remote-control -c', 'Enter')
```

* **Return type:**
  [`tuple`](https://docs.python.org/3/builtins/stdtypes.html#tuple)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`...`](https://docs.python.org/3/builtins/constants.html#Ellipsis)]


# _autosummary/xa.service.html.md

# xa.service

FastAPI service for `xa`.

`build_api(...)` returns a mountable `FastAPI` app that reimplements
the `edualc` route surface on top of the `xa` primitives. The service
is deliberately a function (not a module that imports-and-runs) so it can
be embedded into larger hosts (enlace / tw_platform) or launched
standalone via `xa serve`.

FastAPI is an optional dependency. Import `xa.service` only when you
have installed `xa[service]` (pulls in `fastapi` + `uvicorn`).

### Module Attributes

| [`RC_ENABLE_TIMEOUT_SEC`](_autosummary/xa.service.html.md#xa.service.RC_ENABLE_TIMEOUT_SEC)   | How long POST /sessions/{id}/remote-control waits for claude to write its bridge id after the command is sent.   |
|--------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------|

### Functions

| [`allow_all`](_autosummary/xa.service.html.md#xa.service.allow_all)()                              | No-op auth dependency.                                            |
|-------------------------------------------------------------------------------------------|-------------------------------------------------------------------|
| [`build_api`](_autosummary/xa.service.html.md#xa.service.build_api)(\*[, auth, events_store, ...]) | Return a `FastAPI` app exposing `xa`'s session + archive surface. |
| [`make_basic_auth`](_autosummary/xa.service.html.md#xa.service.make_basic_auth)(username, password)      | Build a FastAPI dependency that enforces HTTP Basic auth.         |

### Classes

| [`Captcha`](_autosummary/xa.service.html.md#xa.service.Captcha)(\*, key[, ttl_sec])   | Stateless 4-letter captcha with an HMAC-signed token.   |
|--------------------------------------------------------------------------------|---------------------------------------------------------|

### *class* xa.service.Captcha(, key, ttl_sec=120)

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

Stateless 4-letter captcha with an HMAC-signed token.

The signing key never leaves the server. Tokens are
`b64(CHALLENGE.EXPIRY).SIG` where SIG = HMAC-SHA256(key, payload).
Multi-worker safe; no server-side state. Pass one instance of this
class to [`build_api()`](_autosummary/xa.service.html.md#xa.service.build_api) to enable captcha-gated deletes.

#### issue()

Return `(token, challenge, ttl_sec)`.

* **Return type:**
  [`tuple`](https://docs.python.org/3/builtins/stdtypes.html#tuple)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`int`](https://docs.python.org/3/builtins/functions.html#int)]

### xa.service.RC_ENABLE_TIMEOUT_SEC *= 15.0*

How long POST /sessions/{id}/remote-control waits for claude to write
its bridge id after the command is sent. The TUI acks well before the
session file is rewritten, so a bare read would always miss.

### xa.service.allow_all()

No-op auth dependency. Useful when the service is behind an external
auth layer (enlace, reverse-proxy mTLS) that already gated the request.

FastAPI inspects the signature to decide what to inject; keep this
nullary so it isn’t treated as query-parameter binding.

* **Return type:**
  [`str`](https://docs.python.org/3/builtins/stdtypes.html#str)

### xa.service.build_api(\*, auth=<function allow_all>, events_store=None, pane_store=None, captcha=None, claude_home=PosixPath('/home/runner/.claude'), claude_bin='claude', session_prefix='xa-', title='xa', version='0.1', include_webui=False, default_folder=None, nav=None)

Return a `FastAPI` app exposing `xa`’s session + archive surface.

The caller composes this app into whatever process they have: mount
under `/api/xa/` inside enlace, or run standalone via `uvicorn`.

`nav` is a list of `(label, address)` links to the owner’s other pages
(`xa.config.load_nav`), shown as a row on the web UI; empty or `None`
shows nothing.

### xa.service.make_basic_auth(username, password)

Build a FastAPI dependency that enforces HTTP Basic auth.

Returns a callable suitable for `Depends(...)`. Uses
`secrets.compare_digest` to avoid timing leaks.

* **Return type:**
  [`Callable`](https://docs.python.org/3/library/typing.html#typing.Callable)[[`...`](https://docs.python.org/3/builtins/constants.html#Ellipsis), [`Any`](https://docs.python.org/3/library/typing.html#typing.Any)]


# _autosummary/xa.sessions.html.md

# xa.sessions

The unified `Session` domain model and multi-host discovery.

This layer is the single thing CLI / HTTP / UI renderers iterate over.
Discovery and actions are delegated to [`xa.hosts`](_autosummary/xa.hosts.html.md#module-xa.hosts); this module
composes them into a host-agnostic API.

### Functions

| [`get_session`](_autosummary/xa.sessions.html.md#xa.sessions.get_session)(session_id, \*[, hosts, claude_home])   | Find one session by full ID or unique prefix.                                       |
|------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------|
| [`iter_local_sessions`](_autosummary/xa.sessions.html.md#xa.sessions.iter_local_sessions)(\*[, claude_home, ...])         | Legacy local-only iterator.                                                         |
| [`kill_session`](_autosummary/xa.sessions.html.md#xa.sessions.kill_session)(session, \*[, hosts])                  | Kill a live `Session`, scoped to what actually belongs to it.                       |
| [`launch_opts`](_autosummary/xa.sessions.html.md#xa.sessions.launch_opts)(facts, \*[, claude_home, ...])          | `(resume kwargs, warning)` that bring `facts` back as it was launched.              |
| [`list_sessions`](_autosummary/xa.sessions.html.md#xa.sessions.list_sessions)(\*[, hosts, project, ...])            | Return sessions sorted by recency (live first, then newest-modified).               |
| [`resume`](_autosummary/xa.sessions.html.md#xa.sessions.resume)(session, \*[, cwd, name, hosts])             | Resume a transcript / archived session on its originating host, as it was launched. |
| [`resume_shell_command`](_autosummary/xa.sessions.html.md#xa.sessions.resume_shell_command)(facts, \*[, ...])              | `(shell command, warning)` that resumes `facts`' session as it was launched.        |

### Classes

| [`Session`](_autosummary/xa.sessions.html.md#xa.sessions.Session)(id, claude_session_id, ...[, ...])   | Canonical session record — valid across hosts and states.   |
|-----------------------------------------------------------------------------------------------|-------------------------------------------------------------|

### *class* xa.sessions.Session(id, claude_session_id, bridge_session_id, host, cwd, project_slug, state, live_pid, tmux_name, name, summary, first_user_message, turn_count, forked_from, created, modified, url, url_source, transcript_path, pre_first_turn=False, attention=None, attention_hint=None, tmux_pane=None, pane_provider=None, pane_ref=None)

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

Canonical session record — valid across hosts and states.

Fields that don’t apply to a given state are `None`. Discovery
functions return fresh instances; callers should treat it as
immutable.

#### *property* pane_address *: [Optional](https://docs.python.org/3/library/typing.html#typing.Optional)[[PaneAddress](_autosummary/xa.panes.html.md#xa.panes.PaneAddress)]*

Where this session’s pane is, or `None` (a session with no terminal).

### xa.sessions.get_session(session_id, , hosts=None, claude_home=None)

Find one session by full ID or unique prefix.

Raises `LookupError` if the prefix is ambiguous.

* **Return type:**
  [`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`Session`](_autosummary/xa.sessions.html.md#xa.sessions.Session)]

### xa.sessions.iter_local_sessions(, claude_home=PosixPath('/home/runner/.claude'), project_slug=None, include_live=True, tmux_bin=None)

Legacy local-only iterator.

Retained for backward compatibility and because some tests construct
sessions directly from a fake `~/.claude/`. Wraps a fresh
`LocalHost`.

* **Return type:**
  [`Iterator`](https://docs.python.org/3/library/typing.html#typing.Iterator)[[`Session`](_autosummary/xa.sessions.html.md#xa.sessions.Session)]

### xa.sessions.kill_session(session, , hosts=None)

Kill a live `Session`, scoped to what actually belongs to it.

Kills the backing tmux session only when it is *dedicated* to this
claude (single pane, claude verified in it) — a claude living in one
window of a shared multi-window workspace must not take the whole
workspace down, so there we SIGTERM the identity-verified pid
instead. Remote hosts keep the name-kill contract (their server
applies its own scoping). Returns a short description of what was
killed (e.g. `"tmux:mysess"` / `"pid:1234"`).

* **Return type:**
  [`str`](https://docs.python.org/3/builtins/stdtypes.html#str)

### xa.sessions.launch_opts(facts, , claude_home=PosixPath('/home/runner/.claude'), permission_mode=None, euid=None)

`(resume kwargs, warning)` that bring `facts` back as it was launched.

Effort is deliberately not restored: the recorded per-turn value can sit
below the account’s `effortLevel`, and the issue asked for the model.
`permission_mode` (`''`: claude’s default) replaces the recorded mode,
bypass is then not allowed and there is no warning; `euid` stands in for
the process’s own when deciding whether bypass is refused.

* **Return type:**
  [`tuple`](https://docs.python.org/3/builtins/stdtypes.html#tuple)[[`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict), [`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]]

### xa.sessions.list_sessions(, hosts=None, project=None, include_forks=True, include_live=True, state=None, limit=None, claude_home=None, tmux_bin=None)

Return sessions sorted by recency (live first, then newest-modified).

When `hosts` is `None` we default to a single `LocalHost`.
If `claude_home` or `tmux_bin` are given, they’re forwarded into
that default `LocalHost` — handy for fixture-based tests.

Filters:

- `project` — substring match against `cwd` (case-insensitive)
- `include_forks=False` — drop sessions with a `forked_from`
- `include_live=False` — skip live discovery (per host)
- `state` — one of `"live"` / `"archived"` / `"transcript_only"`

* **Return type:**
  [`list`](https://docs.python.org/3/builtins/stdtypes.html#list)[[`Session`](_autosummary/xa.sessions.html.md#xa.sessions.Session)]

### xa.sessions.resume(session, , cwd=None, name=None, hosts=None, \*\*opts)

Resume a transcript / archived session on its originating host, as it was launched.

Whatever the caller leaves unset comes from the transcript
([`launch_opts()`](_autosummary/xa.sessions.html.md#xa.sessions.launch_opts)): the cwd it was started in, its model when that differs
from the account default’s family, and its permission mode, so a session
started with `--dangerously-skip-permissions` comes back with it.
`permission_mode=''` asks for claude’s default explicitly. When a launch
fact had to be dropped (bypass refused to root), the result’s `warning`
says so.

Only for a local host: a remote one gets exactly what the caller set, and
its own xa reads its own transcript the same way.

* **Return type:**
  [`SpawnResult`](_autosummary/xa.claude_cli.html.md#xa.claude_cli.SpawnResult)

### xa.sessions.resume_shell_command(facts, , claude_home=PosixPath('/home/runner/.claude'), claude_bin='claude', cwd=None, remote_control=False, permission_mode=None, euid=None)

`(shell command, warning)` that resumes `facts`’ session as it was launched.

The one place that assembles the line: `cd` into the cwd it was started in,
the account’s environment (`claude_home`), `--resume <id>`, the permission
flags and the model ([`launch_opts()`](_autosummary/xa.sessions.html.md#xa.sessions.launch_opts)), every token shell-quoted. The
command is for a fresh shell and carries no secret. It never runs `claude_bin`:
every flag is written, so run it where that claude is new enough
([`xa.claude_cli.prepare_spawn()`](_autosummary/xa.claude_cli.html.md#xa.claude_cli.prepare_spawn) is what probes). `warning` is what had to
be dropped (bypass refused to root), else `None`.

```pycon
>>> from xa.claude_fs import LaunchFacts
>>> f = LaunchFacts('s1', Path('/t.jsonl'), '/w x', '', False, None, None, None, None, 0.0)
>>> cmd, warning = resume_shell_command(f, claude_home=Path('/nonexistent/.claude'))
>>> cmd.startswith("cd '/w x' && exec env"), '--resume s1' in cmd, warning
(True, True, None)
```

* **Return type:**
  [`tuple`](https://docs.python.org/3/builtins/stdtypes.html#tuple)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]]


# _autosummary/xa.store.html.md

# xa.store

Minimal key-value and append-log storage.

This is deliberately thin and stdlib-only — enough to back `xa.archive`’s
event log and per-session pane captures without pulling in `dol`. Two
types:

- `JsonLinesStore` — append-only JSONL. Iterable, multi-writer safe on
  POSIX (one line == one atomic `write`), no random access.
- `FileStore` — dict-like view over a directory of flat files. Keys
  must match a strict allowlist regex so callers can’t escape `root`.

Later phases may swap these for `dol` equivalents without changing
the archive API.

### Functions

| [`default_events_store`](_autosummary/xa.store.html.md#xa.store.default_events_store)([state_dir])       | The event log at `<state_dir>/events.jsonl`.                                                                                 |
|------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------|
| [`default_pane_store`](_autosummary/xa.store.html.md#xa.store.default_pane_store)([state_dir])         | Per-session pane logs at `<state_dir>/panes/<id>.log`.                                                                       |
| [`default_revive_check_store`](_autosummary/xa.store.html.md#xa.store.default_revive_check_store)([state_dir]) | The report-only check's streak counters (`<state_dir>/revive-check/streaks.json`).                                           |
| [`default_revive_store`](_autosummary/xa.store.html.md#xa.store.default_revive_store)([state_dir])       | Per-pane last-reconnect stamps for [`xa.revive.RateGuard`](_autosummary/xa.revive.html.md#xa.revive.RateGuard). |

### Classes

| [`FileStore`](_autosummary/xa.store.html.md#xa.store.FileStore)(root, \*[, suffix])   | Directory of files, accessed by key.              |
|----------------------------------------------------------------------------------|---------------------------------------------------|
| [`JsonLinesStore`](_autosummary/xa.store.html.md#xa.store.JsonLinesStore)(path)            | Append-only JSONL file with an `Iterable` reader. |

### *class* xa.store.FileStore(root, , suffix='')

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

Directory of files, accessed by key.

Values are `bytes`. Keys must match `[A-Za-z0-9_.-]+` — this
rejects path traversal attempts like `../etc/passwd`.

#### path_for(key)

Public path accessor (for callers that need to hand the path to tmux).

* **Return type:**
  [`Path`](https://docs.python.org/3/library/pathlib.html#pathlib.Path)

### *class* xa.store.JsonLinesStore(path)

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

Append-only JSONL file with an `Iterable` reader.

```pycon
>>> import tempfile, pathlib
>>> with tempfile.TemporaryDirectory() as td:
...     s = JsonLinesStore(pathlib.Path(td) / 'log.jsonl')
...     s.append({'a': 1})
...     s.append({'b': 2})
...     list(s) == [{'a': 1}, {'b': 2}]
True
```

### xa.store.default_events_store(state_dir=PosixPath('/home/runner/.xa'))

The event log at `<state_dir>/events.jsonl`.

* **Return type:**
  [`JsonLinesStore`](_autosummary/xa.store.html.md#xa.store.JsonLinesStore)

### xa.store.default_pane_store(state_dir=PosixPath('/home/runner/.xa'))

Per-session pane logs at `<state_dir>/panes/<id>.log`.

* **Return type:**
  [`FileStore`](_autosummary/xa.store.html.md#xa.store.FileStore)

### xa.store.default_revive_check_store(state_dir=PosixPath('/home/runner/.xa'))

The report-only check’s streak counters (`<state_dir>/revive-check/streaks.json`).

Kept apart from [`default_revive_store()`](_autosummary/xa.store.html.md#xa.store.default_revive_store) so a check tick can never be mistaken for
a reconnect attempt by the rate guard.

* **Return type:**
  [`FileStore`](_autosummary/xa.store.html.md#xa.store.FileStore)

### xa.store.default_revive_store(state_dir=PosixPath('/home/runner/.xa'))

Per-pane last-reconnect stamps for [`xa.revive.RateGuard`](_autosummary/xa.revive.html.md#xa.revive.RateGuard).

On disk rather than in memory on purpose: the guard exists to stop a
cron tick, a hook and a human from each sending `/remote-control`
into the same pane seconds apart, and every one of those is a
different process.

* **Return type:**
  [`FileStore`](_autosummary/xa.store.html.md#xa.store.FileStore)


# _autosummary/xa.telemetry.html.md

# xa.telemetry

Named telemetry profiles: where a session’s OTLP trace export goes, and where its credentials live.

A profile is a `[telemetry.<name>]` table of `~/.config/xa/config.toml`; `xa spawn
--telemetry <name>` (and `resume`) turns it into an [`xa.claude_env.OtlpTraces`](_autosummary/xa.claude_env.html.md#xa.claude_env.OtlpTraces).

```toml
[telemetry.lab]
endpoint = "https://otel.example.com/v1/traces"
headers_file = "~/.config/xa/lab.keys"       # KEY=VALUE lines, mode 600, yours
export_interval_ms = 5000
content = false                              # prompts and tool output stay out
[telemetry.lab.resource]
team = "fleet"
[telemetry.lab.headers]                      # header name = template over the file's keys
Authorization = "Bearer ${LAB_TOKEN}"
```

**Credentials never leave their file.** The config holds key *names* only; the values are
read from `headers_file` at the moment a pane starts, by the pane’s
own shell (`_xa_h="$(xa telemetry-headers lab)" && export OTEL_EXPORTER_OTLP_HEADERS="$_xa_h"`). So the
tmux command line, `ps`, the archive and the logs carry the expression, never the value,
and xa writes no file of its own. A missing key is an error that names the key.

### Functions

| [`get_telemetry_profile`](_autosummary/xa.telemetry.html.md#xa.telemetry.get_telemetry_profile)(name[, path])   | The profile called `name`; an unknown name lists the known ones.                                      |
|----------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------|
| [`load_telemetry_profiles`](_autosummary/xa.telemetry.html.md#xa.telemetry.load_telemetry_profiles)([path])       | Every `[telemetry.*]` profile of the config file (empty when there is none).                          |
| [`profile_from_table`](_autosummary/xa.telemetry.html.md#xa.telemetry.profile_from_table)(name, raw)         | Build a profile from its `[telemetry.<name>]` table; unknown keys are an error (typos).               |
| [`read_keys_file`](_autosummary/xa.telemetry.html.md#xa.telemetry.read_keys_file)(path)                  | The `KEY=VALUE` lines of a keys file (`export` prefix, quotes and whole-line `#` comments tolerated). |

### Classes

| [`TelemetryProfile`](_autosummary/xa.telemetry.html.md#xa.telemetry.TelemetryProfile)(name, endpoint[, protocol, ...])   | One named export target: its non-secret settings plus *where* its headers come from.   |
|------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------|

### *class* xa.telemetry.TelemetryProfile(name, endpoint, protocol='http/protobuf', content=False, resource=dict(), export_interval_ms=None, headers_file=None, headers=dict())

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

One named export target: its non-secret settings plus *where* its headers come from.

#### headers_env_value()

The value of `OTEL_EXPORTER_OTLP_HEADERS` (empty when the profile has no headers).

* **Return type:**
  [`str`](https://docs.python.org/3/builtins/stdtypes.html#str)

#### resolve_headers()

`{header: value}` with each `${KEY}` read from `headers_file`.

The keys file is the only source: a pane’s environment is the tmux server’s, not
the caller’s, so an environment fallback would pass here and fail there.
Raises `ValueError` naming the missing key (never a value).

* **Return type:**
  [`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict)

#### shell_export(, xa_command=None)

The shell fragment that exports the headers in the pane, or `''` without headers.

It holds a command substitution, never the value.

```pycon
>>> p = TelemetryProfile('lab', 'http://h/v1/traces', headers={'A': '${K}'})
>>> export = p.shell_export(xa_command=['xa'])
>>> export.startswith('_xa_h="$(XA_CONFIG='), 'telemetry-headers lab' in export
(True, True)
```

* **Return type:**
  [`str`](https://docs.python.org/3/builtins/stdtypes.html#str)

#### traces()

The `OtlpTraces` for the command line: no headers, so no secret.

* **Return type:**
  [`OtlpTraces`](_autosummary/xa.claude_env.html.md#xa.claude_env.OtlpTraces)

### xa.telemetry.get_telemetry_profile(name, path=None)

The profile called `name`; an unknown name lists the known ones. Headers are checked now.

Resolving them here means a missing key fails the `xa spawn` that asked, in the
caller’s terminal, rather than silently in a pane that exits on start.

* **Return type:**
  [`TelemetryProfile`](_autosummary/xa.telemetry.html.md#xa.telemetry.TelemetryProfile)

### xa.telemetry.load_telemetry_profiles(path=None)

Every `[telemetry.*]` profile of the config file (empty when there is none).

* **Return type:**
  [`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`TelemetryProfile`](_autosummary/xa.telemetry.html.md#xa.telemetry.TelemetryProfile)]

### xa.telemetry.profile_from_table(name, raw)

Build a profile from its `[telemetry.<name>]` table; unknown keys are an error (typos).

* **Return type:**
  [`TelemetryProfile`](_autosummary/xa.telemetry.html.md#xa.telemetry.TelemetryProfile)

### xa.telemetry.read_keys_file(path)

The `KEY=VALUE` lines of a keys file (`export` prefix, quotes and whole-line `#` comments tolerated).

```pycon
>>> import tempfile
>>> p = Path(tempfile.mkdtemp()) / 'k'
>>> _ = p.write_text('# c\nexport A="1"\nB=two\n')
>>> read_keys_file(p)
{'A': '1', 'B': 'two'}
```

* **Return type:**
  [`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]


# _autosummary/xa.tmux.html.md

# xa.tmux

Pure tmux wrappers.

No Claude Code knowledge lives here. Every public function takes a
`binary` keyword so callers can override the tmux executable (tests,
cross-platform installs, remote-host bridges).

Key gotchas encoded below:

- `session_target(name)` returns `f"{name}:"` — the trailing colon is
  essential. A bare session name can be silently resolved as a window or
  pane spec and mis-target a different session.
- `list_sessions` returns an empty list (not raises) when the tmux
  server isn’t running; tmux exits non-zero in that case and we absorb it.

### Functions

| [`capture_pane`](_autosummary/xa.tmux.html.md#xa.tmux.capture_pane)(name, \*[, lines, binary])          | Return the last `lines` of the targeted pane, or '' on failure.                                                          |
|---------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------|
| [`descendants`](_autosummary/xa.tmux.html.md#xa.tmux.descendants)(pid)                                 | All transitive descendant PIDs of `pid`.                                                                                 |
| [`kill_pane`](_autosummary/xa.tmux.html.md#xa.tmux.kill_pane)(ref, \*[, binary])                     | Close exactly one pane (`session:@window.%pane`), leaving its session and the other windows of a shared workspace alone. |
| `kill_session`(name, \*[, binary])                                                                |                                                                                                                          |
| [`list_panes`](_autosummary/xa.tmux.html.md#xa.tmux.list_panes)(\*[, binary])                         | Every pane on the server, or `[]` when no server is running.                                                             |
| [`list_sessions`](_autosummary/xa.tmux.html.md#xa.tmux.list_sessions)(\*[, binary])                      | Return all live tmux sessions; empty list if server isn't running.                                                       |
| [`new_session`](_autosummary/xa.tmux.html.md#xa.tmux.new_session)(name, \*, command[, binary])         | Create a detached tmux session running `command` as its pane's program.                                                  |
| [`pane_count`](_autosummary/xa.tmux.html.md#xa.tmux.pane_count)(name, \*[, binary])                   | Number of panes (across all windows) in the session; 0 if gone.                                                          |
| [`pane_current_path`](_autosummary/xa.tmux.html.md#xa.tmux.pane_current_path)(name, \*[, binary])            | Working directory of the targeted pane's program, or None.                                                               |
| [`pane_pid`](_autosummary/xa.tmux.html.md#xa.tmux.pane_pid)(name, \*[, binary])                     | Return the pid of the first pane's program, or None if the session is gone.                                              |
| [`pane_pids`](_autosummary/xa.tmux.html.md#xa.tmux.pane_pids)(name, \*[, binary])                    | PIDs of every pane program in the session (all windows, all panes).                                                      |
| [`pane_target`](_autosummary/xa.tmux.html.md#xa.tmux.pane_target)(ref)                                 | Target string for pane-scoped commands (capture, send-keys).                                                             |
| [`pipe_pane_to_file`](_autosummary/xa.tmux.html.md#xa.tmux.pipe_pane_to_file)(name, \*, path[, binary])      | Start streaming the pane's output to `path` (append mode).                                                               |
| [`proc_comm`](_autosummary/xa.tmux.html.md#xa.tmux.proc_comm)(pid)                                   | Return the `comm` name of a pid (kernel-level process name), '' if unreadable.                                           |
| [`rename_session`](_autosummary/xa.tmux.html.md#xa.tmux.rename_session)(old_name, new_name, \*[, binary]) | Rename a live tmux session.                                                                                              |
| [`send_keys`](_autosummary/xa.tmux.html.md#xa.tmux.send_keys)(name, \*keys[, binary])                | Send one or more keys/strings to the targeted pane.                                                                      |
| [`session_target`](_autosummary/xa.tmux.html.md#xa.tmux.session_target)(name)                             | Return the canonical target string for a session.                                                                        |

### Classes

| [`TmuxPane`](_autosummary/xa.tmux.html.md#xa.tmux.TmuxPane)(target, pid, current_command, ...)    | Minimal view of one tmux pane, from `list-panes -a`.    |
|-------------------------------------------------------------------------------------------------|---------------------------------------------------------|
| [`TmuxSession`](_autosummary/xa.tmux.html.md#xa.tmux.TmuxSession)(name, created, activity, attached) | Minimal view of one tmux session, from `list-sessions`. |

### *class* xa.tmux.TmuxPane(target, pid, current_command, current_path)

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

Minimal view of one tmux pane, from `list-panes -a`.

### *class* xa.tmux.TmuxSession(name, created, activity, attached)

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

Minimal view of one tmux session, from `list-sessions`.

### xa.tmux.capture_pane(name, , lines=200, binary='tmux')

Return the last `lines` of the targeted pane, or ‘’ on failure.

`name` may be a session name (targets its active pane) or a full
pane ref (`session:@w.%p`) for an exact pane.

* **Return type:**
  [`str`](https://docs.python.org/3/builtins/stdtypes.html#str)

### xa.tmux.descendants(pid)

All transitive descendant PIDs of `pid`.

Uses `/proc/*/status` where available and `ps` elsewhere (macOS),
so the process-tree walk behaves the same on every platform xa runs
on. Silently tolerates races (processes dying mid-scan) and returns
`[]` when neither source can be read.

* **Return type:**
  [`list`](https://docs.python.org/3/builtins/stdtypes.html#list)[[`int`](https://docs.python.org/3/builtins/functions.html#int)]

### xa.tmux.kill_pane(ref, , binary='tmux')

Close exactly one pane (`session:@window.%pane`), leaving its session and the
other windows of a shared workspace alone.

* **Return type:**
  [`None`](https://docs.python.org/3/builtins/constants.html#None)

### xa.tmux.list_panes(, binary='tmux')

Every pane on the server, or `[]` when no server is running.

`target` is the full pane ref, the same shape claude records in its
ephemeral session file, so the two views join without parsing.

* **Return type:**
  [`list`](https://docs.python.org/3/builtins/stdtypes.html#list)[[`TmuxPane`](_autosummary/xa.tmux.html.md#xa.tmux.TmuxPane)]

### xa.tmux.list_sessions(, binary='tmux')

Return all live tmux sessions; empty list if server isn’t running.

* **Return type:**
  [`list`](https://docs.python.org/3/builtins/stdtypes.html#list)[[`TmuxSession`](_autosummary/xa.tmux.html.md#xa.tmux.TmuxSession)]

### xa.tmux.new_session(name, , command, binary='tmux')

Create a detached tmux session running `command` as its pane’s program.

`command` is passed to a shell: the caller is responsible for quoting.
Use `shlex.quote` for untrusted parts.

* **Return type:**
  [`None`](https://docs.python.org/3/builtins/constants.html#None)

### xa.tmux.pane_count(name, , binary='tmux')

Number of panes (across all windows) in the session; 0 if gone.

* **Return type:**
  [`int`](https://docs.python.org/3/builtins/functions.html#int)

### xa.tmux.pane_current_path(name, , binary='tmux')

Working directory of the targeted pane’s program, or None.

This is where a pane’s shell would run a command, which is what
`claude remote-control -c` keys its per-directory record on.

* **Return type:**
  [`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]

### xa.tmux.pane_pid(name, , binary='tmux')

Return the pid of the first pane’s program, or None if the session is gone.

* **Return type:**
  [`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`int`](https://docs.python.org/3/builtins/functions.html#int)]

### xa.tmux.pane_pids(name, , binary='tmux')

PIDs of every pane program in the session (all windows, all panes).

Empty list when the session is gone. `name` may be a session name
or a full pane ref — `-s` scopes to the containing session either way.

* **Return type:**
  [`list`](https://docs.python.org/3/builtins/stdtypes.html#list)[[`int`](https://docs.python.org/3/builtins/functions.html#int)]

### xa.tmux.pane_target(ref)

Target string for pane-scoped commands (capture, send-keys).

Accepts either a bare session name or a full tmux pane ref
(`session:@window.%pane` — the shape claude records in its ephemeral
session file). A bare name targets the session’s *active* pane, which
may not be the claude pane in a multi-window session — pass the full
ref whenever you have one. Session names in xa match
`[A-Za-z0-9_.-]` so they can never contain a `:`.

```pycon
>>> pane_target('foo')
'foo:'
>>> pane_target('foo:@1.%2')
'foo:@1.%2'
```

* **Return type:**
  [`str`](https://docs.python.org/3/builtins/stdtypes.html#str)

### xa.tmux.pipe_pane_to_file(name, , path, binary='tmux')

Start streaming the pane’s output to `path` (append mode).

Uses `-o` so a duplicate call toggles the pipe off, matching edualc’s
behavior. tmux stops piping automatically when the pane dies.

* **Return type:**
  [`None`](https://docs.python.org/3/builtins/constants.html#None)

### xa.tmux.proc_comm(pid)

Return the `comm` name of a pid (kernel-level process name), ‘’ if unreadable.

Linux reads `/proc/<pid>/comm`, which is a bare name (`claude`).
`ps -o comm=` on macOS reports a *path* (`/usr/local/bin/claude`),
so the fallback takes the basename — callers compare against bare
names (see `xa.claude_fs._looks_like_claude()`) and must not have
to care which platform answered.

* **Return type:**
  [`str`](https://docs.python.org/3/builtins/stdtypes.html#str)

### xa.tmux.rename_session(old_name, new_name, , binary='tmux')

Rename a live tmux session.

Both names must match the strict `[A-Za-z0-9_.-]{1,48}` pattern
used elsewhere in `xa`; callers should validate before calling.

* **Return type:**
  [`None`](https://docs.python.org/3/builtins/constants.html#None)

### xa.tmux.send_keys(name, \*keys, binary='tmux')

Send one or more keys/strings to the targeted pane.

Always pass `"Enter"` for newline. `name` may be a session name
(targets its active pane) or a full pane ref for an exact pane.

* **Return type:**
  [`None`](https://docs.python.org/3/builtins/constants.html#None)

### xa.tmux.session_target(name)

Return the canonical target string for a session.

```pycon
>>> session_target('foo')
'foo:'
```

* **Return type:**
  [`str`](https://docs.python.org/3/builtins/stdtypes.html#str)


# about-this-build.html.md

<!-- generated by epythet -->

# About this build

This documentation was built on **2026-12-06 21:29 UTC** from commit <a href="https://github.com/addaix/xa/commit/60708691c022def80c61ccecf6eca8ee9a58d7c5"><code>6070869</code></a> on branch <code>main</code>, for **xa 0.1.22** (from <code>pyproject.toml</code>).

#### NOTE
Nothing suggests a mismatch: the tree was clean at the commit above, and the documented version is the one on PyPI.

## Source

|                     |                                                                                                                                                  |
|---------------------|--------------------------------------------------------------------------------------------------------------------------------------------------|
| Commit              | <a href="https://github.com/addaix/xa/commit/60708691c022def80c61ccecf6eca8ee9a58d7c5"><code>60708691c022def80c61ccecf6eca8ee9a58d7c5</code></a> |
| Branch              | <code>main</code>                                                                                                                                |
| Tags at this commit | none                                                                                                                                             |
| Working tree        | clean                                                                                                                                            |
| Remote              | <code>https://github.com/addaix/xa</code>                                                                                                        |

## Continuous integration

|              |                                                                                            |
|--------------|--------------------------------------------------------------------------------------------|
| Repository   | <code>addaix/xa</code>                                                                     |
| Run          | <a href="https://github.com/addaix/xa/actions/runs/47704021661">47704021661</a>            |
| Ref          | <code>refs/heads/main</code>                                                               |
| Event commit | <code>60708691c022def80c61ccecf6eca8ee9a58d7c5</code> (in the history of the built commit) |

## Tools

|          |         |
|----------|---------|
| epythet  | 0.2.26  |
| Sphinx   | 9.1.1   |
| docutils | 0.22.4  |
| Python   | 3.12.16 |

## Configuration as resolved

|               |                                                                  |
|---------------|------------------------------------------------------------------|
| theme         | <code>auto</code> (Sphinx theme <code>furo</code>)               |
| accent        | <code>#93342a</code>                                             |
| api_generator | <code>autosummary</code>                                         |
| ignore        | <code>tests/</code>, <code>scrap/</code>, <code>examples/</code> |
| agent_outputs | <code>true</code>                                                |
| aggregates    | <code>md</code>                                                  |
| ai_artifacts  | <code>true</code>                                                |

## Package on PyPI

Latest release: <a href="https://pypi.org/project/xa/0.1.22/">0.1.22</a>, the same as the documented version.

## Reproduce

```bash
git clone https://github.com/addaix/xa && cd xa
git checkout 60708691c022def80c61ccecf6eca8ee9a58d7c5
pip install "epythet==0.2.26"
epythet quickstart . --ignore tests/ scrap/ examples/
```

The same data, for machines: <a href="build_info.json"><code>build_info.json</code></a> (schema version 1).


# ai-agents.html.md

<!-- generated by epythet -->

# For AI agents

`xa` ships artifacts for coding agents alongside its code. This page lists
them, says where each lives in the repository, and points at the
machine-readable copies of this documentation.

## Skills

Skills are folders holding a `SKILL.md` (the [Agent Skills](https://agentskills.io) format): a description that tells an agent when to use it and a body with the procedure. Install one into your agent with `gh skill` (any host: `--agent claude-code`, `copilot`, `cursor`, `codex`, `gemini`), or use the copy bundled in the wheel.

### `xa-install`

Use when the user wants to install, configure, provision, secure, or troubleshoot `xa` — the cross-machine Claude Code session manager. Triggers on “install xa”, “set up xa on this server”, “configure xa hosts”, “start xa serve”, “xa from my phone”, “make xa accessible from my phone”, “secure xa”, “xa config”, or any request to use xa for the first time. Also use if the user asks why `xa list` is empty, why a remote host isn’t showing, why they can’t resume a session, or whether their xa deployment is safe.

```bash
gh skill install addaix/xa xa-install --agent claude-code
```

Source: [`xa/data/skills/xa-install`](https://github.com/addaix/xa/tree/HEAD/xa/data/skills/xa-install) (bundled with the pip package).

### `xa-dev`

Use when developing on or diagnosing the `xa` package (Claude Code session manager). Triggers on work under /root/py/proj/t/xa, edits to xa/xa/\*.py, failing tests, or questions about xa’s architecture, layering, or extension points. Not for using xa as an end user — that’s the shipped xa-install skill.

Source: [`.claude/skills/xa-dev`](https://github.com/addaix/xa/tree/HEAD/.claude/skills/xa-dev).

The bundled skills are also on disk after `pip install xa`, under the package’s `data/skills/` directory; link them into an agent without network access with `skill link-skills <that directory>`.

## Machine-readable documentation

This site publishes the same documentation in forms that fit an agent’s context window:

- [`llms.txt`](https://addaix.github.io/xa/llms.txt): an index of every page with a one-line description ([llms.txt](https://llmstxt.org) format)
- [`xa.md`](https://addaix.github.io/xa/xa.md): the whole documentation as one Markdown file
- `<page>.html.md`: a rendered Markdown twin of every page, advertised from each page’s `<head>` with `<link rel="alternate" type="text/markdown">`
- [`objects.inv`](https://addaix.github.io/xa/objects.inv): the Sphinx inventory: a symbol-to-URL index (`sphobjinv convert plain objects.inv -`)


# api.html.md

# API reference

| [`xa`](_autosummary/xa.html.md#module-xa)   | xa — tools for managing remote Claude Code sessions.   |
|-----------------------------------------------------------------|--------------------------------------------------------|


