Cortex

Cortex

Enables AI coding assistants to semantically search and retrieve relevant code patterns, documentation, and implementations from a codebase via MCP tools.

Category
Visit Server

README

๐Ÿง  Cortex: Open-Source AI Memory for your Codebase. Works with Claude CLI and others

Never Explain Your Codebase Twice.

MIT License GitHub Stars Buy Me a Coffee

100% Local 100% Free Zero API Costs

TypeScript Node.js PostgreSQL Docker MCP

๐ŸŽฏ What is Cortex ยท ๐Ÿ‘ฅ Who Needs It ยท โšก How It Works ยท ๐Ÿš€ Quick Start ยท ๐Ÿ“– Docs ยท โ“ FAQ


๐ŸŽฏ What is Cortex?

Cortex is a semantic memory layer for AI coding assistants. It indexes your codebase into a vector database, so AI can find relevant code by meaning โ€” not just keywords.

<table> <tr> <td width="50%">

โŒ Without Cortex

You: "Add payment processing"

Claude Code:
  โ†’ Reads CLAUDE.md (if exists)
  โ†’ Reads README.md
  โ†’ Maybe searches some files
  โ†’ Picks random agents (unpredictable)
  โ†’ Misses your PaymentService
  โ†’ Creates duplicate from scratch

</td> <td width="50%">

โœ… With Cortex

You: "Add payment processing"

Claude Code:
  โ†’ Reads CLAUDE.md (finds Cortex instructions)
  โ†’ Loads Cortex memory agent
  โ†’ Queries MCP: "payment processing"
  โ†’ Gets: PaymentService, StripeClient, docs
  โ†’ Extends YOUR existing code

</td> </tr> </table>


๐Ÿ‘ฅ Who Needs Cortex?

You should use Cortex if... Why it helps
๐Ÿข Your codebase has 20+ files AI can't hold everything in context
๐Ÿ”„ You've had AI rewrite existing code Cortex finds it first
๐Ÿ“š You have docs AI keeps ignoring Semantic search surfaces them
๐Ÿค Your team has established patterns AI learns and follows them
๐Ÿ’ธ You want free, local, private No cloud, no API costs

โšก How It Works

flowchart TB
    subgraph INPUT["๐Ÿ“ Your Codebase"]
        A1[src/services/payment.ts]
        A2[src/utils/logger.ts]
        A3[docs/API.md]
        A4[README.md]
    end

    subgraph CORTEX["๐Ÿง  Cortex Processing"]
        B1[๐Ÿ“„ Chunk Files]
        B2[๐Ÿ”ข Generate Embeddings]
        B3[(๐Ÿ—„๏ธ Vector Database)]
    end

    subgraph QUERY["๐Ÿค– AI Assistant"]
        C1["User: Add email notifications"]
        C2[๐Ÿ” cortex_query]
        C3[๐Ÿ“‹ Results]
        C4[โœ… Writes Code]
    end

    A1 & A2 & A3 & A4 --> B1
    B1 --> B2
    B2 --> B3

    C1 --> C2
    C2 -->|"search: notification"| B3
    B3 -->|"Found: NotificationService, EmailClient, logging patterns"| C3
    C3 --> C4
Step What Happens
1๏ธโƒฃ Index Cortex chunks your code into ~1024 char pieces and creates semantic embeddings
2๏ธโƒฃ Query AI asks natural language questions: "how do we handle notifications?"
3๏ธโƒฃ Build AI receives relevant files and patterns, writes consistent code

๐Ÿš€ Quick Start

Step 1 ยท Add Cortex

cd your-project
git submodule add https://github.com/Remskill/Cortex.git cortex
cd cortex && cp .env.example .env && npm install

Step 2 ยท Configure Ignore Patterns

โš ๏ธ Do this BEFORE syncing! Skips junk to be added to your memory.

cp docs/.cortexignore.default ../.cortexignore

Step 3 ยท Start Services

docker-compose up -d

Wait for model to be ready img.png

โฑ๏ธ First run downloads the embedding model (~274MB, 2-5 min)

Step 4 ยท Initialize

npm run setup

Step 5 ยท Configure MCP

Create .mcp.json in your project root:

{
  "mcpServers": {
    "cortex": {
      "command": "npx",
      "args": ["tsx", "cortex/src/server.ts"],
      "env": {
        "DATABASE_URL": "postgres://cortex:cortex-dev-pass-123@localhost:5433/cortex",
        "OLLAMA_URL": "http://localhost:11434"
      }
    }
  }
}

Step 6 ยท Restart Claude Code

Run /exit and reopen. Verify with /mcp โ†’ should see cortex: connected

MCP Connected

Step 7 ยท Install Git Hook

๐Ÿ”ด Required โ€” keeps AI memory in sync with your code

npm run hook:install

Step 8 ยท Create Cortex Memory Agent (Recommended)

๐Ÿ’ก Why? Agents ensure Claude Code automatically queries Cortex before implementing features.

Option A: Using Claude Code CLI (recommended)

/agents
# โ†’ Select "Create new agent"
# โ†’ Follow prompts to create an agent for searching codebase patterns
# โ†’ Name it something like "cortex-memory-agent"

