# Branch Session

> Branch the current Claude Code or Codex session into a new tmux session. Creates a parallel conversation that can diverge independently. Use when you want to explore an alternative approach without losing your current context.

- **Type:** Skill
- **Install:** `agentstack add skill-buddyh-agent-skills-branch-session`
- **Verified:** Yes — security-reviewed for prompt injection and unsafe behavior
- **Seller:** [buddyh](https://agentstack.voostack.com/s/buddyh)
- **Installs:** 0
- **Category:** [Agent Skills](https://agentstack.voostack.com/c/agent-skills)
- **Latest version:** 0.1.0
- **License:** MIT
- **Upstream author:** [buddyh](https://github.com/buddyh)
- **Source:** https://github.com/buddyh/agent-skills/tree/main/branch-session

## Install

```sh
agentstack add skill-buddyh-agent-skills-branch-session
```

Requires the [AgentStack CLI](https://agentstack.voostack.com/docs/cli). Works with Claude Code, Cursor, and any MCP-compatible agent.

## About

# Branch Session

## Overview

Create a "branch" of the current conversation by spawning a new tmux session that continues from the same session. Both sessions can then diverge independently. The original session remains untouched.

## Platform Support

- **Claude Code**: Uses `claude --continue ` to resume from the same session
- **Codex**: Uses `codex resume ` to resume from the same session

## Workflow

### Step 1: Get Current Session ID

**Claude Code:**
1. Get current working directory
2. Convert to Claude project path format:
   ```bash
   # /home/user/projects/myapp -> -home-user-projects-myapp
   PROJECT_PATH=$(echo "$PWD" | sed 's|/|-|g' | sed 's|^-||')
   ```
3. Find most recently modified session file:
   ```bash
   SESSION_FILE=$(ls -t ~/.claude/projects/$PROJECT_PATH/*.jsonl 2>/dev/null | head -1)
   SESSION_ID=$(basename "$SESSION_FILE" .jsonl)
   ```

**Codex:**
```bash
# Find recent session files
ls -t ~/.codex/sessions/$(date +%Y/%m/%d)/*.jsonl 2>/dev/null | head -5
```

### Step 2: Generate Branch Name

Create a unique session name:
```bash
SHORT_ID=$(echo "$SESSION_ID" | cut -c1-5)
TIMESTAMP=$(date +%H%M)
BRANCH_NAME="branch-${SHORT_ID}-${TIMESTAMP}"
```

### Step 3: Execute Branch

Run the branch script:
```bash
~/.claude/skills/branch-session/scripts/branch_session.sh "$PWD" "$SESSION_ID" "$BRANCH_NAME"
```

The script creates a new tmux session and launches the agent with session context:

- **Claude Code**: `claude --continue $SESSION_ID`
- **Codex**: `codex resume $SESSION_ID`

### Step 4: Confirm

Report to user:
```
Branched session: branch-a1b2c-1508
Directory: /home/user/projects/myapp
Resuming: a1b2c3d4-da03-4ece-8625-582be89f6dff

To attach: tmux attach -t branch-a1b2c-1508
```

## Quick Reference

**Invocation**: `/branch`

**Session naming**: `branch--`

**Use cases**:
- Explore alternative implementation approaches
- Test something risky without losing progress
- Split work into parallel tracks

## Setup

Make the script executable (one-time):
```bash
chmod +x ~/.claude/skills/branch-session/scripts/*.sh
```

## Requirements

- tmux installed and running
- Claude Code CLI (`claude`) or Codex CLI (`codex`)
- Active session to branch from

## Resources

### scripts/
- `branch_session.sh` - Creates tmux session and continues from current session

## Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

- **Author:** [buddyh](https://github.com/buddyh)
- **Source:** [buddyh/agent-skills](https://github.com/buddyh/agent-skills)
- **License:** MIT

Install and usage instructions live in the source repository linked above.

## Pricing

- **Free** — Free

## Security capabilities

Automated source analysis of v0.1.0 — what this tool can access:

- **Network access:** no
- **Filesystem access:** no
- **Shell / process execution:** no
- **Environment & secrets:** no
- **Dynamic code execution:** no

*"Yes" means the capability is present in the source — more access means more to trust, not that it is unsafe.*


## Versions

- **0.1.0** — security scan: passed — Imported from the upstream source.

## Links

- Listing page: https://agentstack.voostack.com/l/skill-buddyh-agent-skills-branch-session
- Seller: https://agentstack.voostack.com/s/buddyh
- Browse the marketplace: https://agentstack.voostack.com/browse

---
Listed on AgentStack — the marketplace for AI agent skills and MCP servers. Every listing is security-reviewed. Creators keep 70%.
