AgileFlow

/session:end

PreviousNext

End current session and optionally clean up worktree

/session:end

Cleanly end a Claude Code session, removing its lock and optionally cleaning up the git worktree.

Quick Start

/agileflow:session:end

How It Works

  1. Shows current session information
  2. Asks if you want to remove the git worktree
  3. Removes the session lock file
  4. Optionally deletes the worktree directory

Example Interaction

Ending Session 2 "auth"

Path: /home/user/myproject-auth
Branch: session-2
Created: 2 hours ago

Do you want to remove the git worktree?

○ Keep worktree (just end session tracking)
○ Remove worktree (delete directory and branch)

Cleanup Options

OptionWhat Happens
Keep worktreeSession lock removed, directory stays. You can cd there and work manually.
Remove worktreeDirectory deleted, branch optionally removed, full cleanup.

When to Use Each Option

Keep Worktree

  • You want to continue working there without Claude
  • You need to preserve uncommitted changes
  • You'll return to this work later

Remove Worktree

  • Work is complete and merged
  • You want to free up disk space
  • Cleaning up abandoned experiments

Ending Current Session

When running from your current session:

/agileflow:session:end
# This ends your current session
# You'll see a warning before proceeding

Ending Other Sessions

You can also end sessions you're not currently in:

/agileflow:session:status
# See all sessions
 
/agileflow:session:end
# Select which session to end

What Gets Cleaned Up

Session Lock

Always removed:

.agileflow/sessions/2.lock → deleted

Registry Entry

Updated:

{
  "sessions": {
    "2": {
      "ended": "2025-12-26T15:00:00Z",
      "status": "ended"
    }
  }
}

Git Worktree (optional)

If you choose to remove:

git worktree remove /home/user/myproject-auth
# Directory deleted
# Branch optionally deleted

Safety Checks

The command prevents accidental data loss:

  • Uncommitted changes: Warning shown if worktree has uncommitted work
  • Main session: Cannot remove main project worktree
  • Active sessions: Warning if trying to end another active session

Stale Session Cleanup

If a session died unexpectedly:

/agileflow:session:status
# Shows "stale" for dead sessions
 
/agileflow:session:end
# Select the stale session to clean up