Automatically inject project-specific knowledge, schemas, and code patterns into Claude Code based on what you're working on.
Type "create a form" → Claude receives your forms documentation, relevant Zod schemas, code usage examples, and BMAD workflow suggestions before processing your prompt.
Getting Started? See INTEGRATION-GUIDE.md for step-by-step setup instructions, including how to create knowledge files from scratch.
- 🌍 Global Skills — Set
"global": trueto always inject (no trigger required) - 📊 Priority Sorting — Output sorted by priority level (critical → high → medium → low)
- ⚡ File Caching — Cached file locations for better performance on large codebases
- 🔌 Pluggable Schema Extractors — Built-in support for Zod, Yup, and Valibot (configurable)
- 📚 Knowledge Injection — Summarizes markdown docs and injects key points
- 📐 Schema Discovery — Finds and extracts relevant schemas from your codebase (Zod, Yup, Valibot)
- 🔧 Code Pattern Extraction — Shows usage examples from your existing code
- 🤖 BMAD Agent Suggestions — Recommends relevant agents and workflows
⚠️ Guardrails — Warns before potentially problematic operations- 🎯 Priority-Based Filtering — Critical/high priority auto-injects, medium/low suggests only
- 🌍 Global Skills — Always-active skills that inject on every prompt
- ⚡ Caching — File location caching for performance
- 🐛 Debug Mode — Set
DEBUG_HOOK=1for error logging
You: "Create a form for adding team members"
Claude receives (before your prompt):
╔═══════════════════════════════════════════════════════════╗
║ ____ __ __ _ ____ ║
║ | __ )| \/ | / \ | _ \ ║
║ | _ \| |\/| | / _ \ | | | | ║
║ | |_) | | | |/ ___ \| |_| | ║
║ |____/|_| |_/_/ \_\____/ Context Injection System ║
╚═══════════════════════════════════════════════════════════╝
📋 INJECTED PROJECT CONTEXT
────────────────────────────────────────
📚 Knowledge: knowledge/forms-validation.md
# Forms & Validation Patterns
## Required Libraries
- `react-hook-form` — Form state management
- `zod` — Schema validation
## Critical Rules
1. NO generic on useForm — Let zodResolver infer types
2. Schema in separate file — Shared between client/server
📐 Schema: apps/web/app/.../member.schema.ts
export const CreateMemberSchema = z.object({
name: z.string().min(1),
email: z.string().email(),
role: z.enum(['admin', 'member']),
});
🔧 Pattern: apps/web/app/.../member-form.tsx
const form = useForm({
resolver: zodResolver(CreateMemberSchema),
});
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
🎯 SKILL ACTIVATION SUGGESTIONS
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
🤖 BMAD AGENT AVAILABLE
────────────────────────────────────────
🤖 bmad-dev
Developer agent for implementing stories
💡 Consider activating: /bmad:bmm:agents:dev
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
💡 TIP: Review suggestions above before proceeding
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
# Copy the .claude folder to your project root
cp -r .claude /path/to/your/project/
# Copy knowledge files (or create your own)
cp -r knowledge /path/to/your/project/cd /path/to/your/project
npm install -D tsxInstalling in your project root ensures
npxfinds it quickly without re-downloading.
Edit .claude/skills/skill-rules.json to match your project's patterns.
Add markdown files to knowledge/ documenting your project's conventions.
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ Your Prompt │────▶│ Hook Script │────▶│ Injected │
│ "create form" │ │ - Match skills │ │ Context + │
│ │ │ - Extract docs │ │ Suggestions + │
│ │ │ - Find schemas │ │ Your Prompt │
│ │ │ - Find patterns │ │ │
└─────────────────┘ └──────────────────┘ └─────────────────┘
- UserPromptSubmit hook runs before every prompt
- Skill rules map keywords/patterns to knowledge files and actions
- Hook script extracts and formats relevant content
- Claude receives the injected context before your prompt
your-project/
├── .claude/
│ ├── settings.json # Hook registration
│ ├── hooks/
│ │ ├── context-injection.ts # Main hook script
│ │ ├── package.json # Dependencies (tsx)
│ │ └── tsconfig.json
│ └── skills/
│ └── skill-rules.json # Keyword → knowledge mapping
│
└── knowledge/ # Your pattern documentation
├── forms-validation.md
├── server-actions.md
├── database-patterns.md
└── ...
{
"hooks": {
"UserPromptSubmit": [
{
"hooks": [
{
"type": "command",
"command": "npx tsx .claude/hooks/context-injection.ts"
}
]
}
]
}
}{
"version": "2.1",
"config": {
"contextInjection": {
"enabled": true,
"maxKnowledgeLines": 50,
"maxSchemaLines": 30,
"maxPatternLines": 20,
"schemaSearchDirs": ["apps", "packages", "src", "lib"],
"cacheEnabled": true,
"cacheTTLSeconds": 300,
"schemaExtractors": [
{
"name": "zod",
"filePattern": ".schema.ts",
"extractPatterns": ["export\\s+(const|type)\\s+\\w+.*=.*z\\."]
}
]
}
},
"skills": {
"global-anti-patterns": {
"type": "knowledge",
"priority": "critical",
"global": true,
"description": "Anti-patterns to avoid (always active)",
"knowledgeFile": "knowledge/anti-patterns.md"
},
"forms": {
"type": "knowledge",
"priority": "high",
"description": "Forms and validation patterns",
"knowledgeFile": "knowledge/forms-validation.md",
"promptTriggers": {
"keywords": ["form", "validation", "zod"],
"intentPatterns": ["(create|build).*?form"]
},
"fileTriggers": {
"pathPatterns": ["**/*-form.tsx"],
"contentPatterns": ["useForm", "zodResolver"]
},
"contextInjection": {
"enabled": true,
"includeSchemas": true,
"includePatterns": true,
"schemaPatterns": ["form", "input"]
}
}
}
}| Type | Purpose | Auto-Inject |
|---|---|---|
knowledge |
Injects documentation from markdown files | ✅ (high/critical) |
agent |
Suggests a BMAD agent slash command | ❌ |
workflow |
Suggests a BMAD workflow to run | ❌ |
skill |
Suggests a Claude Code skill | ❌ |
guardrail |
Shows warning before proceeding | ✅ (always) |
| Priority | Behavior |
|---|---|
critical |
Always inject content + show prominently |
high |
Auto-inject content + show suggestion |
medium |
Show suggestion only (no injection) |
low |
Skip unless contextInjection.enabled: true |
| Option | Description |
|---|---|
enabled |
Force enable/disable injection for this skill |
includeSchemas |
Find *.schema.ts files matching patterns |
includePatterns |
Find code examples via fileTriggers.contentPatterns |
schemaPatterns |
Patterns to search for in schema file content |
Set "global": true on any skill to make it always active — no trigger required:
{
"global-anti-patterns": {
"type": "knowledge",
"priority": "critical",
"global": true,
"description": "Anti-patterns to avoid (always active)",
"knowledgeFile": "knowledge/anti-patterns.md"
}
}Global skills are useful for:
- Anti-patterns that should always be visible
- Project conventions that apply to all code
- Critical warnings that shouldn't be forgotten
File caching improves performance on large codebases by caching schema file locations:
{
"config": {
"contextInjection": {
"cacheEnabled": true,
"cacheTTLSeconds": 300
}
}
}- Cache is stored in
.claude/.cache/file-cache.json - Default TTL is 5 minutes (300 seconds)
- Cache is invalidated when files are deleted
- Set
cacheEnabled: falseto disable
Configure extractors for different validation libraries:
{
"config": {
"contextInjection": {
"schemaExtractors": [
{
"name": "zod",
"filePattern": ".schema.ts",
"extractPatterns": ["export\\s+(const|type)\\s+\\w+.*=.*z\\."]
},
{
"name": "yup",
"filePattern": ".schema.ts",
"extractPatterns": ["export\\s+(const|type)\\s+\\w+.*=.*yup\\."]
},
{
"name": "valibot",
"filePattern": ".schema.ts",
"extractPatterns": ["export\\s+(const|type)\\s+\\w+.*=.*v\\."]
}
]
}
}
}Default extractors for Zod, Yup, and Valibot are included. Add custom extractors for other libraries.
Case-insensitive substring matching:
"keywords": ["form", "validation", "zod"]For complex matching with capture groups:
"intentPatterns": [
"(create|build|add|make).*?form",
"(validate|check).*?(input|data)"
]Find code patterns in your codebase:
"fileTriggers": {
"pathPatterns": ["**/*-form.tsx", "**/*.schema.ts"],
"contentPatterns": ["useForm", "zodResolver", "FormField"]
}# Windows (PowerShell)
$env:DEBUG_HOOK="1"; echo '{"prompt":"create a form"}' | npx tsx .claude/hooks/context-injection.ts
# Linux/Mac
echo '{"prompt":"create a form"}' | DEBUG_HOOK=1 npx tsx .claude/hooks/context-injection.ts| Issue | Solution |
|---|---|
| Hook not running | Check .claude/settings.json is valid JSON |
| No output | Verify keywords match and knowledge files exist |
| Errors silently | Run with DEBUG_HOOK=1 to see errors |
| Wrong schemas found | Adjust schemaPatterns or schemaSearchDirs |
This is part of the BMAD Method — an AI-driven agile development framework.
{
"bmad-dev": {
"type": "agent",
"priority": "high",
"description": "Developer agent for implementing stories",
"slashCommand": "/bmad:bmm:agents:dev",
"promptTriggers": {
"keywords": ["implement", "build feature", "code this"]
},
"suggestion": "Consider activating: /bmad:bmm:agents:dev"
}
}{
"dev-story": {
"type": "workflow",
"priority": "high",
"description": "Execute story implementation",
"slashCommand": "/bmad:bmm:workflows:dev-story",
"promptTriggers": {
"keywords": ["implement story", "execute story"]
}
}
}{
"no-story-warning": {
"type": "guardrail",
"priority": "critical",
"description": "Reminder to load story context",
"promptTriggers": {
"intentPatterns": ["^implement.*?feature$"]
},
"suggestion": "⚠️ Ensure you have a story loaded first!"
}
}See the knowledge/ folder for examples:
forms-validation.md— React Hook Form + Zod patternsserver-actions.md— Server Actions and data fetchingdatabase-patterns.md— Supabase, RLS, migrationsui-components.md— Shadcn/UI component usagetesting.md— Playwright E2E testing patterns
MIT — Use however you like.
PRs welcome! Especially for:
- Additional framework knowledge files
- New skill types and patterns
- Hook improvements
- Documentation