Skip to main content

claude-smart-fork

PyPI version Python 3.10+ License: MIT CI

Semantic search across your Claude Code sessions. Find the most relevant context for new tasks instead of starting from scratch.

Demo

The Problem

You've had hundreds of Claude Code sessions. Each one contains valuable context: decisions made, patterns established, problems solved. But when you start a new task, all that knowledge is locked away in session files you can't easily search.

The Solution

claude-smart-fork indexes your Claude Code session history and lets you semantically search for relevant past sessions. Found a good match? Fork from that session and continue with all the context already loaded.

$ smart-fork search "add rate limiting to Express API"

🔍 Top Matching Sessions:

1. 🟢 [94%] a1b2c3d4...
   📁 ~/projects/my-api
   📝 API middleware and request handling patterns
   🛠️ TypeScript, Express, Redis

2. 🟡 [82%] e5f6g7h8...
   📁 ~/projects/rate-limiter
   📝 Redis-based rate limiting implementation

To fork the top result:
  claude --resume a1b2c3d4-full-session-id

Installation

Minimal Install (Keyword Search)

pip install claude-smart-fork

This gives you the CLI with basic keyword-based search. No heavy dependencies.

With Vector Search (Recommended)

pip install "claude-smart-fork[chromadb,embeddings]"

Adds semantic search using local embeddings (~300MB for the model, downloaded once).

With LLM Summarization

# Using Claude API
pip install "claude-smart-fork[claude]"

# Using local Ollama
pip install "claude-smart-fork[ollama]"

Everything

pip install "claude-smart-fork[all]"

Quick Start

1. Initialize

smart-fork init

This creates ~/.claude-smart-fork/ with default configuration.

2. Index Your Sessions

# Preview what would be indexed
smart-fork index --dry-run

# Index all sessions
smart-fork index

3. Search

smart-fork search "implement OAuth authentication"

4. Fork

Copy the session ID from the search results and use Claude Code's built-in resume:

claude --resume <session-id>

Configuration

Configuration is stored in ~/.claude-smart-fork/config.json:

{
  "sessions_path": "~/.claude/projects",
  "backend": "chromadb",
  "embedding_model": "nomic-ai/nomic-embed-text-v1",
  "summarizer": "simple",
  "auto_index": true,
  "search_results_limit": 5
}

Backend Options

Backend Install Description
sqlite Base Keyword search, no vectors
chromadb [chromadb] Vector search with local embeddings

Embedding Models

Model Size Quality Install
nomic-ai/nomic-embed-text-v1 270MB Best for code [embeddings]
all-MiniLM-L6-v2 80MB Good, faster [embeddings]
openai API Excellent Requires API key

Summarizers

Summarizer Install Description
simple Base Keyword extraction, no LLM
claude [claude] Claude API summarization
ollama [ollama] Local Ollama models

Claude Code Integration

Automatic Indexing with Hooks

Add to ~/.claude/settings.json:

{
  "hooks": {
    "SessionEnd": [
      {
        "type": "command",
        "command": "smart-fork index-session $CLAUDE_SESSION_ID"
      }
    ]
  }
}

Now sessions are automatically indexed when they end.

Custom Slash Command

Create ~/.claude/commands/detect-fork.md:

# /detect-fork

Search for relevant past sessions to fork from.

## Usage

Run: `smart-fork search "$ARGUMENTS"`

Present the results and offer to provide the fork command.

CLI Reference

# Initialize configuration
smart-fork init [--force]

# Index sessions
smart-fork index [--dry-run] [--limit N] [--since DATE]

# Index a specific session
smart-fork index-session <session-id>

# Search sessions
smart-fork search <query> [--limit N] [--project PATH]

# Show statistics
smart-fork stats

# Show configuration
smart-fork config [--edit]

# Update configuration
smart-fork config set <key> <value>

How It Works

  1. Parsing: Reads Claude Code JSONL session files from ~/.claude/projects/
  2. Summarization: Extracts key information (topic, decisions, files, technologies)
  3. Embedding: Converts summaries to vectors using local models
  4. Storage: Stores vectors in ChromaDB for fast similarity search
  5. Search: Converts your query to a vector and finds nearest neighbors

Development

# Clone the repo
git clone https://github.com/a-bekheet/claude-smart-fork.git
cd claude-smart-fork

# Install with dev dependencies
pip install -e ".[dev]"

# Run tests
pytest

# Run linting
ruff check src tests
ruff format src tests

# Type checking
mypy src

Contributing

Contributions are welcome! Please read CONTRIBUTING.md for guidelines.

Roadmap

  • Cross-machine sync via Git
  • Project-scoped search
  • Time-based queries ("what was I working on Tuesday?")
  • Session similarity chains
  • VS Code extension
  • Web UI for browsing sessions

License

MIT License - see LICENSE for details.

Acknowledgments

Metadata

Release files for claude-smart-fork 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for claude-smart-fork 0.1.0
File Size Uploaded
claude_smart_fork-0.1.0.tar.gz 28.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for claude-smart-fork 0.1.0
File Interpreter ABI Platform
claude_smart_fork-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 69.8 kB

Release files / claude_smart_fork-0.1.0.tar.gz

Download URL claude_smart_fork-0.1.0.tar.gz
Size 28.8 kB
Tags Source
SHA-256 checksum
How to use checksums
814190c3eb91f3f6e5f1592ab48748092d9a7ed939120d88467d31926c52b4cd
BLAKE2b-256 checksum
How to use checksums
2552fa8bb5691b6e677cdbe646b71aab75f1c18af545b8c9d97b8fb7ff1126a8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.14

Release files / claude_smart_fork-0.1.0-py3-none-any.whl

Download URL claude_smart_fork-0.1.0-py3-none-any.whl
Size 41.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9ef4c7ae5153c3740443e51b403640c8abbede5c531e91ed358f1550f4dda32c
BLAKE2b-256 checksum
How to use checksums
f5154b20b704713a2c9c583bb523359b102a7f7d60980eda769aa649f697577c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.14

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page