Skip to main content

Adaptive Neural Knowledge System + PostToolUse compression hooks. Two-phase token optimization (retrieval + consumption) for Claude Code.

Project description

๐Ÿง  NeuralMind

PyPI version License: MIT Python 3.10+

Two-phase token optimization for Claude Code โ€” smart retrieval + tool-output compression in one package.

Most tools save tokens on what you fetch OR on what Claude sees back โ€” never both. NeuralMind v0.2.0 does both in one pip install.

โšก Two-phase optimization

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Phase 1: Retrieval โ€” what to fetch                          โ”‚
โ”‚   neuralmind wakeup .    โ†’  ~365 tokens (vs 50K raw)        โ”‚
โ”‚   neuralmind query "?"   โ†’  ~800 tokens (vs 2,700 raw)      โ”‚
โ”‚   mcp: neuralmind_skeleton  โ†’  graph-backed file view       โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Phase 2: Consumption โ€” what Claude actually sees            โ”‚
โ”‚   PostToolUse hooks compress Read/Bash/Grep output          โ”‚
โ”‚   File reads โ†’ graph skeleton (~88% reduction)              โ”‚
โ”‚   Bash output โ†’ errors + summary (~91% reduction)           โ”‚
โ”‚   Search results โ†’ capped at 25 matches                     โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Combined effect: 5-10ร— total reduction vs baseline Claude Code.

๐ŸŽฏ The Problem

You: "How does authentication work in my codebase?"

โŒ Traditional: Load entire codebase โ†’ 50,000 tokens โ†’ $0.15-$3.75/query
โœ… NeuralMind: Smart context โ†’ 766 tokens โ†’ $0.002-$0.06/query

๐Ÿ’ฐ Real Savings

Model Without NeuralMind With NeuralMind Monthly Savings
Claude 3.5 Sonnet $450/month $7/month $443
GPT-4o $750/month $12/month $738
GPT-4.5 $11,250/month $180/month $11,070
Claude Opus $2,250/month $36/month $2,214

Based on 100 queries/day. Pricing sources

๐Ÿš€ Quick Start

# Install
pip install neuralmind graphifyy

# Generate knowledge graph
cd your-project
graphify update .

# Build neural index
neuralmind build .

# (v0.2.0) Install PostToolUse hooks โ€” compresses Read/Bash/Grep
neuralmind install-hooks .

# Query your codebase
neuralmind query . "How does authentication work?"

# (v0.2.0) Skeleton view of a file without loading source
neuralmind skeleton tools/voiceover.py

โœจ Key Features

Feature Description
4-Layer Context Progressive disclosure โ€” only loads what's relevant
Semantic Search Finds code by meaning, not just keywords
Query-Aware Different questions get different context
CLI Tool Simple commands: build, query, wakeup, search
MCP Server Direct integration with Claude Desktop & Cursor
Auto-Updates Git hooks and scheduled maintenance

๐Ÿ“Š Benchmarks

Project Nodes Avg Token Reduction
cmmc20 (React/Node) 241 65.6x
mempalace (Python) 1,626 46.0x

๐Ÿ”ง How It Works

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Layer 0: Project Identity (~100 tokens) - ALWAYS LOADED     โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Layer 1: Architecture Summary (~300 tokens) - ALWAYS LOADED โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Layer 2: Relevant Modules (~300 tokens) - QUERY-SPECIFIC    โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Layer 3: Semantic Search (~300 tokens) - QUERY-SPECIFIC     โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Total: ~800-1,100 tokens vs 50,000+ for full codebase

๐Ÿ“‹ Use Cases

  1. Daily Development โ€” Get context for AI coding questions
  2. New Developer Onboarding โ€” Generate project overviews
  3. Code Review โ€” Understand related code quickly
  4. Documentation โ€” AI-assisted docs from actual code
  5. CI/CD Integration โ€” Auto-update context files
  6. IDE Integration โ€” MCP server for Claude/Cursor

๐Ÿ‘‰ See full use cases and examples in USAGE.md

๐Ÿ–ฅ๏ธ CLI Commands

