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; this module
composes them into a host-agnostic API.
Functions
|
Find one session by full ID or unique prefix. |
|
Legacy local-only iterator. |
|
Kill a live |
|
|
|
Return sessions sorted by recency (live first, then newest-modified). |
|
Resume a transcript / archived session on its originating host, as it was launched. |
|
|
Classes
|
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)[source]¶
Bases:
objectCanonical 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[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)[source]¶
Find one session by full ID or unique prefix.
Raises
LookupErrorif the prefix is ambiguous.
- xa.sessions.iter_local_sessions(*, claude_home=PosixPath('/home/runner/.claude'), project_slug=None, include_live=True, tmux_bin=None)[source]¶
Legacy local-only iterator.
Retained for backward compatibility and because some tests construct sessions directly from a fake
~/.claude/. Wraps a freshLocalHost.
- xa.sessions.kill_session(session, *, hosts=None)[source]¶
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:
- xa.sessions.launch_opts(facts, *, claude_home=PosixPath('/home/runner/.claude'), permission_mode=None, euid=None)[source]¶
(resume kwargs, warning)that bringfactsback 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;euidstands in for the process’s own when deciding whether bypass is refused.
- xa.sessions.list_sessions(*, hosts=None, project=None, include_forks=True, include_live=True, state=None, limit=None, claude_home=None, tmux_bin=None)[source]¶
Return sessions sorted by recency (live first, then newest-modified).
When
hostsisNonewe default to a singleLocalHost. Ifclaude_homeortmux_binare given, they’re forwarded into that defaultLocalHost— handy for fixture-based tests.Filters:
project— substring match againstcwd(case-insensitive)include_forks=False— drop sessions with aforked_frominclude_live=False— skip live discovery (per host)state— one of"live"/"archived"/"transcript_only"
- xa.sessions.resume(session, *, cwd=None, name=None, hosts=None, **opts)[source]¶
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-permissionscomes 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’swarningsays 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:
- 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)[source]¶
(shell command, warning)that resumesfacts’ session as it was launched.The one place that assembles the line:
cdinto the cwd it was started in, the account’s environment (claude_home),--resume <id>, the permission flags and the model (launch_opts()), every token shell-quoted. The command is for a fresh shell and carries no secret. It never runsclaude_bin: every flag is written, so run it where that claude is new enough (xa.claude_cli.prepare_spawn()is what probes).warningis what had to be dropped (bypass refused to root), elseNone.>>> 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)