memforge-codebase-memory-routing

Code-discovery rules for projects connected to Codegraph, a service that indexes code structure for queries. They define when to use Codegraph and when to use ordinary file searches.

In plain words
What is it for?
Use them to locate definitions, callers, callees, call paths, affected symbols, related source files, and project file structures.
Why use it?
They help agents find relevant code with fewer manual searches and less text to read.

Cursor rule

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/zql0805/memforge/memforge-codebase-memory-routing
Clone the repo
git clone --depth 1 https://github.com/zql0805/memforge
Per session 641 This file is loaded in full into every session.
When invoked 641 The same file — it is already loaded in full.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00641 $0.00641
Opus 5 $0.00320 $0.00320
Sonnet 5 $0.00128 $0.00128
Haiku 4.5 $0.00064 $0.00064

Measured yesterday against content hash 1144e346a652, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

memforge-codebase-memory-routing scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

packages/memory-service/src/rules-templates/memforge-codebase-memory-routing.mdc · 50 lines

What it actually says

代码发现工具路由策略

核心原则

当需要理解代码结构时,优先使用 Codegraph MCP 的结构化工具,而非 Grep/Glob/Read 全文搜索。 Codegraph 基于 AST 实时解析,已索引多个仓库,查询精确且 Token 消耗低。

工具选择决策树

需要做的事 首选(Codegraph) 备选(传统工具)
根据任务描述获取相关代码 codegraph_context(task) 手动 Grep + Read 多文件
查找函数/类/方法定义 codegraph_search(query) Grep 按函数名搜索
追踪谁调用了某函数 codegraph_callers(symbol) Grep 逐文件追踪
追踪某函数调了什么 codegraph_callees(symbol) Grep 逐文件追踪
追踪两个符号间的调用路径 codegraph_trace(from, to) 手动逐层追踪
分析修改某符号的影响范围 codegraph_impact(symbol) git diff + 手动分析
批量查看多个相关符号源码 codegraph_explore(symbols) 逐个 Read 文件
查看单个符号签名和位置 codegraph_node(symbol) Grep + Read
查看项目文件结构 codegraph_files(project) ls / Glob

多项目查询

所有工具支持 projectPath 参数切换目标仓库,格式:/opt/memforge/repos/<产品线>/<仓库名>

仍然使用 Grep/Glob/Read 的场景

以下场景直接使用传统工具

  • 文本内容搜索:日志文本、错误消息、配置值、字符串常量
  • 文件名搜索:按文件名模式查找文件(Glob)
  • 配置文件:读取 JSON/YAML/TOML/ENV 等
  • 文档/注释:搜索 Markdown、README、注释
  • 非代码文件:SQL 脚本、Shell 脚本、Dockerfile
  • 已知文件路径:直接 Read

注意事项

  • Codegraph 数据基于 AST 实时解析,代码变更后 ~1s 自动同步
  • 优先使用 codegraph_context(task) —— 描述任务即可获取相关代码,无需精确指定符号名
  • 如果 Codegraph MCP 不可用(服务离线/网络不通),静默回退到 Grep/Glob/Read
Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 50 lines · 641 tokens per session scan A 1144e346a652

Subscribe to this mod's changes

memforge-codebase-memory-routing is a cursor rule published in the GitHub repository zql0805/memforge (2 stars, last pushed 2mo ago), licensed MIT. It adds 641 tokens to every session, about $0.0032 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.