Skip to content

Latest commit

 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🍀 Context Feeder

Give Claude Code a memory that never forgets.

A lightweight context injection engine for Claude Code that automatically feeds relevant rules, docs, and project knowledge into Claude's context — using keyword matching, tag ranking, and shell scripts. No vector database. No embeddings. No cloud API. Just JSON tags + hooks.


Why?

Claude Code reads your CLAUDE.md at session start. But Vercel's research found that skills-based retrieval was skipped in 56% of cases. The model decides what's relevant — and it often decides wrong.

Context Feeder doesn't ask. It injects.

Every time you send a message, the engine matches keywords against your tag database and force-feeds the matched context into Claude's window. No skipping. No forgetting. 100% delivery.


How It Works

Your Message
  │
  ▼
┌─────────────────────────────────────────────────┐
│  prompt_handler.sh (orchestrator)                │
│                                                  │
│  Stage 1: Parser ─── keyword match ──► tags.json │
│  Stage 2: Counter ── count + rank ──► best/norm  │
│  Stage 3: Injector ─ rank check ───► stdout      │
│                                                  │
│  stdout → Claude Code context (force-injected)   │
└─────────────────────────────────────────────────┘

3-Stage Chain:

Stage File Role
Parser tag_search.py Scans your message for keywords, finds matching context files
Counter counter.py Tracks how often each tag is called, assigns rank (best/normal/worst)
Injector tag_injector.sh Checks rank thresholds, reads matched files, outputs to Claude's context

Ranking System:

Rank Threshold Meaning
best Inject on 1st match Frequently used — inject immediately
normal Inject on 2nd match Standard — inject on second occurrence
worst Inject on 3rd match Rarely used — inject reluctantly, auto-delete after 30 days

Quick Start

1. Clone

git clone https://github.com/friends0485-cyber/context-feeder.git

2. Add your context files

Create .toml files in contexts/:

# contexts/my-rules.toml

[rule_001]
title = "API Error Handling"
tags = ["error", "catch", "try", "exception", "handler"]
content = '''
All API endpoints must:
- Wrap async handlers with error middleware
- Return structured error responses { error: string, code: number }
- Log errors with request context
- Never expose stack traces to clients
'''

3. Register keywords

Edit config/tags.json:

{
  "base_path": ".",
  "categories": {
    "my_project": {
      "root": "contexts",
      "files": ["my-rules.toml"],
      "keywords": {
        "rule_001": ["error", "catch", "try", "exception", "handler"]
      },
      "tag_to_file": {
        "rule_001": "my-rules.toml"
      }
    }
  }
}

Tip: Use the scanner (python engine/scanner.py) to auto-generate tags.json from your toml files.

4. Connect to Claude Code hooks

Copy the hook config into your .claude/settings.json:

{
  "hooks": {
    "UserPromptSubmit": [
      {
        "hooks": [{
          "type": "command",
          "command": "bash /path/to/context-feeder/engine/prompt_handler.sh"
        }]
      }
    ],
    "SessionStart": [
      {
        "matcher": "startup|compact|clear",
        "hooks": [{
          "type": "command",
          "command": "python3 /path/to/context-feeder/engine/counter.py reset"
        }]
      }
    ]
  }
}

5. Done

Next time you type a message containing "error handling" or "try catch", Context Feeder automatically injects your API error handling rules into Claude's context. Claude sees it, follows it, every time.


Architecture

context-feeder/
├── engine/                  # Core engine (copy this to use)
│   ├── prompt_handler.sh    # 3-stage chain orchestrator
│   ├── tag_search.py        # Keyword matching parser
│   ├── counter.py           # Tag ranking system
│   ├── tag_injector.sh      # Rank-based context injector
│   └── scanner.py           # Auto-builds tags.json from toml files
│
├── config/                  # User configuration
│   ├── tags.json            # Keyword → file mapping database
│   ├── scan_roots.toml      # Scanner root paths
│   └── settings.json        # Claude Code hooks template
│
├── contexts/                # Your context files go here
│   ├── coding-standards.toml
│   └── architecture-guide.toml
│
└── examples/                # Additional injection patterns
    ├── boot-injector.sh     # Session start context loading
    ├── heart-injector.sh    # Periodic re-injection (time-based)
    └── pre-injector.sh      # Tool-specific rules (before Edit/Write)

Advanced Features

Auto-Scanner

Instead of manually editing tags.json, let the scanner build it:

# Edit config/scan_roots.toml to point to your context directories
# Then run:
python engine/scanner.py

The scanner traverses all .toml files, extracts tags fields, and rebuilds tags.json automatically.

Cooldown

Same file won't be re-injected within 30 minutes (configurable). Prevents context flooding when the same keywords appear repeatedly.

Session Reset

Counter resets session counts at each session start, so ranking thresholds reset fresh every session.

Beyond the Engine

The core 3-stage chain is just the beginning. The author's production system includes 10 interconnected modules:

Module Role
Logger Records all tool usage (21 categories, structured format)
Watchdog Verifies logger output + maintains real-time dashboard
Reminder Detects workflow violations + sends warnings
Console Real-time web UI for monitoring (localhost)
Cleaner Session cleanup + cache management
Boot Injector Session start context loading (heart file + rules)
Heart Injector Time-based periodic re-injection (every 2 hours)
Post Injector Tool-count-based re-injection (every 50 tool uses)
Pre Injector Tool-specific manual injection (before Edit/Write/Read)

See examples/ for starter patterns. Full system guide coming soon.


Requirements

  • Claude Code (with hooks support)
  • Python 3.11+ (for tomllib) or pip install tomli
  • Bash (Git Bash on Windows works)

How is this different from...

Tool Approach Context Feeder
CLAUDE.md Read once at start, model decides relevance Force-injected on every matching message
RAG + Vector DB Embeddings + similarity search + infrastructure JSON keyword match + shell scripts, zero infra
Claude-Mem Session memory (past observations) Rule/knowledge injection (present context)
Skills Model chooses to invoke System forces delivery, no model choice

Contributing

Issues and PRs welcome. This project started as a solo developer's production system for managing an AI coding assistant across 26+ custom resources, and has been extracted into a general-purpose engine.


License

MIT — see LICENSE


Built by Leo KIM · AI Automation Engineer · @leokim_KR


📺 Video

영상 보기

About

Give Claude Code a memory that never forgets. Lightweight context injection engine — no vector DB, just JSON tags + hooks.

Topics

Resources

Stars

7 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages