Context Management System
Enables AI development tools to maintain context across chat sessions with automatic branching, progress tracking, and TODO management for different tasks.
README
Context Management System
A context management system for AI development tools like Cursor, Claude Code, and Gemini CLI that enables leveraging previous context from chat sessions while maintaining dynamic workflows.
š Quick Start (5 Minutes)
Get up and running immediately:
-
Install dependencies:
pip install -r requirements.txt # Or install in development mode: pip install -e . -
Set up MCP integration (choose your tool):
- Cursor: Copy
mcp-config-cursor.jsonto~/.cursor/mcp.jsonor.cursor/mcp.jsonin your project - Gemini CLI: Copy
mcp-config-gemini.jsonto.gemini/settings.jsonin your project - Claude Desktop: Edit
~/Library/Application Support/Claude/claude_desktop_config.json
- Cursor: Copy
-
Restart your AI tool - The context management tools are now available!
-
Start using it - The AI will automatically:
- Create context branches for different tasks
- Log reasoning steps as it works
- Create checkpoints when you make progress
- Remember context across sessions
That's it! The system auto-detects your project workspace and creates a .context/ directory automatically.
⨠What You Get
Once set up, your AI assistant can:
- Remember across sessions: Pick up exactly where you left off, even days later
- Organize by task: Automatically branch context for different features/bugs
- Track progress: See what's been done, what's pending, and what's next
- Smart context switching: Automatically detect which branch matches your current work
- No manual work: The AI handles all context management automatically
Features
- LOG: Record reasoning steps as the AI works through problems
- COMMIT: Checkpoint important points in chat sessions
- BRANCH: Create new branches with easy access to previous branch context
- MERGE: Merge context from multiple branches into the current branch
- INFO: Get project information at different levels (project goals, branch summaries, detailed chat sessions)
- TODO Management: Track and manage TODO items across branches
- Smart Branch Detection: Automatically suggest the right branch for your work
Installation
Option 1: Development Install (Recommended)
# Clone or download this repository
cd context-engineering
# Install in development mode
pip install -e .
Option 2: Direct Install
pip install -r requirements.txt
Integration Options
Option 1: MCP Server (Recommended)
The MCP (Model Context Protocol) server allows AI tools to call context management functions directly. This is the recommended approach as it enables seamless integration.
For Cursor
Quick Setup:
-
Copy the config file:
# For project-specific setup (recommended): cp mcp-config-cursor.json .cursor/mcp.json # Or for global setup: mkdir -p ~/.cursor cp mcp-config-cursor.json ~/.cursor/mcp.json -
Edit the
cwdpath in the config file to point to this repository:{ "mcpServers": { "context-management": { "command": "python3", "args": ["-m", "src.mcp_server"], "cwd": "/absolute/path/to/context-engineering" } } }Note: Use
${workspaceFolder}for project-specific configs (Cursor will auto-replace it) -
Restart Cursor - The AI will now have access to context management tools!
What happens next:
- When you start a new chat, the AI can call
context_status()to check your workspace - The AI will automatically create a
.context/directory in your project root - All context management happens automatically - no manual intervention needed
For Gemini CLI
-
Create the config directory:
mkdir -p .gemini cp mcp-config-gemini.json .gemini/settings.json -
Edit
.gemini/settings.jsonand update thecwdpath:{ "mcpServers": { "context-management": { "command": "python3", "args": ["-m", "src.mcp_server"], "cwd": "/absolute/path/to/context-engineering" } } } -
Restart Gemini CLI - Context management tools are now available!
For Claude Desktop
-
Edit the config file:
# On macOS: open ~/Library/Application\ Support/Claude/claude_desktop_config.json # On Windows: # %APPDATA%\Claude\claude_desktop_config.json # On Linux: # ~/.config/Claude/claude_desktop_config.json -
Add or merge this configuration:
{ "mcpServers": { "context-management": { "command": "python3", "args": ["-m", "src.mcp_server"], "cwd": "/absolute/path/to/context-engineering" } } } -
Restart Claude Desktop - You're all set!
Option 2: CLI Commands
Use the CLI directly or have the AI invoke shell commands:
# Log reasoning steps
python3 -m src.cli log "Investigating the auth module..."
# Commit progress
python3 -m src.cli commit --from-log all
# Create/switch branches
python3 -m src.cli branch fix-login-bug --empty
# Get info
python3 -m src.cli info --level branch
šÆ First Steps After Setup
Once you've configured MCP and restarted your AI tool, here's what to expect:
1. Automatic Workspace Detection
When you start a new chat session, the AI will:
- Automatically detect your project workspace (via git root or existing
.context/directory) - Create a
.context/directory structure if it doesn't exist - Initialize the main context file with your project goals
2. Start Working Normally
Just work with your AI as usual! The system will:
- Automatically branch when you switch to different tasks
- Log reasoning steps as the AI thinks through problems
- Create checkpoints when significant progress is made
- Track TODOs across your work sessions
3. Example: Your First Session
You: "Help me add user authentication to my app"
AI: [Automatically calls context_detect_branch()]
ā Creates branch "add-user-auth"
ā Logs: "Starting authentication feature implementation"
ā Works on the task...
You: "Actually, let's fix the login bug first"
AI: [Automatically calls context_detect_branch()]
ā Switches to branch "fix-login-bug" (or creates it)
ā Has access to previous login-related context
ā Continues from where you left off
4. Returning Later
When you come back days or weeks later:
You: "What were we working on?"
AI: [Calls context_summary()]
ā Shows: Current branch, pending TODOs, recent progress
ā Picks up exactly where you left off
No manual context management needed - it all happens automatically!
MCP Tools
When using the MCP server, the AI has access to these tools:
context_status() - Check workspace path and current branch. Used at session start.
context_set_workspace(workspace_path) - Set the project workspace directory. Used if auto-detection fails.
context_summary() - Get quick overview of TODOs and progress. Used at session start and when checking status.
context_detect_branch(context_hint) - Smart branching: find the right branch for current work. Used before starting new tasks.
context_todos(action, item, todo_id) - View, add, or complete TODO items. Used throughout the session.
context_log(reasoning_step) - Log a reasoning step during AI thought process. Used as the AI works through problems.
context_commit(message, from_log) - Checkpoint progress by creating a commit. Used when significant progress is made.
context_branch(name, purpose, from_branch, empty) - Create a new branch or switch to existing one. Used when switching tasks.
context_merge(branches) - Merge context from other branches. Used when combining work from multiple branches.
context_info(level, branch) - Get detailed project/branch/session information. Used when you need detailed context.
Note: The AI uses these tools automatically - you don't need to call them manually!
Workflow Example
Here's a real-world example of how the system works across multiple sessions:
Day 1: Starting a New Feature
You ask: "Let's add user authentication"
The AI automatically:
- Detects this is a new task and calls
context_detect_branch("user authentication") - Creates a new branch called "add-user-auth"
- Logs: "Starting auth implementation..."
- Works on the feature, logging steps like "Created User model..." and "Implemented login endpoint..."
- Creates a checkpoint with
context_commit(from_log="all")
Day 2: Switching Tasks
You say: "Actually, let's fix the login bug first"
The AI automatically:
- Detects the task switch and calls
context_detect_branch("login bug fix") - Switches to (or creates) the "fix-login-bug" branch
- Logs: "Investigating login issue..."
- Finds and fixes the bug
- Commits: "Fixed password validation"
Day 5: Returning to Previous Work
You ask: "What were we working on?"
The AI automatically:
- Calls
context_summary()to load your context - Shows you're on branch "add-user-auth"
- Shows pending TODO: "Add password reset"
- Shows last commit: "Implemented login endpoint"
- Picks up exactly where you left off
Key Benefits:
- No context loss between sessions
- Automatic task organization
- Seamless switching between features
- Progress tracking and TODO management
Project Structure
The system creates a .context/ directory in your project root:
your-project/
āāā .context/ # Context management directory
ā āāā main.md # Project goals, milestones, shared TODOs
ā āāā .current_branch # Current branch pointer (hidden file)
ā āāā branches/
ā āāā <branch-name>/ # One directory per branch
ā āāā commits.yaml # Checkpoint history (structured)
ā āāā log.yaml # Detailed reasoning steps (append-only)
ā āāā metadata.yaml # Branch metadata (file structure, env, etc.)
āāā src/ # Your actual project code
āāā ...
Important: The .context/ directory should be committed to git so context is shared across machines and team members.
Troubleshooting
MCP Server Not Working
Problem: AI doesn't have access to context tools
Solutions:
- Check the config file path - Make sure you edited the correct config file for your tool
- Verify the
cwdpath - Use absolute paths, not relative ones - Check Python path - Ensure
python3is in your PATH - Restart your AI tool - MCP configs are only loaded on startup
- Check for errors - Look in your AI tool's logs/console for MCP errors
Workspace Not Detected
Problem: context_status() shows wrong workspace or "not found"
Solutions:
- Set workspace manually: The AI can call
context_set_workspace(workspace_path="/path/to/project") - Ensure git repository: The system auto-detects via git root
- Create
.context/manually: If needed, create.context/in your project root
Branch Detection Not Working
Problem: AI creates new branches instead of switching to existing ones
Solutions:
- Use descriptive hints: When the AI calls
context_detect_branch(), provide clear context - Check branch names: Existing branches are matched by name similarity
- Manual switch: You can ask the AI to switch branches explicitly
Context Not Persisting
Problem: Context is lost between sessions
Solutions:
- Check
.context/exists: The directory should be in your project root - Verify git commit: Make sure
.context/is committed to git - Check branch: Ensure you're on the same branch as before
Development
This tool is under active development. See TODO.md for implementation progress.
Contributing
Contributions are welcome! The system is designed to be extensible and modular.
Requirements
- Python 3.8+
- See
requirements.txtfor dependencies
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.