Skip to content

Fix session discovery for Claude Code --worktree sessions #144

@jcleira

Description

@jcleira

Description

Claude Code has a --worktree flag that creates its own git worktrees under .claude/worktrees/<branch>/. When this flag is used, Claude Code keys the session directory to the main repo path rather than the worktree path. Partio's session discovery doesn't account for this, causing partio rewind, partio doctor, and the post-commit hook's session linking to silently fail.

This mirrors the fix in entireio/cli#817.

Root cause

find_session_dir.go walks up from the worktree root. But when Claude Code's --worktree creates sub-worktrees under .claude/worktrees/, the session is keyed to the parent (main repo root), not the worktree root. The walk-up logic misses this.

What to fix

In internal/agent/claude/find_session_dir.go:

  1. Detect if the current path is inside a .claude/worktrees/<branch>/ directory (Claude-managed worktree).
  2. Resolve the main repo root (directory above .claude/) and use it as the session key.
  3. Add a table-driven test covering this case.

Why

Users who run Claude with --worktree get no checkpoints — a silent failure. Hooks run but sessions are never linked to commits.

Source

Inspired by entireio/cli#817

Acceptance Criteria

  • partio rewind finds sessions when Claude Code was launched with --worktree
  • partio doctor correctly identifies the session directory in this case
  • find_session_dir.go resolves the main repo root when inside .claude/worktrees/<branch>/
  • Existing worktree tests still pass
  • New table-driven test covers the --worktree case

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions