Skip to main content

Semantic search across Claude Code sessions to find the best context for new tasks

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

claude_smart_fork-0.1.0.tar.gz (28.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

claude_smart_fork-0.1.0-py3-none-any.whl (41.0 kB view details)

Uploaded Python 3

File details

Details for the file claude_smart_fork-0.1.0.tar.gz.

File metadata

  • Download URL: claude_smart_fork-0.1.0.tar.gz
  • Upload date:
  • Size: 28.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for claude_smart_fork-0.1.0.tar.gz
Algorithm Hash digest
SHA256 814190c3eb91f3f6e5f1592ab48748092d9a7ed939120d88467d31926c52b4cd
MD5 8e40fdaaf68ad722b515bd71becf973c
BLAKE2b-256 2552fa8bb5691b6e677cdbe646b71aab75f1c18af545b8c9d97b8fb7ff1126a8

See more details on using hashes here.

File details

Details for the file claude_smart_fork-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for claude_smart_fork-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9ef4c7ae5153c3740443e51b403640c8abbede5c531e91ed358f1550f4dda32c
MD5 0a78683824ce89fd4e348ad30365c51c
BLAKE2b-256 f5154b20b704713a2c9c583bb523359b102a7f7d60980eda769aa649f697577c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page