claude

package
v0.4.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 10, 2026 License: Apache-2.0 Imports: 29 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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

View Source
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

func Slug(path string) string

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 New

func New() *Module

New returns the 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) CloudURL added in v0.4.0

func (m *Module) CloudURL(_ string, id agent.SessionID) string

CloudURL is the session's page on claude.ai.

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) Detect

func (m *Module) Detect(_ context.Context, h agent.Host) (agent.Install, error)

Detect resolves the config folder and the claude binary.

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

func (m *Module) Integration(h agent.Host, in agent.Install) agent.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

func (m *Module) List(ctx context.Context, h agent.Host, in agent.Install) (agent.Listing, error)

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

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

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 (m *Module) ParseCloudLink(s string) (string, agent.SessionID, bool)

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

func (m *Module) Profile(agent.Install) ir.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 (m *Module) RecoverWrite(ctx context.Context, h agent.Host, in agent.Install, req ir.WriteRequest) (ir.WriteResult, error)

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

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

func (m *Module) SessionWatchPaths(in agent.Install, pa agent.Path) []string

SessionWatchPaths excludes logs, credentials and unrelated caches.

func (*Module) Spec

func (*Module) Spec() agent.Spec

Spec declares Claude Code.

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 (m *Module) VerifyAppFocus(ctx context.Context, h agent.Host, in agent.Install, key agent.SessionKey) error

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).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL