Skip to content

Commit 4d65d60

Browse files
committed
feat: Update Claude instructions to discourage direct codegraph tool usage in main session
Changes guidance to recommend spawning Explore agents for exploration questions instead of using codegraph_explore/codegraph_context directly in main session to avoid filling up context with large amounts of source code. Adds completeness signal to codegraph_explore output so agents know not to re-read files that already have source code included.
1 parent b927492 commit 4d65d60

2 files changed

Lines changed: 21 additions & 12 deletions

File tree

src/installer/claude-md-template.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,25 @@ CodeGraph builds a semantic knowledge graph of codebases for faster, smarter cod
1616
1717
### If \`.codegraph/\` exists in the project
1818
19-
**Use codegraph tools directly in the main session.** Codegraph replaces the need for Explore agents in most cases. Instead of spawning an agent (which takes 30+ tool calls and 1+ minutes), use codegraph MCP tools directly for fast, structured answers:
19+
**NEVER call \`codegraph_explore\` or \`codegraph_context\` directly in the main session.** These tools return large amounts of source code that fills up main session context. Instead, ALWAYS spawn an Explore agent for any exploration question (e.g., "how does X work?", "explain the Y system", "where is Z implemented?").
2020
21-
| Tool | Use For |
22-
|------|---------|
23-
| \`codegraph_explore\` | **Deep exploration** — comprehensive context for a topic in ONE call (replaces Explore agents) |
24-
| \`codegraph_context\` | Quick context for a task (lighter than explore) |
25-
| \`codegraph_search\` | Find symbols by name (functions, classes, types) |
26-
| \`codegraph_callers\` | Find what calls a function |
27-
| \`codegraph_callees\` | Find what a function calls |
28-
| \`codegraph_impact\` | See what's affected by changing a symbol |
29-
| \`codegraph_node\` | Get details + source code for a symbol |
21+
**When spawning Explore agents**, include this instruction in the prompt:
22+
23+
> This project has CodeGraph initialized (.codegraph/ exists). Use \`codegraph_explore\` as your PRIMARY tool — it returns full source code sections from all relevant files in one call.
24+
>
25+
> **Rules:**
26+
> 1. Make at most 3 \`codegraph_explore\` calls — one broad query, then up to 2 focused follow-ups.
27+
> 2. Do NOT re-read files that codegraph_explore already returned source code for. The source sections are complete and authoritative.
28+
> 3. Only fall back to grep/glob/read for files listed under "Additional relevant files" if you need more detail, or if codegraph returned no results.
3029
31-
**For deep exploration questions** (e.g., "how does the undo/redo system work?"), use \`codegraph_explore\` directly. It returns full source code sections from all relevant files in a single call — no need to spawn an Explore agent.
30+
**The main session may only use these lightweight tools directly** (for targeted lookups before making edits, not for exploration):
3231
33-
**Do NOT tell Explore agents to use codegraph tools.** Testing shows Explore agents use codegraph for discovery then still read all the same files — making them slower, not faster. Codegraph's value is in the main session where it replaces the need for exhaustive file reading.
32+
| Tool | Use For |
33+
|------|---------|
34+
| \`codegraph_search\` | Find symbols by name |
35+
| \`codegraph_callers\` / \`codegraph_callees\` | Trace call flow |
36+
| \`codegraph_impact\` | Check what's affected before editing |
37+
| \`codegraph_node\` | Get a single symbol's details |
3438
3539
### If \`.codegraph/\` does NOT exist
3640

src/mcp/tools.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,11 @@ export class ToolHandler {
849849
}
850850
}
851851

852+
// Add completeness signal so agents know they don't need to re-read these files
853+
lines.push('');
854+
lines.push('---');
855+
lines.push(`> **Complete source code is included above for ${filesIncluded} files.** You do NOT need to re-read these files — the relevant sections are already shown in full. Only use Read/Grep for files listed under "Additional relevant files" if you need more detail.`);
856+
852857
return this.textResult(lines.join('\n'));
853858
}
854859

0 commit comments

Comments
 (0)