Command Purpose
neuralmind build . Build/rebuild neural index
neuralmind query . "..." Query with natural language
neuralmind wakeup . Get project overview
neuralmind search . "..." Direct semantic search
neuralmind benchmark . Measure token reduction
neuralmind stats . Show index statistics
neuralmind skeleton <file> v0.2.0 Compact graph-backed file view
neuralmind install-hooks . v0.2.0 Install PostToolUse compression hooks (project)
neuralmind install-hooks --global v0.2.0 Install hooks globally for all projects
neuralmind install-hooks --uninstall v0.2.0 Remove hooks (preserves other tools' hooks)
neuralmind init-hook . Install git post-commit hook (auto-rebuild on commit)

๐Ÿช PostToolUse Compression (v0.2.0)

NeuralMind ships with Claude Code hooks that compress tool outputs before the model sees them:

Tool Compression Typical savings
Read Replaces raw source with graph skeleton (functions, rationales, call graph) ~88%
Bash Keeps errors + last 3 lines + summary; drops routine output ~91%
Grep Caps at 25 matches + "N more hidden" pointer varies

Install per-project (recommended):

cd my-project
neuralmind install-hooks .    # writes .claude/settings.json

Install globally (all projects):

neuralmind install-hooks --global    # writes ~/.claude/settings.json

Bypass temporarily (for debugging):

NEURALMIND_BYPASS=1 claude-code ...

Uninstall cleanly (preserves other hooks):

neuralmind install-hooks --uninstall    # project
neuralmind install-hooks --uninstall --global    # global

The hook installer is idempotent and non-destructive โ€” existing hooks from other tools (Prettier, Black, etc.) are preserved.

Coming from Pith?

NeuralMind v0.2.0 provides full Pith-parity compression plus graph-backed retrieval โ€” both in one package. Migration:

# Remove Pith global hooks, then:
pip install neuralmind
neuralmind install-hooks --global

Unlike Pith's regex-based skeletonization, NeuralMind uses the semantic graph you've already built, so skeletons include rationales, call graphs, and cross-file edges that regex can't extract.

โฐ Scheduling Updates

Git Hook (Recommended)

# .git/hooks/post-commit
#!/bin/bash
graphify update . --quiet
neuralmind build . --quiet

Cron Job

# Daily at 6 AM
0 6 * * * cd /project && graphify update . && neuralmind build .

CI/CD

- run: pip install neuralmind graphifyy
- run: graphify update . && neuralmind build .
- run: neuralmind wakeup . > AI_CONTEXT.md

๐Ÿ‘‰ See full scheduling guide in USAGE.md

๐Ÿ”Œ MCP Server Integration

For Claude Desktop or Cursor:

{
  "mcpServers": {
    "neuralmind": {
      "command": "neuralmind-mcp",
      "args": ["/path/to/project"]
    }
  }
}

Exposed MCP tools (v0.2.0):

Tool Purpose
mcp__neuralmind__wakeup Minimal project overview (~365 tokens)
mcp__neuralmind__query Natural language code query (~800 tokens)
mcp__neuralmind__search Direct semantic search with scores
mcp__neuralmind__skeleton v0.2.0 Compact file view (functions, rationales, calls)
mcp__neuralmind__stats Index health
mcp__neuralmind__benchmark Measure token reduction
mcp__neuralmind__build Rebuild index

Project-scoped auto-registration: drop a .mcp.json at your project root and Claude Code loads it on open:

{
  "mcpServers": {
    "neuralmind": {
      "command": "neuralmind-mcp",
      "args": ["."]
    }
  }
}

๐Ÿ“š Documentation

๐Ÿค Contributing

See CONTRIBUTING.md for guidelines.

๐Ÿ“„ License

MIT License โ€” see LICENSE for details.


โญ Star this repo if NeuralMind saves you money!

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

neuralmind-0.2.2.tar.gz (30.5 kB view details)

Uploaded Source

Built Distribution

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

neuralmind-0.2.2-py3-none-any.whl (35.0 kB view details)

Uploaded Python 3

File details

Details for the file neuralmind-0.2.2.tar.gz.

File metadata

  • Download URL: neuralmind-0.2.2.tar.gz
  • Upload date:
  • Size: 30.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for neuralmind-0.2.2.tar.gz
Algorithm Hash digest
SHA256 be9782614692ef6860f69f5b117fe075758fddd73fef29b4a861a971b8a576c6
MD5 84cfc826ca79388628cc4c12522ac4ef
BLAKE2b-256 ad0d397321f62cd52f1f46f6721b8459398d8ec6e3a5865f336c4c8e46673990

See more details on using hashes here.

Provenance

The following attestation bundles were made for neuralmind-0.2.2.tar.gz:

Publisher: release.yml on dfrostar/neuralmind

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

File details

Details for the file neuralmind-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: neuralmind-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 35.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for neuralmind-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e937db09820bda5ae26a1aabddb9162a877cfd4728b30ed53e425097a451ce82
MD5 cc1d2c95886e3c344dce67c5ea54381e
BLAKE2b-256 ec95d7b9916abd6eb69594c62567539df238ef25e91c4768dde8720b426ed501

See more details on using hashes here.

Provenance

The following attestation bundles were made for neuralmind-0.2.2-py3-none-any.whl:

Publisher: release.yml on dfrostar/neuralmind

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