Skip to content

State Command

Quick Start: Manage workflow state for existing worktrees. Use sequant state to bootstrap state tracking for worktrees created before state management was enabled, rebuild corrupted state, or clean up orphaned entries.

  • Command: sequant state <subcommand>
  • Subcommands: init, rebuild, clean

The sequant state command provides utilities for managing the .sequant/state.json file, which tracks workflow progress for each issue. This is useful when:

  • You have existing worktrees that were created before state tracking was enabled
  • The state file becomes corrupted or out of sync
  • You want to clean up entries for deleted worktrees

Populate state for untracked worktrees. Scans all git worktrees, identifies those with issue-related branch names, and adds them to the state file.

Terminal window
sequant state init

What it does:

  1. Runs git worktree list to find all worktrees
  2. Parses branch names to extract issue numbers (supports feature/123-*, issue-123, 123-* patterns)
  3. Fetches issue titles from GitHub using gh CLI
  4. Infers current phase from existing run logs (if available)
  5. Adds entries to .sequant/state.json

Options:

OptionDescription
--jsonOutput results as JSON (for scripting)
-v, --verboseShow detailed progress during discovery

Example output:

🔍 Discovering untracked worktrees...
✓ Added #117: Add state bootstrapping for existing worktrees
Branch: feature/117-state-bootstrapping
Inferred phase: exec
✓ Added #119: Integrate state updates into all workflow skills
Branch: feature/119-state-integration
Summary:
Worktrees scanned: 6
Already tracked: 2
Newly added: 2

Recreate the entire state file from scratch by combining run logs and worktree discovery.

Terminal window
sequant state rebuild --force

What it does:

  1. Scans .sequant/logs/ for all run logs
  2. Extracts issue information and phase history from logs
  3. Discovers additional worktrees not in logs
  4. Creates a fresh state file

Options:

OptionDescription
-f, --forceRequired. Confirms you want to replace the existing state file
--jsonOutput results as JSON
-v, --verboseShow detailed progress

Example output:

🔄 Rebuilding state from scratch...
Step 1: Rebuilding from run logs...
Step 2: Discovering untracked worktrees...
✓ State rebuilt successfully
Logs processed: 15
Issues from logs: 8
Worktrees scanned: 6
Worktrees added: 2
Run `sequant status --issues` to see the rebuilt state.

Remove entries for worktrees that no longer exist (orphaned entries). Automatically detects merged PRs and handles them appropriately.

Terminal window
sequant state clean --dry-run

What it does:

  1. Checks each state entry against active git worktrees
  2. Identifies orphaned entries (worktree path no longer exists)
  3. For orphaned entries with PRs, checks GitHub to see if the PR was merged
  4. Merged PRs: Automatically removed (work is complete)
  5. Non-merged orphans: Marked as abandoned (kept for review)
  6. Optionally removes old merged/abandoned issues by age

Options:

OptionDescription
-d, --dry-runPreview what would be cleaned without making changes
--allRemove all orphaned entries (both merged and abandoned) in one step
--max-age <days>Also remove merged/abandoned issues older than N days
--jsonOutput results as JSON
-v, --verboseShow detailed progress

Example output:

🧹 Cleanup preview (dry run)...
🔍 Orphaned: #42 (worktree not found: /path/to/worktree)
Checking PR #100 status...
PR status: MERGED
✓ Merged PR detected, removing entry
🔍 Orphaned: #55 (worktree not found: /path/to/worktree)
Checking PR #105 status...
PR status: OPEN
→ Marked as abandoned (kept for review)
Preview (no changes made):
Merged PRs (auto-removed): #42
Abandoned (no merge): #55
Run without --dry-run to apply these changes.
Use --all to remove both merged and abandoned entries.

The sequant status command also supports cleanup flags as a shortcut:

Terminal window
# These are equivalent:
sequant state clean --dry-run
sequant status --cleanup --dry-run
# With --all flag:
sequant state clean --all
sequant status --cleanup --all

When you first enable state tracking on a project with existing worktrees:

Terminal window
# 1. Initialize state for all existing worktrees
sequant state init
# 2. Verify the state was populated correctly
sequant status --issues

If your state file becomes corrupted or inconsistent:

Terminal window
# 1. Rebuild state from logs and worktrees
sequant state rebuild --force
# 2. Verify the rebuilt state
sequant status --issues

After removing old worktrees manually:

Terminal window
# 1. Preview what will be cleaned (checks PRs for merge status)
sequant state clean --dry-run
# 2. If the preview looks correct, apply changes
# Merged PRs are auto-removed, non-merged are marked "abandoned"
sequant state clean
# 3. To remove everything (merged + abandoned) in one step:
sequant state clean --all

To clean up issues that were merged more than 30 days ago:

Terminal window
sequant state clean --max-age 30

All subcommands support --json for integration with scripts:

Terminal window
# Get discovered worktrees as JSON
sequant state init --json | jq '.discovered[].issueNumber'
# Check for orphaned entries
sequant state clean --dry-run --json | jq '.orphaned'

Symptoms: A worktree exists but state init doesn’t find it.

Solution: Check that the branch name matches one of these patterns:

  • feature/<number>-<description>
  • issue-<number>
  • <number>-<description>

Branches like feature/dashboard without an issue number won’t be discovered.

Symptoms: Issue titles show as “(title unavailable for #123)”.

Solution: Ensure gh CLI is installed and authenticated:

Terminal window
gh auth status

The state will still be created with a placeholder title, which you can update later.

Symptoms: Running sequant state rebuild shows a warning and exits.

Solution: This is a safety feature. Add --force to confirm:

Terminal window
sequant state rebuild --force

Generated for Issue #117 on 2026-01-20