Skip to main content

Activating in Your Agent

Claude Code (CLAUDE.md)

Add the strategy block to your project's CLAUDE.md file. Claude Code reads this file automatically and applies the instructions to every interaction.

# CLAUDE.md

## Search & Generation Strategy

tea-rags is available as an MCP server. Use it for ALL code search.

### Before generating code:
1. Find a stable template: `search_code` with `rerank: "stable"`
- Only use results with chunkBugFixRate < 25%, chunkCommitCount <= 5
2. Check target area: `semantic_search` with `rerank: "hotspots"`, `metaOnly: true`
- chunkBugFixRate > 40% + chunkAgeDays > 60 → wrapper pattern + feature flag
- chunkCommitCount > 8 → simplify, reduce complexity
- chunkAgeDays > 180 → minimal changes only
3. Match domain owner: `semantic_search` with `rerank: "ownership"`, `metaOnly: true`

### After generating code:
4. Verify with ripgrep: confirm ALL referenced functions, imports, and types exist
- Semantic search finds by meaning, not exact identifiers
- 0 ripgrep matches for a referenced function = fix the reference before committing
5. Check blast radius: `semantic_search` with `rerank: { custom: { imports: 0.7, similarity: 0.3 } }`, `metaOnly: true`

### Never:
- Copy code from results with chunkBugFixRate > 50%
- Modify single-owner code without flagging the owner
- Change code with relativeChurn > 5.0 without proposing a rewrite
- Trust generated identifiers without ripgrep verification

Cursor (.cursorrules)

# .cursorrules

## Code Search

Use tea-rags MCP server for code search. Before writing new code:

Search for stable templates:
- Use rerank="stable" to find low-churn, battle-tested implementations
- Reject results with chunkBugFixRate > 40% — find alternatives
- Prefer results with chunkCommitCount <= 3 and chunkAgeDays > 60

Assess risk before modifying existing code:
- Use rerank="hotspots" with metaOnly=true on the target area
- If chunkBugFixRate > 40% and code is older than 60 days, use wrapper pattern
- If `blameDominantAuthorPct` label is `silo` or `deep-silo`, match the
live-line owner's style exactly (their lines are still in the file)

Match coding style to domain owner:
- Use rerank="ownership" on the target directory (live-line, blame-based)
- Follow the live-line owner's (`blameDominantAuthor`) error handling,
naming, and structure patterns
- For review routing, prefer `recentDominantAuthor` (recent commit window) —
the live-line owner may have moved on

After generating code, verify with ripgrep:
- Confirm all referenced function names, imports, and types actually exist
- Semantic search finds by meaning, not exact identifiers — always verify
- 0 ripgrep matches = fix the reference before committing

Custom Agents (system prompt)

For agents built with the Claude API or other LLM frameworks:

You have access to a tea-rags MCP server for semantic code search with
git-derived quality signals.

TEMPLATE SELECTION:
Use search_code with rerank="stable" to find templates.
A good template has: chunkBugFixRate < 25%, chunkCommitCount <= 5, chunkAgeDays > 60.
Never base new code on results with chunkBugFixRate > 50%.

RISK ASSESSMENT:
Before modifying code, use semantic_search with rerank="hotspots"
and metaOnly=true on the target area.
Switch to defensive mode (wrapper pattern) if:
chunkBugFixRate > 40% AND chunkAgeDays > 60.

STYLE MATCHING:
Use semantic_search with rerank="ownership" to find the live-line owner
(`blameDominantAuthor` from `git blame HEAD`).
If `blameDominantAuthorPct` label is `concentrated`, `silo`, or `deep-silo`,
match their patterns exactly — their lines are still in the file.
If ownership label is `shared`, use project-wide conventions.
For review routing, use `recentDominantAuthor` (recent commit window) — they
are the ones mentally loaded into the area right now.

POST-GENERATION VERIFICATION (MANDATORY):
After generating code, use ripgrep to verify ALL referenced identifiers:
- Function names, import paths, type names must return > 0 matches
- Semantic search finds by meaning, not exact tokens
- 0 matches = hallucinated identifier, fix before committing

The Transformation

AspectBefore (similarity-only RAG)After (data-driven generation)
Template selectionFirst search hitLowest bug rate, proven in production
Style guideGeneric language conventionsDomain owner's actual patterns
Anti-patternsUnknown, invisibleExplicitly identified and avoided
Feature contextMissing — code exists in a vacuumtaskIds reveal evolution and intent
Risk assessmentNo signal — all code treated equallyMetrics-driven defensive strategies
Generation modeOne mode for everythingDynamically adapted to target area context
VerificationTrust semantic results as-isRipgrep verification of all referenced identifiers
Decision basis"Looks right"Measurable evidence from version history

This is the shift from "find similar code" to context-aware engineering — where the agent reasons about the quality, history, and ownership of every code decision it makes.

See Also