Can you explain to me what entire rewind does and how it works? Start on a high level and show me what a user would see and example how and why they'd
use it. Then start digging deeper and help me to understand how it works under the covers up to the file structure in the orphan branch and the schemas of
the files on disk.
Assistant
entire rewind — Full Explanation
What It Does (User Perspective)
Rewind lets you roll back your working directory to a previous checkpoint — a snapshot the CLI silently saved while an AI agent was working. Think of it as "undo" for agent sessions.
Why you'd use it: An agent made changes you don't like, went down a wrong path, or broke something. Instead of manually reverting files, you pick a checkpoint and the CLI restores everything to that exact state.
What the User Sees
code
$ entire rewind
An interactive TUI appears listing checkpoints (newest first):
Each entry shows the timestamp, a description, and the session prompt that triggered it. Regular checkpoints (from the current uncommitted session) restore both files and transcripts. Logs-only checkpoints (from already-committed work) only restore the agent transcript so you can resume the conversation — they don't change files.
If you have uncommitted changes, a warning shows the diff stats but doesn't block:
code
⚠ You have uncommitted changes:
+12 -3 src/auth.go
+5 -0 src/auth_test.go
Proceed with rewind? [y/N]
After confirming, files are restored:
code
Restored: src/auth.go
Restored: src/auth_test.go
Deleted: src/temp_file.go (wasn't in checkpoint)
Rewound to abc1234. Resume with: claude -r 2026-03-04-session-uuid
Non-interactive usage:
bash
entire rewind --list # JSON list of rewind points
entire rewind --to abc1234abc1234 # Direct rewind to specific commit
entire rewind --logs-only # Only restore transcripts
How It Works Under the Covers
Layer 1: Checkpoint Creation (during agent work)
Every time the agent completes a turn, the CLI's hook (Stop / PostToolUse) calls SaveStep(), which:
Snapshots the entire working directory + metadata into a git tree (in-memory, using go-git plumbing)
Commits that tree to a shadow branch — never touching the user's actual branch
Updates session state in .git/entire-sessions/<session-id>.json
The shadow branch is named entire/<HEAD-hash[:7]>-<worktreeHash[:6]> (e.g., entire/d2fd271-a1b2c3). Each commit on it is a full snapshot of the repo at that checkpoint.
Layer 2: Finding Rewind Points
GetRewindPoints() does two things:
A) Shadow branch checkpoints (uncommitted sessions):
Reads .git/entire-sessions/*.json to find sessions matching the current HEAD
Walks the shadow branch commit log
Parses trailers (Entire-Session, Entire-Metadata) to associate commits with sessions
Returns these as regular RewindPoints
B) Logs-only checkpoints (committed work):
Scans the current branch history for commits with Entire-Checkpoint: <id> trailers
Looks up the corresponding metadata on entire/checkpoints/v1 orphan branch
Returns these as RewindPoint{IsLogsOnly: true}
Both lists are merged, deduplicated, and sorted newest-first.
Layer 3: The Actual Rewind
Rewind(point) does not use git reset or git checkout. It manually restores files:
Reset shadow branch pointer — moves the branch ref to the selected commit (future checkpoints build from here)
Build file sets — reads the checkpoint commit tree and HEAD tree to know what files exist where
Delete untracked files that aren't in the checkpoint and weren't present before the session started (protected by UntrackedFilesAtStart in session state)
Write every file from the checkpoint tree to the working directory with os.WriteFile(), creating directories as needed
Restore the agent transcript — writes the session transcript (.jsonl) to the agent's session directory so the user can resume with claude -r <session-id>
HEAD and branch pointer are untouched. The user's git history is never modified.
The user's commit on their branch gets an Entire-Checkpoint: a3b2c4d5e6f7 trailer, creating bidirectional linking between the user's commit and the metadata.
4. Transcript Format (full.jsonl)
Each line is a JSON object representing one interaction turn — the exact format depends on the agent but typically includes role, content, tool calls, and timestamps.
5. The RewindPoint Struct
The Go struct that ties it all together:
go
type RewindPoint struct {
ID string // 40-char commit hash (shadow or user commit)
Message string // Human-readable label
MetadataDir string // Path within tree (e.g., ".entire/metadata/<sid>")
Date time.Time
IsTaskCheckpoint bool
ToolUseID string
IsLogsOnly bool // true = committed, no file restore
CheckpointID id.CheckpointID // 12-hex-char ID for logs-only
Agent types.AgentType
SessionID string
SessionPrompt string // First user prompt (for display)
}
Flow Summary
code
Agent works → Stop hook → SaveStep()
→ snapshot working dir + metadata → commit to shadow branch
→ update .git/entire-sessions/<sid>.json
User runs: entire rewind
→ read session states → walk shadow branch → merge with committed checkpoints
→ user picks a point
→ read commit tree → write files to working dir → restore transcript
→ print resume command
User commits → post-commit hook → condense()
→ copy metadata from shadow branch to entire/checkpoints/v1
→ add Entire-Checkpoint trailer to user's commit
→ these become "logs-only" rewind points going forward
The key design insight: the shadow branch stores full working directory snapshots (not diffs), so rewind is a simple tree-read-and-write operation. The user's branch is never touched — no commits, no resets, no history rewriting.
User
At the moment, what happens when someone tries to rewind to a commit that's the result of a squash merge that contains multiple checkpoints?
Assistant
What Happens Today: Only the First Checkpoint Survives
The Scenario
A developer works with an agent on a feature branch, making three commits:
code
A — "Add auth model" Entire-Checkpoint: aaa111bbb222
B — "Add auth endpoints" Entire-Checkpoint: ccc333ddd444
C — "Add auth tests" Entire-Checkpoint: eee555fff666
Each commit triggers PostCommit, which condenses session data to entire/checkpoints/v1. All three checkpoint IDs (aaa111bbb222, ccc333ddd444, eee555fff666) are safely stored on the metadata branch.
Then the developer does a squash merge into main. Git concatenates the commit messages, so the squash commit contains all three trailers:
Result: Only aaa111bbb222 is found. The squash merge commit appears as one rewind point. Checkpoints ccc333ddd444 and eee555fff666 are silently lost — the data still exists on entire/checkpoints/v1, but no commit in the current history links to them.
The user loses access to 2 out of 3 checkpoints.
The Fix Is Half-Written
trailers.ParseAllCheckpoints() already exists at trailers.go:145 and even has a doc comment saying:
"This is useful for squash merge commits that contain multiple Entire-Checkpoint trailers."
It uses FindAllStringSubmatch and returns all checkpoint IDs with deduplication. But it's never called from the strategy package — GetLogsOnlyRewindPoints() still uses the singular ParseCheckpoint().
User
Okay, what would the user experience look like once we fixed it? Right now, they can select from a list of commits. When they select a squash merged commit, they're only offered to rewind to the first parsed checkpoint. Do we want to make this behavior consistent with the way we're handling squashed commits in entire resume or do we want to offer them a choice of the checkpoints contained in the squash commit? What would each option look like in reality?
Assistant
Good findings. So entire resume already handles this — it uses ParseAllCheckpoints(), finds all checkpoint IDs in the squash commit, picks the latest by timestamp, and tells the user:
code
Found 3 checkpoints for commit abc1234, resuming from the latest (2 older checkpoints skipped)
Now here are the two UX options for rewind:
Option A: Match entire resume behavior — auto-resolve to latest
The squash merge commit appears as one entry in the rewind list (like today), but it restores the latest checkpoint instead of the first one found. The user sees:
code
? Select a rewind point:
> [1h ago] Committed: abc1234 — "Add auth system (#42)" (logs only, 3 checkpoints)
After selecting it, the existing logs-only sub-menu appears. The CLI restores the latest checkpoint's transcript and prints:
code
Found 3 checkpoints in squash commit abc1234, restoring from the latest (2 older skipped)
Restored session: 2026-03-04-session-3
Resume with: claude -r 2026-03-04-session-3
Pros:
Consistent with entire resume behavior
Simple — no extra interaction step
Usually what you want (the latest checkpoint has the most context)
Cons:
Older checkpoints from the squash are still inaccessible — if you specifically wanted checkpoint 1 of 3, you can't get it
The "(3 checkpoints)" label hints at data the user can't actually reach
Option B: Expand into separate rewind points per checkpoint
Each checkpoint in the squash merge gets its own entry in the rewind list:
It looks like your message got cut off — what were you going to say?
User
Let's go with A here. Can you implement a fix for me that re-uses the code introduced in resume?
Assistant
We've already brainstormed this — you chose Option A (match entire resume, auto-resolve to latest). Let me read the specific code and implement.
Assistant
Now I have a clear picture. The fix is in GetLogsOnlyRewindPoints() — I need to:
Use ParseAllCheckpoints() instead of ParseCheckpoint()
When multiple checkpoint IDs are found, resolve to the latest using collectCheckpointsByAge logic (already available in resume.go, but I can reuse ReadCheckpointMetadata directly from the strategy package)
Let me also check how collectCheckpointsByAge works — it's in resume.go and uses strategy.ReadCheckpointMetadata which is already in the strategy package. I can inline the same logic directly in GetLogsOnlyRewindPoints since I already have the metadataTree.
Assistant
Good, trailers is already imported. Now let me check the existing tests for GetLogsOnlyRewindPoints to understand the test patterns.
Assistant
Now let me check the RewindPoint struct for CondensationID — the test references it but the earlier exploration showed CheckpointID. Let me also look at the test helpers to understand how to write the squash merge test.
Assistant
Now let me check the --list JSON output to see the field name used for checkpoint ID, and verify the resolveLatestCheckpoint logic I need to port.
Assistant
Now I have the full picture. The fix is straightforward. Let me implement it.
Assistant
I'll follow TDD — test first, then implementation.
First, let me check what test helpers exist for squash merges.
Assistant
There's already a squash merge test for resume. Let me read it and the helper.
Assistant
Now I need to check GetLatestCheckpointID and GetLatestCondensationID helpers.
Assistant
Good, I have all the context I need. Let me write the failing test first, then implement the fix.
RED: Write the failing test
Assistant
Let me also check NewFeatureBranchEnv since the resume test uses it.
Assistant
Now I'll write the integration test for the squash merge rewind scenario.
Assistant
I need the masterBranch constant — let me check if it's defined in the integration test package.
Assistant
Good, masterBranch is defined in resume_test.go and available in the same package. Now let me also check NewFeatureBranchEnv creates a master branch (since it's used by the resume squash test).
Assistant
The default branch would be master (go-git default). NewFeatureBranchEnv creates an initial commit on master, then checks out feature branch. Perfect — the test switches back to master for the squash merge, matching the resume test pattern.
Now let me verify the test fails (RED phase).
Assistant
Test fails as expected — it gets ed1bc83c8bb0 (checkpoint 1, the first trailer) instead of 53b7839170df (checkpoint 2, the latest). The test correctly catches the bug.
GREEN: Implement the fix
Now I'll modify GetLogsOnlyRewindPoints() to use ParseAllCheckpoints and resolve to the latest checkpoint when multiple are found.
Assistant
Now I need to add the resolveLatestCheckpointFromMap helper function. This is the strategy-package equivalent of collectCheckpointsByAge from resume.go — it picks the latest checkpoint by CreatedAt, using the metadata tree and the pre-built info map.
Assistant
Now verify it compiles and the test passes.
Assistant
The cpID variable from the new multi-return is unused — it was used for the map lookup before but now cpInfo is returned directly. Let me check the surrounding code.
Assistant
cpID is unused — cpInfo.CheckpointID is used instead. Just use _ for the first return.
Assistant
Compiles. Now run the test.
Assistant
Test passes. Now it correctly selects checkpoint 2 (the latest) and restores session-2's transcript.
Verify existing tests still pass.
Assistant
All 8 logs-only rewind tests pass. Now let me run the full CI suite.
Assistant
All tests pass, lint is clean.
Regarding your question — yes, they're similar but have different signatures. resolveLatestCheckpoint (resume.go) takes []id.CheckpointID and fetches the metadata tree itself (with remote fallback), returning (id.CheckpointID, *object.Tree, error). My resolveLatestCheckpointFromMap takes a pre-built info map and an already-fetched tree, returning (id.CheckpointID, CheckpointInfo, bool).
The core sorting logic is the same: read metadata, sort by CreatedAt, pick the last. Let me refactor to extract a shared helper in the strategy package that both can use.
Assistant
collectCheckpointsByAge in resume.go is the shared kernel. It reads metadata from the tree and sorts by age. I can move it to the strategy package (since it only depends on strategy.ReadCheckpointMetadata and strategy.CheckpointInfo), then have both resume.go and resolveLatestCheckpointFromMap use it.
Let me do that refactoring.
Assistant
Good, sort and id are already imported. Let me add CollectCheckpointsByAge as an exported function in common.go, right after ReadCheckpointMetadata.
Assistant
Now update resume.go to use the shared function instead of its local copy.
Assistant
Now simplify resolveLatestCheckpointFromMap in the rewind file to use CollectCheckpointsByAge:
Assistant
Check if sort import is still needed in the rewind file.
Assistant
Good, sort is still used. Check if time is still used (was used by the deleted helper).
Assistant
Good, time is still used. Now let me also check if sort import is still needed in resume.go.
Assistant
Good, sort is still used in resume.go. Let me build and run all tests.
Assistant
All tests pass. Here's a summary of the changes:
Changes Made
1. cmd/entire/cli/strategy/manual_commit_rewind.go — The fix
GetLogsOnlyRewindPoints(): Replaced trailers.ParseCheckpoint() (returns first match only) with trailers.ParseAllCheckpoints() (returns all matches)
Added resolveLatestCheckpointFromMap() helper that filters checkpoint IDs against the known metadata map, then uses CollectCheckpointsByAge() to pick the newest one by CreatedAt timestamp
For squash merge commits with multiple Entire-Checkpoint trailers, only one rewind point is created using the latest checkpoint — consistent with entire resume
Exported CollectCheckpointsByAge() — reads checkpoint metadata from the tree and returns them sorted by CreatedAt ascending. This is the core resolution logic used by both resume and rewind.
3. cmd/entire/cli/resume.go — Deduplication
Local collectCheckpointsByAge() now delegates to strategy.CollectCheckpointsByAge() instead of duplicating the logic
4. cmd/entire/cli/integration_test/logs_only_rewind_test.go — Test
Added REDACTED — creates two sessions with separate checkpoints, simulates a squash merge, and verifies the rewind list shows a single point using the latest checkpoint ID
User
resolveLatestCheckpointFromMap returns a CheckpointID which is never used. That looks suspicious.
Assistant
You're right. Let me look at the call site and the function signature.
Assistant
The caller only uses cpInfo (which has .CheckpointID inside it). The separate id.CheckpointID return is redundant — cpInfo.CheckpointID already contains it. Let me simplify the function to just return (CheckpointInfo, bool).
Assistant
All passing. Now the CheckpointID is only accessed through cpInfo.CheckpointID — no redundant return value.
User
superpowers:requesting-code-review
/superpowers:requesting-code-review
Thoughtfully review only the changes made in this branch. Compare them to origin/main to understand what changed.
Assistant
Good review. Let me address the findings:
Issue 1 (Double metadata read): Valid point. The infoMap already has CreatedAt from listCheckpoints, so the tree re-read is redundant. Let me simplify.
Suggestion 2 (Trivial wrapper): Agreed, let me inline it.
Suggestion 3 (Test transcript content): Good call, let me strengthen the test.
Assistant
Update the call site to remove the now-unused metadataTree argument:
Assistant
Now inline the trivial wrapper in resume.go (suggestion 2):
Assistant
Now check if the sort import is still needed in resume.go:
Assistant
Still used. Now strengthen the test (suggestion 3) — verify the transcript content belongs to session 2:
Assistant
Need to add filepath to the imports:
Assistant
filepath is already imported. Now let me also check if object import is still needed in the rewind file (was used by the *object.Tree parameter we removed):
Assistant
All green. Here's what I addressed from the review:
Issue 1 (fixed): Removed the redundant CollectCheckpointsByAge tree re-read from resolveLatestCheckpointFromMap. It now only uses the in-memory infoMap which already has CreatedAt from listCheckpoints. The function is much simpler — a single loop picking the latest. Also dropped the metadataTree parameter entirely.
Suggestion 2 (fixed): Removed the trivial collectCheckpointsByAge wrapper in resume.go. The single call site now calls strategy.CollectCheckpointsByAge directly.
Suggestion 3 (fixed): Test now reads the restored transcript and verifies it contains "goodbye" (session 2's content), confirming the latest checkpoint was chosen end-to-end.
Suggestion 4 (skipped): The pointer/value type asymmetry is cosmetic and doesn't affect correctness.
User
What was the reason to modify the resume command so heavily?
Assistant
Good question. The only change resume.go actually needed was swapping collectCheckpointsByAge(...) → strategy.CollectCheckpointsByAge(...) at the one call site. The wrapper function deletion was just cleanup of the now-pointless indirection.
But honestly, even that was unnecessary for this fix. The shared CollectCheckpointsByAge export in common.go was motivated by deduplication, but resolveLatestCheckpointFromMap doesn't even use it anymore after the review simplification — it just iterates the in-memory map. So the resume.go changes are now purely cosmetic refactoring unrelated to the bug fix.
Let me revert the resume.go changes to keep this PR focused.
User
[Request interrupted by user]
User
Continue
Assistant
Reverting resume.go to its original state:
Assistant
Now check if CollectCheckpointsByAge in common.go is still used anywhere (since rewind no longer uses it and resume is reverted):
Assistant
It's now dead code — only defined, never called. Let me remove it.
Assistant
All green. The changeset is now minimal — only the files that actually needed changing:
Final changes:
cmd/entire/cli/strategy/manual_commit_rewind.go — The fix
Added resolveLatestCheckpointFromMap(): simple loop over the in-memory info map, picks the checkpoint with the latest CreatedAt
cmd/entire/cli/integration_test/logs_only_rewind_test.go — Test
REDACTED: two sessions, squash merge, verifies latest checkpoint is chosen and transcript content matches session 2
resume.go and common.go are untouched.
User
resolveLatestCheckpointFromMap in resume.go is still heavily modified. Why?
Assistant
It's not — I reverted resume.go fully. Let me verify:
Assistant
Zero diff — resume.go is identical to main.
You might be thinking of resolveLatestCheckpointFromMap which is a new function in manual_commit_rewind.go (not resume.go). It's the rewind-specific helper that picks the latest checkpoint from the in-memory map. Want me to show the full diff of what's changed?
Assistant
Two files changed: the rewind implementation (+28 net lines) and the new integration test.
User
Can you create a detailed but concise pull request description outlining why the changes in this branch were made and what changed? Preferrably as a markdown document copied to my clipboard.
Assistant
Copied to your clipboard.
User
Can you also add an end2end test validating this behavior?
Assistant
Let me look at the existing squash merge resume E2E test more closely — it has exactly the pattern I need.
Assistant
Now let me check the entire.RewindLogsOnly signature and the imports used in resume_test.go:
Assistant
I have everything I need. The test follows the same pattern as TestResumeSquashMergeMultipleCheckpoints: two agent prompts on a feature branch, two commits with checkpoints, then a squash merge to main. Instead of calling entire resume, it calls entire rewind --list and verifies the squash commit shows up with the latest checkpoint ID.
Assistant
All green. Added TestRewindSquashMergeMultipleCheckpoints in e2e/tests/rewind_test.go. It follows the same pattern as the existing TestResumeSquashMergeMultipleCheckpoints:
Creates a feature branch with two agent-assisted commits (each with its own checkpoint)
Squash merges onto main with both Entire-Checkpoint trailers in the message
Asserts entire rewind --list shows exactly one logs-only point for the squash commit
Asserts that point uses the latest checkpoint ID (cpID2, not cpID1)
/requesting-code-review thoughtfully review the changes in this branch only. Find out what changed by comparing to origin/main.
User
superpowers:requesting-code-review
/superpowers:requesting-code-review
thoughtfully review the changes in this branch only. Find out what changed by comparing to origin/main.
Assistant
Review came back clean. Key findings:
Issue 1 (Missing unit test for resolveLatestCheckpointFromMap): Fair point — it's a pure function, easy to test directly. Let me add it.
Issue 2, Suggestions 3-5: All acknowledged as correct observations but not blocking. The E2E test correctly reads checkpoint trailers from the feature branch commits (not the squash), and the integration test already validates transcript content.
Let me add the unit test:
Assistant
Good, existing tests are in rewind_test.go and use the strategy package (internal access). I'll add the unit test there.
Assistant
I need to check the CheckpointID type used in the strategy package — the map key might be id.CheckpointID not just CheckpointID:
Assistant
The test file is in package strategy, so I need to use id.CheckpointID. Let me check how it's used in the function signature:
Assistant
Right — it uses id.CheckpointID. Let me fix the test:
Assistant
Now fix the test to use id.CheckpointID:
Assistant
Wait, that also replaced CheckpointID inside CheckpointInfo struct fields. Let me check:
Assistant
The replace_all broke struct field references. CheckpointID is a field name in CheckpointInfo, not the type. Let me fix:
Assistant
Now fix the info.id.CheckpointID → info.CheckpointID references:
Assistant
Also fix the CheckpointID field in the existing RewindPoint struct literal at line ~184 and the CheckpointInfo.CheckpointID in the test for PreviewRewind_LogsOnly:
Assistant
Line 185 has a broken struct field too — that's in the existing test for PreviewRewind_LogsOnly, where the replace_all incorrectly changed CheckpointID: to id.CheckpointID: as a struct field name.
Assistant
All pass. Let me also verify the existing test still works (since I touched it with the replace_all):
Each entry has its own CheckpointID and maps to a distinct set of session transcripts on entire/checkpoints/v1. Selecting any one of them goes through the normal logs-only sub-menu and restores that specific checkpoint's data.
Pros:
Full access to all checkpoint data — nothing is silently lost
User can pick exactly which point in the squash they want
Each checkpoint may have different sessions/transcripts, and the user can see that
Cons:
Squash merges with many commits could bloat the list (10 commits = 10 entries from one squash)
Slightly inconsistent with entire resume (which auto-picks latest)
The entries share the same commit hash, which could look odd
My take
Option A is the right call. Here's why:
Consistency matters.entire resume already established the pattern: squash merge → resolve to latest. Users who learn one command won't be surprised by the other.
Rewind's purpose for logs-only points is transcript restoration. You're not restoring files (the squash commit is already on the branch). The latest checkpoint's transcript is almost always the one you want — it has the full conversation context up to that point.
Option B's benefit is theoretical. In practice, if someone squash-merged 3 commits, they almost certainly want to resume from where they left off (the latest), not from checkpoint 1 of 3 where the agent had barely started. The rare case where you'd want an older checkpoint from a squash doesn't justify complicating the list for everyone.
The fix is minimal. Swap ParseCheckpoint for ParseAllCheckpoints + resolveLatestCheckpoint() (or a shared helper), and you're done. The existing RestoreLogsOnly() already handles multi-session checkpoints correctly downstream.