Option B: Copy example agent

# Copy the pre-built agent definition
cp cortex/docs/cortex-memory-agent.md .claude/agents/cortex-memory-agent.md

See docs/cortex-memory-agent.md for a complete agent example.

Step 9 ยท Add to CLAUDE.md

Tell Claude cli to always use your Cortex agent:

## Cortex Memory
**ALWAYS use the cortex-memory-agent before implementing ANY feature.**
This agent will query Cortex to find existing patterns and prevent code duplication.

Manual query example:
cortex_query("what you're building")

โœ… Done!

cortex_query("how we handle API errors")
cortex_query("existing notification system")
cortex_query("database connection patterns")

๐Ÿ”„ Git Auto-Sync

After installing the hook, Cortex syncs automatically on every commit:

git commit -m "Add new feature"
# ๐Ÿ”„ Syncing changed files...
# โœ… src/feature.ts (12 chunks)
# โœ… docs/FEATURE.md (5 chunks)
Benefit Description
๐Ÿค– Zero effort Happens automatically
โšก Incremental Only changed files
๐ŸŽฏ Always fresh AI never sees stale code

๐Ÿ› ๏ธ MCP Tools Reference

Tool Purpose
cortex_query Search by meaning
cortex_sync Manual file sync
cortex_stats Database stats
cortex_init Health check
cortex_list_files List indexed files
cortex_delete Remove from index

Query Examples

// Find existing implementations
cortex_query("payment processing")
cortex_query("user session management")

// Find patterns
cortex_query("how we handle errors in API routes")
cortex_query("state management approach")

// Find documentation
cortex_query("deployment process")
cortex_query("environment configuration")

๐Ÿ’ก Tip: Be specific. "how we validate user input in forms" beats "validation".


๐Ÿ“ Configuration

.cortexignore

Controls what gets indexed. Copy the default:

cp cortex/docs/.cortexignore.default .cortexignore

Auto-excluded: node_modules, dist, build, .git, binary files

.cortexconfig.json (Optional)

{
  "maxFileSize": 52428800
}

52428800 = 50MB. Also accepts "50MB" string format.


๐Ÿ’ป System Requirements

Component Minimum
Docker Docker Desktop or Engine
RAM 4GB (8GB recommended)
Disk ~2GB for models
Node.js v18+

๐Ÿ”ง Troubleshooting

<details> <summary><strong>Services won't start</strong></summary>

docker ps                    # Is Docker running?
docker-compose logs          # Check errors
docker-compose down && docker-compose up -d

</details>

<details> <summary><strong>No results from queries</strong></summary>

cortex_stats()      // Check if data exists
cortex_list_files() // List what's indexed

If empty, run npm run db:sync </details>

<details> <summary><strong>Emergency reset</strong></summary>

docker-compose down -v   # Delete all data
docker-compose up -d     # Fresh start
npm run setup            # Reinitialize

</details>


โ“ FAQ

<details> <summary><strong>Is it really free?</strong></summary>

Yes. MIT licensed, no API costs, no subscriptions. Embeddings run locally via Ollama. </details>

<details> <summary><strong>Does my code leave my machine?</strong></summary>

No. Everything runs in local Docker containers. Your code never leaves localhost. </details>

<details> <summary><strong>What languages work?</strong></summary>

All of them. Cortex indexes text content โ€” TypeScript, Python, Go, Rust, Java, C++, Markdown, everything. </details>

<details> <summary><strong>How is this different from grep?</strong></summary>

Grep finds exact text matches. Cortex finds meaning:

  • Search "user authentication" โ†’ finds login handlers, JWT code, session management
  • Even if none of those files contain the words "user authentication" </details>

๐Ÿค Contributing

All contributions welcome:

  • ๐Ÿ› Bug reports
  • ๐Ÿ’ก Feature ideas & suggestions
  • ๐Ÿ“ Documentation improvements
  • ๐Ÿ”ง Code contributions

Have an idea? Open a GitHub Issue โ€” we discuss everything!

Fork โ†’ Branch โ†’ PR โ†’ We'll review and merge together.


๐Ÿ” Similar Projects

If Cortex isn't the right fit, check out Zep โ€” they solve a similar problem (agent context/memory) with a different approach. We discovered them after building Cortex and found the ideas surprisingly similar. Worth exploring if you need alternatives!


๐Ÿ’– Support

<a href="https://buymeacoffee.com/denys_medvediev"> <img src="https://img.shields.io/badge/โ˜•-Buy%20Me%20a%20Coffee-yellow.svg?style=for-the-badge" alt="Buy Me a Coffee"> </a>


๐Ÿ”— Links

GitHub ยท Issues ยท LinkedIn


<div align="center">

Made with โค๏ธ by Denys Medvediev

โญ Star this repo if it helps you! โญ

</div>

Recommended Servers

playwright-mcp

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.

Official
Featured
TypeScript
Magic Component Platform (MCP)

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.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

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.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

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.

Official
Featured
TypeScript
Kagi MCP Server

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.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

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.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured