Documentation
¶
Overview ¶
Package claude is the Claude Code module: sessions are JSON-lines transcripts under <config>/projects/<slug of the working directory>/<id>.jsonl, with side folders for subagents and spilled tool output, and file backups under <config>/file-history/<id>.
Index ¶
- Constants
- Variables
- func Slug(path string) string
- type Module
- func (m *Module) Account(ctx context.Context, h agent.Host, in agent.Install) (agent.Account, error)
- func (m *Module) Adopted(_ context.Context, h agent.Host, in agent.Install, a agent.Adopt) (agent.Adoption, error)
- func (m *Module) Bundle(_ context.Context, h agent.Host, in agent.Install, s agent.Summary) (agent.Bundle, error)
- func (*Module) CheckApp(in agent.Install, key agent.SessionKey, o agent.ResumeOptions) error
- func (m *Module) CloudURL(_ string, id agent.SessionID) string
- func (m *Module) ContextCapacity(ctx context.Context, h agent.Host, in agent.Install, s *agent.Summary) (ir.Capacity, error)
- func (m *Module) Detect(_ context.Context, h agent.Host) (agent.Install, error)
- func (m *Module) FetchCloud(ctx context.Context, h agent.Host, in agent.Install, sid agent.SessionID, ...) (agent.Fetched, error)
- func (m *Module) Integration(h agent.Host, in agent.Install) agent.Integration
- func (m *Module) List(ctx context.Context, h agent.Host, in agent.Install) (agent.Listing, error)
- func (m *Module) ListCloud(ctx context.Context, h agent.Host, in agent.Install, q agent.CloudQuery) (agent.CloudListing, error)
- func (m *Module) Live(ctx context.Context, h agent.Host, in agent.Install, ids []agent.SessionID) (map[agent.SessionID]agent.LiveInfo, error)
- func (m *Module) MovementHooks(h agent.Host, in agent.Install, bin string, args ...string) agent.HookIntegration
- func (m *Module) ParseCloudLink(s string) (string, agent.SessionID, bool)
- func (m *Module) PlanMove(src, dst agent.Install, s agent.Summary, b agent.Bundle, p agent.Placement) (agent.MovePlan, error)
- func (m *Module) Preview(ctx context.Context, h agent.Host, in agent.Install, s agent.Summary, n int) (agent.Preview, error)
- func (m *Module) Profile(agent.Install) ir.Profile
- func (m *Module) Read(ctx context.Context, h agent.Host, in agent.Install, s agent.Summary, ...) (ir.Segment, error)
- func (m *Module) ReadStep(cl string, out agent.StepOutput) (agent.CloudSession, error)
- func (m *Module) RecoverWrite(ctx context.Context, h agent.Host, in agent.Install, req ir.WriteRequest) (ir.WriteResult, error)
- func (m *Module) Rename(_ context.Context, h agent.Host, in agent.Install, s agent.Summary, ...) error
- func (m *Module) Resume(in agent.Install, key agent.SessionKey, p agent.Placement, ...) agent.Command
- func (m *Module) Sanitize() agent.RewritePolicy
- func (m *Module) SendCloud(ctx context.Context, h agent.Host, _ agent.Install, r agent.SendRequest) (agent.Sent, error)
- func (m *Module) SessionWatchPaths(in agent.Install, pa agent.Path) []string
- func (*Module) Spec() agent.Spec
- func (m *Module) Stop(ctx context.Context, h agent.Host, in agent.Install, s agent.Summary, ...) error
- func (m *Module) TestCloud(ctx context.Context, h agent.Host, _ agent.Install, _ string) (agent.CloudTest, error)
- func (m *Module) Verify(_ context.Context, h agent.Host, mp agent.MovePlan, staged map[string]string, ...) error
- func (m *Module) VerifyAppFocus(ctx context.Context, h agent.Host, in agent.Install, key agent.SessionKey) error
- func (m *Module) Write(ctx context.Context, h agent.Host, in agent.Install, req ir.WriteRequest) (ir.WriteResult, error)
Constants ¶
const CopyNote = "Claude Code saves its copy only after you send a message in it: send one (even \"ok\"), and hopsesh picks the copy up"
CopyNote is what the user must know at the teleport: Claude Code writes the copy only once a message is sent in it.
Variables ¶
var ErrStillRunning = errors.New("the session did not exit in time; quit it yourself (type /exit in it), then try again")
ErrStillRunning means a stopped session did not exit in time.
Functions ¶
func Slug ¶
Slug returns the project folder name Claude Code uses for a resolved working directory: every UTF-16 code unit that is not [A-Za-z0-9] becomes '-', and names longer than 200 units are cut to 200 and suffixed with "-" plus the base-36 absolute value of the Java String.hashCode of the full path. The path is NFC-normalised first, as Claude Code does.
Types ¶
type Module ¶
type Module struct{}
Module is the Claude Code module.
func (*Module) Account ¶
func (m *Module) Account(ctx context.Context, h agent.Host, in agent.Install) (agent.Account, error)
Account asks claude which login it uses (it reads its own credentials; hopsesh never does). The key is a hash of the organisation id.
func (*Module) Adopted ¶ added in v0.4.0
func (m *Module) Adopted(_ context.Context, h agent.Host, in agent.Install, a agent.Adopt) (agent.Adoption, error)
Adopted finds the copy a teleport wrote in the worktree's project folder: a transcript written after a.Since that holds the "continued from another machine" record, or a teleported-from record naming the session (any such record when a.Session is empty: the picker chose). Failing both, the one transcript written there since (the worktree is hopsesh's own, so nothing else runs in it). It counts the cloud's messages (a reply split over several records counts once; the user's own new turn after the marker does not count), and reads the first user message, so the core can check the copy begins where the hand-off began. Only a teleported-from record states a count.
func (*Module) Bundle ¶
func (m *Module) Bundle(_ context.Context, h agent.Host, in agent.Install, s agent.Summary) (agent.Bundle, error)
Bundle is the transcript, its side folder and its file-history backups.
func (*Module) CheckApp ¶ added in v0.4.0
func (*Module) CheckApp(in agent.Install, key agent.SessionKey, o agent.ResumeOptions) error
func (*Module) ContextCapacity ¶ added in v0.4.0
func (m *Module) ContextCapacity(ctx context.Context, h agent.Host, in agent.Install, s *agent.Summary) (ir.Capacity, error)
ContextCapacity follows only the resumed branch. Native usage measures the last completed prompt; later records use a conservative byte upper estimate. A compaction summary resets that baseline. Unknown models keep the small fallback.
func (*Module) FetchCloud ¶ added in v0.4.0
func (m *Module) FetchCloud(ctx context.Context, h agent.Host, in agent.Install, sid agent.SessionID, t agent.FetchTarget) (agent.Fetched, error)
FetchCloud brings a cloud session into the worktree the core made (t.Dir) with `claude --teleport <id>`, which needs the user's terminal: it checks the login first, then returns the command and where Claude Code will write its copy of the conversation (the project folder of the worktree, under the config folder). An empty id leaves the choice to Claude Code's own picker. Teleport fetches and checks out the session's branch itself.
func (*Module) Integration ¶
Integration says where things go: the skill in <config>/skills, and approval rules as permission rules in <config>/settings.json, merged with what the user has there.
func (*Module) List ¶
List summarises every transcript under <config>/projects, newest first. Subagent-only and bookkeeping-only transcripts are left out, as Claude Code's own picker does.
func (*Module) ListCloud ¶ added in v0.4.0
func (m *Module) ListCloud(ctx context.Context, h agent.Host, in agent.Install, q agent.CloudQuery) (agent.CloudListing, error)
ListCloud lists what hopsesh can know of Claude Code's cloud without a list command (Claude Code has none; `claude --teleport` without an id is an interactive picker): the sessions hopsesh recorded or was given (q.Known), and the local sessions Remote Control mirrors on claude.ai, as Mirror entries. It first checks the login the cloud needs. The listing is always Partial, and it cannot tell a session's state, so that is unknown.
func (*Module) Live ¶
func (m *Module) Live(ctx context.Context, h agent.Host, in agent.Install, ids []agent.SessionID) (map[agent.SessionID]agent.LiveInfo, error)
Live reports open sessions from Claude Code's process registry. One session can run in several processes (a terminal and the Claude app); all of them are in Procs, and the main one (a waiting one first, then the latest to write its entry) gives PID, Status and App.
func (*Module) MovementHooks ¶ added in v0.4.0
func (m *Module) MovementHooks(h agent.Host, in agent.Install, bin string, args ...string) agent.HookIntegration
MovementHooks uses documented synchronous command hooks, never prompt/agent hooks. 2.1.284 is our conservative compatibility baseline, not their introduction. Windows explicitly selects the documented PowerShell shell, avoiding Git Bash availability/default-shell ambiguity. Contract checked 2026-10-06: https://code.claude.com/docs/en/hooks
func (*Module) ParseCloudLink ¶ added in v0.4.0
ParseCloudLink reads a claude.ai/code link, a session_… id or its cse_… form.
func (*Module) PlanMove ¶
func (m *Module) PlanMove(src, dst agent.Install, s agent.Summary, b agent.Bundle, p agent.Placement) (agent.MovePlan, error)
PlanMove puts the transcript in the target working directory's project folder, renames the session for keep-both copies, and appends the records Claude Code itself writes when a session changes folder (relocated) or is renamed (custom-title).
func (*Module) Preview ¶ added in v0.4.0
func (m *Module) Preview(ctx context.Context, h agent.Host, in agent.Install, s agent.Summary, n int) (agent.Preview, error)
Preview reads the end of the transcript's active branch: from the newest message back along parentUuid, within a tail window of the file (never the whole of it).
func (*Module) Profile ¶
Profile says Claude Code takes long histories, and tool calls can be replayed natively.
func (*Module) Read ¶
func (m *Module) Read(ctx context.Context, h agent.Host, in agent.Install, s agent.Summary, from ir.Cursor) (ir.Segment, error)
Read lifts the transcript's active branch (from the leaf Claude Code would resume back to the start) into IR. From a cursor it returns only the nodes after cursor.Head, which must still be on the branch (ErrDiverged otherwise).
func (*Module) ReadStep ¶ added in v0.4.0
func (m *Module) ReadStep(cl string, out agent.StepOutput) (agent.CloudSession, error)
ReadStep reads the cloud session `claude --cloud` started from what it printed: the session's link (View: …), checked against the teleport command it suggests (Resume with: …), or its refusal. A line as wide as the terminal may go on in the next (Claude Code breaks long lines), so the link is read across such a break.
func (*Module) RecoverWrite ¶ added in v0.4.0
func (*Module) Rename ¶ added in v0.4.0
func (m *Module) Rename(_ context.Context, h agent.Host, in agent.Install, s agent.Summary, title string) error
Rename retitles the session with a custom-title record, what /rename writes, keeping the file's time (a legacy title label goes with the old title).
func (*Module) Resume ¶
func (m *Module) Resume(in agent.Install, key agent.SessionKey, p agent.Placement, o agent.ResumeOptions) agent.Command
Resume is `claude [--desktop] --resume <id> [--fork-session] [--remote-control [name]]`.
func (*Module) Sanitize ¶
func (m *Module) Sanitize() agent.RewritePolicy
Sanitize removes thinking blocks for a machine signed in to another account: their signatures are bound to the original account, and removing only the signature fails.
func (*Module) SendCloud ¶ added in v0.4.0
func (m *Module) SendCloud(ctx context.Context, h agent.Host, _ agent.Install, r agent.SendRequest) (agent.Sent, error)
SendCloud checks the login, then returns the command that starts the cloud session with the briefing as its first prompt: `claude --cloud <brief>` in r.Dir, whose current branch is the handoff branch (claude clones the remote's copy of it). With r.Code ViaBundle it sets CCR_FORCE_BUNDLE=1, and Claude Code uploads the repository instead. The command runs without CLAUDE_CODE_CHILD_SESSION and ANTHROPIC_API_KEY.
func (*Module) SessionWatchPaths ¶ added in v0.4.1
SessionWatchPaths excludes logs, credentials and unrelated caches.
func (*Module) Stop ¶
func (m *Module) Stop(ctx context.Context, h agent.Host, in agent.Install, s agent.Summary, grace time.Duration) error
Stop asks every process that has the session open to exit (SIGTERM lets each finish writing its transcript). The registry is read again first, so a recycled pid is never signalled.
func (*Module) TestCloud ¶ added in v0.4.0
func (m *Module) TestCloud(ctx context.Context, h agent.Host, _ agent.Install, _ string) (agent.CloudTest, error)
TestCloud checks the login teleport needs (claude auth status --json) and that `claude --help` still has the flags this module uses. It starts no session.
func (*Module) Verify ¶
func (m *Module) Verify(_ context.Context, h agent.Host, mp agent.MovePlan, staged map[string]string, p agent.Placement) error
Verify reads the staged transcript back: it must open in the target folder.
func (*Module) VerifyAppFocus ¶ added in v0.4.0
func (*Module) Write ¶
func (m *Module) Write(ctx context.Context, h agent.Host, in agent.Install, req ir.WriteRequest) (ir.WriteResult, error)
Write emits Claude Code transcript records: a chain of user and assistant records with the envelope Claude Code needs to resume, a title, and a last-prompt record naming the new leaf (Claude Code resumes from the leaf its newest last-prompt names).