Skip to main content

Semantic checkpointing for Claude Code

Project description

Sage

Stop losing context. Start checkpointing your AI research.

Sage is a Claude Code plugin that gives your AI assistant memory across sessions. When you're deep in research or complex problem-solving, Sage helps Claude automatically save semantic checkpoints—capturing what matters (conclusions, tensions, discoveries) and discarding what doesn't (the meandering path to get there).

The Problem

You're 2 hours into a research session with Claude. You've explored 15 sources, validated 3 hypotheses, found a critical disagreement between experts, and synthesized a thesis. Then:

  • Context window fills up → auto-compaction loses your nuanced findings
  • You close the session → tomorrow you start from scratch
  • You switch projects → that research thread is orphaned

The result: You become the orchestration layer, manually maintaining state across fragmented chat sessions like a conspiracy board.

The Solution

Sage teaches Claude to checkpoint proactively—not when tokens run out, but when something meaningful happens:

  • Hypothesis validated or invalidated
  • Critical constraint discovered
  • Synthesis moment ("putting this together...")
  • Branch point ("we could either X or Y")
  • You say "checkpoint" or "save this"

Each checkpoint captures:

  • Core question — What decision is this driving toward?
  • Thesis + confidence — Your current synthesized position
  • Open questions — What's still unknown
  • Sources — Decision-relevant summaries (not full content)
  • Tensions — Where credible sources disagree (high value!)
  • Unique contributions — What YOU discovered, not just aggregated

Quick Start

1. Install

# From PyPI (recommended)
pip install claude-sage[mcp]

# Or from source
git clone https://github.com/b17z/sage.git
cd sage
pip install -e ".[mcp]"

2. Configure Claude Code

Add to your .mcp.json (project or ~/.claude/.mcp.json for global):

{
  "mcpServers": {
    "sage": {
      "command": "sage-mcp"
    }
  }
}

Or install hooks for auto-checkpoint detection:

sage hooks install

3. Test it

# Start Claude Code
claude

# Have a conversation, do some research
# Sage MCP tools are now available to Claude
# Claude will checkpoint automatically on synthesis moments

# Later, list your checkpoints:
sage checkpoint list
sage checkpoint show <checkpoint-id>

Features

Auto-Checkpoint (MCP Server)

Claude automatically saves checkpoints when meaningful events occur:

Trigger When Confidence
synthesis Claude combines sources into a conclusion 0.5
web_search_complete After research with findings 0.3
topic_shift Conversation changes direction 0.4
branch_point Decision point identified 0.4
constraint_discovered Critical limitation found 0.4
precompact Before context compaction 0.0 (always)
manual You say "checkpoint" 0.0 (always)

Knowledge Persistence

Store and recall facts across sessions:

# Save knowledge
sage knowledge add "GDPR requires consent" --id gdpr-consent --keywords gdpr,consent

# Query knowledge (auto-recalls on matching keywords)
sage knowledge match "What about GDPR?"

# List all knowledge
sage knowledge list

Semantic Embeddings

Sage uses local embeddings for semantic matching:

  • Model: BAAI/bge-large-en-v1.5 (~1.3GB, downloaded on first use)
  • Hybrid scoring: 70% semantic + 30% keyword matching (configurable)
  • Checkpoint deduplication: Skips saving when thesis is 90%+ similar
  • Query prefix support: Optimized retrieval for BGE models

Project-Local Checkpoints

Checkpoints can be stored per-project:

# In a project directory
mkdir .sage  # Checkpoints go here instead of ~/.sage

# Or explicitly
sage checkpoint list --project /path/to/project

Checkpoint Templates

Customize checkpoint format:

sage templates list                    # List available templates
sage_save_checkpoint(..., template="decision")  # Use decision template

Built-in templates: default, research, decision, code-review

Knowledge Types

Different recall behavior by type:

Type Threshold Use Case
knowledge 0.70 General facts
preference 0.30 User preferences (aggressive recall)
todo 0.40 Persistent reminders
reference 0.80 On-demand reference
sage todo list      # List todos
sage todo done <id> # Mark complete

Configurable Thresholds

Tune retrieval and detection via ~/.sage/tuning.yaml or .sage/tuning.yaml:

# Retrieval thresholds
recall_threshold: 0.70      # Knowledge recall sensitivity (0-1)
dedup_threshold: 0.90       # Checkpoint deduplication threshold
embedding_weight: 0.70      # Weight for semantic similarity
keyword_weight: 0.30        # Weight for keyword matching

# Embedding model
embedding_model: BAAI/bge-large-en-v1.5

Project config overrides user config. See sage config commands.

Storage Format

Checkpoints are stored as Markdown with YAML frontmatter (Obsidian-compatible):

