Documentation
¶
Overview ¶
Package rewrite adapts a copied session to the target machine.
It applies a single-pass prefix map (repo root, worktree, home, config dir) to every JSON string in the transcript, keys included, on path boundaries. It handles JSON-escaped Windows paths and paths that follow JSON escapes, converts separators below mapped folders between Windows and macOS/Linux, and never edits ids or signed thinking blocks (dropping them whole only for cross-account moves). It strips the source's Remote Control link record, optionally redacts secrets, and appends a `relocated` record the way Claude Code's own /cd does.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Mapping ¶
type Mapping struct {
From string `json:"from"`
To string `json:"to"`
// ToSep, when set ("/" or `\`), also converts the path separators that follow a
// match (for moves between Windows and macOS/Linux). The rest of the path ends at the
// first byte that cannot be part of a file name segment, such as a space or quote.
ToSep string `json:"toSep,omitempty"`
}
Mapping replaces one absolute path prefix with another (unescaped paths).
type Options ¶
type Options struct {
Mappings []Mapping
// DropThinking removes thinking / redacted_thinking blocks entirely. Required when the
// target machine is signed in to a different Anthropic account: those blocks carry
// signatures bound to the original account, and removing only the signature fails.
DropThinking bool
// StripBridge drops bridge-session records so the copy does not reattach to the source
// session's Remote Control link.
StripBridge bool
// DropMovedMarks drops the "↪ moved to …" title records hopsesh writes on a copy left
// behind, so a copy taken from such a machine shows its real title again.
DropMovedMarks bool
// RenameSession gives the copy a new session id ({old, new}): sessionId fields and the
// id inside paths change; signed content and message ids do not. Used to keep both
// copies when two machines changed the same session.
RenameSession [2]string
// AppendTitle, when set, appends a custom-title record (after the relocated one).
AppendTitle string
// AppendRelocated appends {"type":"relocated",...} the way Claude Code's /cd does, so
// readers of the last 64 KB see the new project directory.
SessionID string
RelocatedCWD string
// Redact, if set, is applied to every rewritable string token (raw JSON bytes) after path
// mapping; it returns the new bytes and how many secrets it replaced.
Redact func(raw []byte) ([]byte, int)
}
Options controls a transcript rewrite.
type Stats ¶
type Stats struct {
Lines int `json:"lines"`
LinesChanged int `json:"linesChanged"`
Replacements map[string]int `json:"replacements"` // by Mapping.From
DroppedBridge int `json:"droppedBridge"`
DroppedMarks int `json:"droppedMoveMarks,omitempty"`
RenamedIDs int `json:"renamedIds,omitempty"`
DroppedThinking int `json:"droppedThinking"`
Redactions int `json:"redactions"`
AppendedRelocate bool `json:"appendedRelocated"`
}
Stats reports what a rewrite changed.