managing-forks

mcfearsome/fork-yeah

Manages parallel conversation branches using git worktrees. Use when you want to explore multiple solution approaches simultaneously, need to try different implementations, or want to checkpoint your current conversation state before branching into alternative paths.

0 stars
0 forks
Shell
4 views

SKILL.md


name: managing-forks description: Manages parallel conversation branches using git worktrees. Use when you want to explore multiple solution approaches simultaneously, need to try different implementations, or want to checkpoint your current conversation state before branching into alternative paths.

Managing Forks - Conversation Branching for Claude Code

This skill enables you to create and manage parallel conversation branches (forks) using git worktrees. Each fork is an independent workspace where you can explore different approaches to solving a problem.

When to Use This Skill

Use fork management when:

  • The user wants to try multiple implementation approaches in parallel
  • You need to explore different solutions without losing your current progress
  • The user asks to "fork" the conversation or try alternatives
  • Working on a feature and want to experiment with different designs
  • The user wants to checkpoint the current state before making major changes

Core Commands

Creating Forks

Basic Fork Creation:

src/fork_create.sh <number>

Creates N parallel fork branches from the current conversation checkpoint.

Example:

src/fork_create.sh 3

Creates 3 parallel branches, each with its own git worktree.

Fork with Target Branch:

src/fork_create.sh <number> --target <branch-name>

Creates N forks that all target a specific branch (useful for feature development).

Example:

src/fork_create.sh 3 --target feature-auth

Creates 3 forks from and targeting the feature-auth branch. All forks will merge back to this branch.

Listing Forks

src/fork_list.sh

Shows all active fork branches with their metadata, creation time, status, and worktree paths.

Viewing Fork Hierarchy

src/fork_tree.sh

Displays a visual tree representation of all forks and their parent-child relationships. Useful for understanding nested fork structures.

Switching Between Forks

src/fork_switch.sh <fork-id>

Switches the working environment to a different fork branch.

Example:

src/fork_switch.sh fork-1730678901-a1b2c3d4-2

Checking Fork Status

src/fork_status.sh

Shows the current fork's status, including git status, worktree information, and fork metadata.

Merging Forks

src/fork_merge.sh <source-fork-id>

Merges changes from another fork branch into the current branch.

Example:

src/fork_merge.sh fork-1730678901-a1b2c3d4-1

Deleting Forks

src/fork_delete.sh <fork-id>

Deletes a fork branch, its worktree, and associated metadata. Prompts for confirmation.

Example:

src/fork_delete.sh fork-1730678901-a1b2c3d4-3

Workflow Examples

Example 1: Exploring Multiple Implementation Approaches

User asks: "I want to try implementing this feature using both REST and GraphQL approaches"

Response workflow:

  1. Create 2 forks: src/fork_create.sh 2 --target feature-api
  2. In fork-1: Implement using REST
  3. In fork-2: Implement using GraphQL
  4. User evaluates both approaches
  5. Merge the preferred approach back to feature-api

Example 2: Trying Different Design Patterns

User asks: "Let's explore both MVC and Clean Architecture for this"

Response workflow:

  1. Ensure current work is committed
  2. Create 2 forks: src/fork_create.sh 2 --target feature-refactor
  3. Switch to fork-1: Implement MVC pattern
  4. Switch to fork-2: Implement Clean Architecture
  5. User compares both implementations
  6. Merge chosen pattern back

Example 3: Nested Forks for Sub-Experiments

User asks: "In the GraphQL approach, let's try two different schema designs"

Response workflow:

  1. Switch to the GraphQL fork
  2. Create nested forks: src/fork_create.sh 2 --target graphql-schema
  3. Implement different schemas in each nested fork
  4. Merge best schema back to GraphQL fork
  5. Eventually merge GraphQL fork to main feature branch

Best Practices

Before Creating Forks

  1. Commit current work: Ensure git working directory is clean

    git add . && git commit -m "checkpoint before forking"
    
  2. Check you're in a git repository:

    git status
    
  3. Plan your forks: Think about how many parallel approaches you need

During Fork Work

  1. Stay organized: Use descriptive commit messages in each fork
  2. Document differences: Note why each approach differs
  3. Test independently: Each fork should be tested on its own
  4. Use fork status: Regularly check src/fork_status.sh to see where you are

After Fork Work

  1. Evaluate results: Compare implementations across forks
  2. Merge carefully: Use src/fork_merge.sh to combine best elements
  3. Clean up: Delete unused forks with src/fork_delete.sh
  4. Document decisions: Note why you chose one approach over another

Technical Details

What Happens When You Create a Fork

  1. Git worktree creation: Each fork gets an isolated git worktree
  2. Checkpoint saving: Current conversation state is saved to JSON
  3. Branch creation: New git branch created for the fork
  4. Metadata storage: Fork information stored in ~/.claude-code/forks/
  5. Terminal session: If tmux is available, creates dedicated session

Fork Data Structure

~/.claude-code/forks/
├── fork-xxx-1/
│   ├── checkpoint.json     # Conversation state
│   ├── metadata.json       # Fork metadata
│   ├── worktree/          # Git worktree
│   └── launch.sh          # Launcher script
├── fork-xxx-2/
│   └── ...
└── .fork-groups.json      # Fork group relationships

