Skip to content

Commit cdc0c5c

Browse files
gdillaclaude
andcommitted
Consolidate 4 skills into 1 with progressive disclosure
Merge codebase-memory-exploring, codebase-memory-tracing, codebase-memory-quality, and codebase-memory-reference into a single codebase-memory skill with a references/ directory. Motivation: - Each skill registered a separate description entry that Claude scans at session startup. 4 skills = 4 description entries consuming listing space when 1 would suffice with a broader trigger phrase set. - The 4 skills had overlapping content (gotchas, tips) scattered across files with no single source of truth. - Per Anthropic's Agent Skills best practices and official spec (agentskills.io), skills should use progressive disclosure: a concise SKILL.md (<500 lines, <5000 tokens) loaded on activation, with detailed reference material in separate files loaded on demand. What changed: - assets/skills/: 4 separate skill directories replaced by 1 codebase-memory/ directory with references/ subdirectory - SKILL.md (54 lines): decision matrix, quick workflows, consolidated gotchas section — everything an agent needs to pick the right tool - references/exploring.md: codebase exploration workflows - references/tracing.md: call chain tracing, impact analysis, cross-service - references/quality.md: dead code, fan-out/fan-in, change coupling - references/tool-reference.md: all 14 tools, edge types, Cypher syntax, regex patterns - cli.c: embedded skill content consolidated into single string with decision matrix, all workflows, and gotchas - cli.h: CBM_SKILL_COUNT 4 → 1 - test_cli.c: updated to test single consolidated skill covering all capabilities The consolidated gotchas section surfaces the 5 most common mistakes (search_graph vs query_graph for edges, 200-row cap, exact name requirement, direction="both" for cross-service, pagination) in the main SKILL.md where the agent reads them before encountering issues. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent f7315b9 commit cdc0c5c

10 files changed

Lines changed: 321 additions & 413 deletions

File tree

cmd/codebase-memory-mcp/assets/skills/codebase-memory-exploring/SKILL.md

Lines changed: 0 additions & 90 deletions
This file was deleted.

cmd/codebase-memory-mcp/assets/skills/codebase-memory-tracing/SKILL.md

Lines changed: 0 additions & 125 deletions
This file was deleted.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
---
2+
name: codebase-memory
3+
description: >
4+
Use the codebase knowledge graph for structural code queries. Triggers on: "explore the codebase",
5+
"understand the architecture", "what functions exist", "show me the structure", "who calls this function",
6+
"what does X call", "trace the call chain", "find callers of", "show dependencies", "impact analysis",
7+
"dead code", "unused functions", "high fan-out", "refactor candidates", "code quality audit",
8+
"graph query syntax", "Cypher query examples", "edge types", "how to use search_graph".
9+
---
10+
11+
# Codebase Memory — Knowledge Graph Tools
12+
13+
Graph tools return precise structural results in ~500 tokens vs ~80K for grep-based exploration.
14+
15+
## Step 1: Check if project is indexed
16+
17+
```
18+
list_projects
19+
```
20+
21+
If the project is missing: `index_repository(repo_path="/path/to/project")`. If already indexed, skip — auto-sync keeps the graph fresh.
22+
23+
## What do you want to do?
24+
25+
| Goal | Read |
26+
|------|------|
27+
| **Explore codebase structure** — find functions, classes, routes, understand architecture | [references/exploring.md](references/exploring.md) |
28+
| **Trace call chains** — who calls X, what does X call, impact analysis, cross-service calls | [references/tracing.md](references/tracing.md) |
29+
| **Code quality analysis** — dead code, high fan-out, hidden coupling, refactor candidates | [references/quality.md](references/quality.md) |
30+
| **Tool reference** — all 14 tools, edge types, node labels, Cypher syntax, regex patterns | [references/tool-reference.md](references/tool-reference.md) |
31+
32+
## Quick Decision Matrix
33+
34+
| Question | Tool call |
35+
|----------|-----------|
36+
| Who calls X? | `trace_call_path(direction="inbound")` |
37+
| What does X call? | `trace_call_path(direction="outbound")` |
38+
| Full call context | `trace_call_path(direction="both")` |
39+
| Find by name pattern | `search_graph(name_pattern="...")` |
40+
| Dead code | `search_graph(max_degree=0, exclude_entry_points=true)` |
41+
| Cross-service edges | `query_graph` with Cypher |
42+
| Impact of local changes | `detect_changes()` |
43+
| Risk-classified trace | `trace_call_path(risk_labels=true)` |
44+
| Text search | `search_code` or Grep |
45+
46+
## Gotchas
47+
48+
1. **`search_graph(relationship="HTTP_CALLS")` does NOT return edges** — it filters nodes by degree. Use `query_graph` with Cypher to see actual edge properties (url_path, confidence).
49+
2. **`query_graph` has a 200-row cap** before aggregation — COUNT queries silently undercount on large codebases. Use `search_graph` with `min_degree`/`max_degree` for counting.
50+
3. **`trace_call_path` needs exact names** — use `search_graph(name_pattern=".*Partial.*")` first to discover the exact function name.
51+
4. **`direction="outbound"` misses cross-service callers** — always use `direction="both"` for complete context. Cross-service HTTP_CALLS appear as inbound edges.
52+
5. **Results default to 10 per page** — check `has_more` and use `offset` to paginate.
53+
6. **Dead code detection requires entry point exclusion** — without `exclude_entry_points=true`, route handlers and `main()` show as false positives.
54+
7. **`search_graph` with degree filters has no row cap** (unlike `query_graph`). Use it for counting, not `query_graph`.
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Codebase Exploration
2+
3+
## Get a structural overview
4+
5+
```
6+
get_graph_schema
7+
```
8+
9+
Returns node label counts (functions, classes, routes), edge type counts, and relationship patterns. Use it to understand what's in the graph before querying.
10+
11+
## Find specific code elements
12+
13+
Find functions by name pattern:
14+
```
15+
search_graph(label="Function", name_pattern=".*Handler.*")
16+
```
17+
18+
Find classes:
19+
```
20+
search_graph(label="Class", name_pattern=".*Service.*")
21+
```
22+
23+
Find all REST routes:
24+
```
25+
search_graph(label="Route")
26+
```
27+
28+
Find modules/packages:
29+
```
30+
search_graph(label="Module")
31+
```
32+
33+
Scope to a specific directory:
34+
```
35+
search_graph(label="Function", qn_pattern=".*services\\.order\\..*")
36+
```
37+
38+
## Read source code
39+
40+
After finding a function via search, read its source:
41+
```
42+
get_code_snippet(qualified_name="project.path.to.FunctionName")
43+
```
44+
45+
## File/directory exploration
46+
47+
```
48+
list_directory(path="src/services")
49+
```
50+
51+
## When to Use Grep Instead
52+
53+
- Searching for **string literals** or error messages → `search_code` or Grep
54+
- Finding a file by exact name → Glob
55+
- The graph indexes structural elements, not text content
56+
57+
## Tips
58+
59+
- Use `project` parameter when multiple repos are indexed.
60+
- Route nodes have a `properties.handler` field with the handler function name.
61+
- `exclude_labels` removes noise (e.g., `exclude_labels=["Route"]` when searching by name pattern).

0 commit comments

Comments
 (0)