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.
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.
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 |
git clone https://github.com/friends0485-cyber/context-feeder.gitCreate .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
'''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.
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"
}]
}
]
}
}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.
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)
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.pyThe scanner traverses all .toml files, extracts tags fields, and rebuilds tags.json automatically.
Same file won't be re-injected within 30 minutes (configurable). Prevents context flooding when the same keywords appear repeatedly.
Counter resets session counts at each session start, so ranking thresholds reset fresh every session.
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.
- Claude Code (with hooks support)
- Python 3.11+ (for
tomllib) orpip install tomli - Bash (Git Bash on Windows works)
| 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 |
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.
MIT — see LICENSE
Built by Leo KIM · AI Automation Engineer · @leokim_KR