Metadata Fields

Each fork stores:

  • fork_id: Unique identifier
  • parent_id: Parent fork (for nested forks)
  • target_branch: Target branch for merging (if specified)
  • branch_number: Position in fork group
  • total_branches: Total forks in group
  • worktree_path: Path to git worktree
  • status: active/archived
  • created_at: ISO timestamp

Error Handling

Common Issues

"Not in a git repository"

  • Solution: Navigate to a git repository before creating forks

"Worktree already exists"

  • Solution: Run git worktree prune to clean up stale worktrees

"Fork not found"

  • Solution: Run src/fork_list.sh to see available forks

"Cannot create worktree"

  • Solution: Ensure uncommitted changes are committed or stashed

Recovery

If forks become corrupted:

  1. List all worktrees: git worktree list
  2. Prune stale worktrees: git worktree prune
  3. Clean fork data: rm -rf ~/.claude-code/forks/<bad-fork-id>

Limitations

  • Maximum 10 forks can be created at once (configurable)
  • Fork IDs are auto-generated and not human-readable
  • Worktrees must be on the same filesystem
  • Each fork requires disk space for its worktree

Integration with Terminal Multiplexing

tmux Mode (Recommended)

When tmux is installed:

  • Each fork gets a dedicated tmux session
  • Easy switching with tmux attach -t fork-<id>
  • Multiple panes can be created in each session

Fallback Modes

When tmux is not available:

  • macOS: Generates iTerm2/Terminal.app launcher scripts
  • Linux: Creates shell launcher scripts
  • Basic: Simple directory switching

Configuration

User configuration is stored in ~/.config/fork-yeah/config.yaml:

terminal:
  mode: auto  # auto, tmux, macos, linux, basic

fork:
  max_forks: 10
  auto_checkpoint: true

display:
  use_colors: true
  tree_ascii: true

Tips for Effective Fork Usage

  1. Communicate clearly: Tell the user which fork you're working in
  2. Use target branches: Always specify --target for feature work
  3. Keep forks focused: Each fork should explore one specific approach
  4. Document as you go: Add commit messages explaining your choices
  5. Merge incrementally: Don't wait until the end to merge good ideas
  6. Visualize often: Use src/fork_tree.sh to stay oriented

Related Documentation

  • Full user guide: README.md
  • Troubleshooting: docs/TROUBLESHOOTING.md
  • Marketplace info: MARKETPLACE.md
  • Configuration reference: config/config.yaml

README

🍴 fork-yeah

A Claude Code plugin for branching conversation paths

Fork-yeah enables you to create parallel branches of your Claude Code conversations, allowing you to explore different approaches while "saving your spot." Think of it as git branches for your AI conversations.

Features

  • Parallel Conversation Paths: Create N parallel branches from any point in your conversation
  • Git Worktrees: Each fork gets its own isolated git worktree
  • State Checkpointing: Saves complete conversation state at fork points
  • Terminal Multiplexing: Seamless integration with tmux for managing multiple forks
  • Nested Forks: Support for creating forks within fork branches
  • Visual Fork Tree: See your fork hierarchy at a glance
  • Cross-Platform: Works on Linux, macOS, and Windows (WSL)

Part of the mcfearsome marketplace - Quality plugins for Claude Code See MARKETPLACE.md for more plugins and marketplace information.

Quick Start

Installation

# Clone the repository
git clone https://github.com/mcfearsome/fork-yeah
cd fork-yeah

# Run setup
./setup.sh

The setup script will:

  • Check for required dependencies (git, python3, jq)
  • Optionally install tmux for the best experience
  • Create necessary directories
  • Link the plugin to Claude Code

Basic Usage

Inside Claude Code:

# Create 3 parallel branches from current conversation
/fork create 3

# List all your forks
/fork list

# View fork hierarchy
/fork tree

# Switch to a specific fork
/fork switch fork-1234567890-abc123-2

# Check current fork status
/fork status

# Merge changes from another fork
/fork merge fork-1234567890-abc123-1

# Delete a fork
/fork delete fork-1234567890-abc123-3

How It Works

The Fork Workflow

  1. Checkpoint: When you create a fork, fork-yeah saves the current conversation state and git commit
  2. Branch: Creates N git branches from that commit point
  3. Worktree: Sets up isolated git worktrees for each fork
  4. Launch: Spawns terminal sessions (tmux panes/windows) for each fork
  5. Work: Each fork can evolve independently
  6. Merge: Optionally merge successful approaches back together

Example Scenario

# You're working on a feature and want to try two approaches

# Save your current work
git add . && git commit -m "baseline before fork"

# Create two parallel branches
/fork create 2

# This creates:
# - fork-xxx-1: Try approach A
# - fork-xxx-2: Try approach B

# Work on each approach independently
# Then merge the better one back to main

Commands Reference

/fork create <number> [--target <branch_name>]

Create N parallel fork branches.

Arguments:

  • number: Number of branches (1-10)
  • --target <branch_name> (optional): Target branch all forks will merge to

Examples:

# Create 3 parallel branches from current point
/fork create 3

# Create 3 branches targeting feature-auth branch
/fork create 3 --target feature-auth

# All forks will be created from and merge back to feature-auth

What it does:

  • Captures current conversation state
  • Creates or checks out target branch (if --target specified)
  • Creates git branches from current commit
  • Sets up worktrees for each fork
  • Launches terminal sessions (if tmux available)
  • Stores target branch info for future merges

Target Branch Benefits:

  • All forks start from the same named branch
  • Makes it clear where work should merge back to
  • Useful for feature development with multiple approaches
  • Target branch is shown in fork metadata

/fork list

List all active fork branches.

Output:

  • Fork ID
  • Creation time
  • Status
  • Worktree path
  • Branch number

/fork switch <fork_id>

Switch to a different fork branch.

Arguments:

  • fork_id: ID of fork to switch to

Example:

/fork switch fork-1730678901-a1b2c3d4-2

What it does:

  • Changes to fork's worktree directory
  • Attaches to tmux session (if using tmux)
  • Updates shell environment

/fork tree

Visualize fork hierarchy as a tree structure.

Output:

  • ASCII tree showing fork relationships
  • Parent-child connections
  • Fork metadata

/fork status

Show status of current fork and conversation state.

Output:

  • Current fork (if in one)
  • Fork details
  • Git status
  • Worktree information

/fork merge <fork_id>

Merge changes from another fork branch.

Arguments:

  • fork_id: Source fork to merge from

Example:

/fork merge fork-1730678901-a1b2c3d4-1

/fork delete <fork_id>

Delete a fork and its worktree.

Arguments:

  • fork_id: Fork to delete

Example:

/fork delete fork-1730678901-a1b2c3d4-3

What it does:

  • Kills associated tmux session
  • Removes git worktree
  • Deletes git branch
  • Cleans up fork data

Terminal Modes

Fork-yeah adapts to your environment:

tmux Mode (Recommended)

When tmux is installed:

  • Creates dedicated sessions for fork groups
  • Uses panes/windows for each fork
  • Seamless switching between forks
  • Full multiplexing capabilities

Fallback Modes

When tmux is not available:

  • macOS: Generates iTerm2/Terminal.app launchers
  • Linux: Creates shell launcher scripts
  • Basic: Simple directory switching

Configuration

Edit ~/.config/fork-yeah/config.yaml to customize:

# Terminal mode: auto, tmux, macos, linux, basic
terminal:
  mode: auto

# Fork creation settings
fork:
  max_forks: 10
  auto_checkpoint: true
  confirm_multiple: true

# Display settings
display:
  use_colors: true
  tree_ascii: true
  date_format: iso

File Structure

~/.claude-code/forks/          # Fork data directory
├── fork-xxx-1/
│   ├── checkpoint.json        # Conversation state
│   ├── metadata.json          # Fork metadata
│   ├── worktree/              # Git worktree
│   └── launch.sh              # Launcher script
├── fork-xxx-2/
│   └── ...
└── .fork-groups.json          # Fork group relationships

~/.config/fork-yeah/           # Configuration
├── config.yaml                # User config
└── tmux.conf                  # tmux settings

How the Plugin Works

fork-yeah integrates with Claude Code through two mechanisms:

1. Slash Commands (commands/ directory)

User-invoked commands that you type explicitly:

  • /fork create 3 - Create forks
  • /fork list - List all forks
  • /fork switch <id> - Switch forks
  • /fork tree - View hierarchy
  • /fork status - Check status
  • /fork merge <id> - Merge forks
  • /fork delete <id> - Delete forks

These appear in Claude Code's /help menu and can be called directly by users.

2. Agent Skill (SKILL.md)

Proactive fork management by Claude:

  • Claude automatically suggests forking when exploring multiple approaches
  • Recognizes when conversation branching would be helpful
  • Manages forks intelligently based on conversation context
  • Uses the skill instructions to make decisions about when and how to fork

Example: If you say "Let's try both REST and GraphQL approaches," Claude may proactively suggest or use /fork create 2 --target api-design without you explicitly asking for it.

Requirements

Required

  • Git
  • Python 3
  • jq (JSON processor)

Optional

  • tmux (highly recommended for best experience)

Troubleshooting

See TROUBLESHOOTING.md for common issues and solutions.

Advanced Usage

Nested Forks

You can create forks within fork branches:

# In main conversation
/fork create 2

# Switch to fork-1
/fork switch fork-xxx-1

# Create sub-forks
/fork create 2

# Now you have:
# - fork-xxx-1
#   - fork-yyy-1
#   - fork-yyy-2
# - fork-xxx-2

Programmatic Access

Use the Python state manager directly:

# List all forks
python3 src/state_manager.py list

# Export checkpoint
python3 src/state_manager.py export fork-xxx-1 backup.json

# Import checkpoint
python3 src/state_manager.py import backup.json

Contributing

Contributions welcome! Please:

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Submit a pull request

License

MIT License - see LICENSE file for details

Support

Credits

Created by mcfearsome for the Claude Code community.


Happy Forking! 🍴