---
id: 2026-01-16T14-30-00_payment-rails-synthesis
type: checkpoint
confidence: 0.75
trigger: synthesis
skill: crypto-payments
---

# Where do stablecoins win vs traditional payment rails?

## Thesis
Integrate, don't replace. Stablecoins win middle-mile + new primitives,
not POS checkout. Most companies have pieces but not packaging.

## Open Questions
- What's the unified customer object strategy?
- Timeline for Stripe's full stack vs current fragmentation?

## Sources
- **sheel_mohnot** (person): No forcing function for stablecoin POS — _contradicts_
- **simon_taylor** (person): Not about price—about TAM expansion — _nuances_

## Tensions
- **sheel_mohnot** vs **sam_broner**: Whether merchant profitability is sufficient — _unresolved_

## Unique Contributions
- **discovery**: Platform team didn't know about existing SDK integration

Checkpoints live in ~/.sage/checkpoints/ (global) or .sage/checkpoints/ (project-local).

CLI Reference

# Checkpoints
sage checkpoint list              # List all checkpoints
sage checkpoint show <id>         # Show checkpoint details
sage checkpoint rm <id>           # Delete a checkpoint

# Knowledge
sage knowledge list               # List all knowledge items
sage knowledge add <file>         # Add knowledge from file
sage knowledge match "query"      # Test what would be recalled
sage knowledge rm <id>            # Remove knowledge item

# Config
sage config list                  # Show current config
sage config set <key> <value>     # Set a value (user-level)
sage config set <key> <value> --project  # Set project-level
sage config reset                 # Reset tuning to defaults

# MCP/Hooks
sage mcp install                  # Install MCP server
sage hooks install                # Install Claude Code hooks

# Admin
sage admin rebuild-embeddings     # Rebuild all embeddings

MCP Tools

Available to Claude via MCP:

Tool Purpose
sage_save_checkpoint Save full checkpoint with thesis, sources, tensions
sage_load_checkpoint Restore checkpoint context
sage_list_checkpoints List all checkpoints
sage_autosave_check Auto-checkpoint with confidence thresholds
sage_save_knowledge Persist facts with keyword triggers
sage_recall_knowledge Query knowledge base semantically
sage_list_knowledge List knowledge items
sage_remove_knowledge Delete knowledge items

Hooks

Claude Code hooks for automatic detection:

Hook Purpose
post-response-semantic-detector.sh Detects synthesis, branch points, constraints, topic shifts
post-response-context-check.sh Triggers checkpoint at 70% context usage
pre-compact.sh Checkpoints before /compact (approves auto-compact)

Hooks have:

  • Priority ordering: topic_shift > branch_point > constraint > synthesis
  • Cooldown mechanism: Prevents duplicate triggers
  • Meta-ban list: Avoids trigger loops on hook discussion

Prerequisites

Documentation

Development

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

# Run tests (578 tests)
pytest tests/ -v

# Lint and format
ruff check sage/ --fix
black sage/

License

MIT

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_sage-2.2.0.tar.gz (139.4 kB view details)

Uploaded Source

Built Distribution

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

claude_sage-2.2.0-py3-none-any.whl (155.7 kB view details)

Uploaded Python 3

File details

Details for the file claude_sage-2.2.0.tar.gz.

File metadata

  • Download URL: claude_sage-2.2.0.tar.gz
  • Upload date:
  • Size: 139.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for claude_sage-2.2.0.tar.gz
Algorithm Hash digest
SHA256 90355f87e6e63c9bbb66a1d62d25f07fc0d65b5719357fc9ac7cb2bebececaba
MD5 2502324998695d2390e3842eba1b413e
BLAKE2b-256 edb01982f825abacdf1f1bd190a977a346b779e95cf62ec80de6333e4877ef11

See more details on using hashes here.

Provenance

The following attestation bundles were made for claude_sage-2.2.0.tar.gz:

Publisher: publish.yml on b17z/sage

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file claude_sage-2.2.0-py3-none-any.whl.

File metadata

  • Download URL: claude_sage-2.2.0-py3-none-any.whl
  • Upload date:
  • Size: 155.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for claude_sage-2.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 35298e6c74787516a2204f1fdd2eca79ee115b6aaa787cecffa638659fe1f713
MD5 a423e47d3d439922c053aa51c9c8e65e
BLAKE2b-256 8c1689cb2ddfd3e554bb89ab6d4f13ab80d4a828aa7439c7cb7b0f5763b84056

See more details on using hashes here.

Provenance

The following attestation bundles were made for claude_sage-2.2.0-py3-none-any.whl:

Publisher: publish.yml on b17z/sage

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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