core/capabilities/context/tool-use/SKILL.md
Guides tool selection across three layers: local scripts (zero context cost), MCP proxy (minimal context), and subagent dispatch (isolated context). Ensures the agent uses the cheapest effective layer and never pollutes the main context window with raw tool output. Use when the agent needs external information, current documentation, database access, or multi-step research.
npx skillsauth add xoai/sage tool-useInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Pick the right tool at the right cost. Every token matters.
When the agent needs information that isn't in its context window: current documentation, database queries, external APIs, file system operations, or multi-step research. Also when the agent needs to verify information (check if an import exists, test an API endpoint) rather than relying on memory.
Core Principle: The main context window is shared between your instructions (CLAUDE.md), the conversation, the task, and any tool output. A 2000-token MCP response is 2000 tokens of pack guidance or conversation history that gets pushed out. Use the cheapest layer that answers the question. Escalate only when needed.
Bash scripts that run and return a result. The output is small and deterministic. Use for anything that can be answered by running a command.
# Run tests
bash .sage/gates/scripts/sage-verify.sh .
# Check for hallucinated imports
bash .sage/gates/scripts/sage-hallucination-check.sh src/ .
# Capture screenshots
bash .sage/tools/sage-screenshot.sh http://localhost:3000 --output .sage/screenshots --full-page
# Check build
npm run build
# Check types
npx tsc --noEmit
When: Tests, builds, type checks, linting, screenshots, file operations. Cost: Only the exit code or small output enters context.
Calls an external MCP tool through the proxy script. The proxy connects to the MCP server, executes the tool, and returns the extracted content — not the raw protocol response.
# Get current framework documentation
npx tsx sage/runtime/mcp/mcp-client.ts call-tool context7 query-docs \
--params '{"libraryId":"/nextjs/nextjs","topic":"server components caching"}'
# Resolve a library name to Context7 ID
npx tsx sage/runtime/mcp/mcp-client.ts call-tool context7 resolve-library-id \
--params '{"libraryName":"supabase"}'
When: You need a SPECIFIC fact from current documentation. "What's the
exact API for revalidatePath in Next.js 16?" "What are the parameters for
Supabase's createClient?" Single-question, single-answer lookups.
Cost: ~200-500 tokens per call. The proxy extracts the relevant text.
Decision test: Can you state the exact question in one sentence? → Layer 2. Do you need to browse, synthesize, or follow up? → Layer 3.
Spawn a subagent (on Tier 1 platforms like Claude Code) with a focused task. The subagent has its own context window, can make multiple MCP calls, search the web, and synthesize results. It returns a compressed summary.
When:
How to dispatch:
Subagent task: "Research how Next.js 16 changed the caching model compared to
Next.js 15. Focus on: what's different for Server Components, what migration
steps are needed, and what the nextjs pack should update."
Context to include: nextjs pack rules (caching section only)
Return: 3-5 bullet summary of key changes + specific migration steps
Cost: Only the returned summary enters the main context (~100-300 tokens). The subagent's full research stays in its isolated window.
MUST (violation = wasted context or missed information):
.sage/mcp-manifest.json before attempting MCP calls. If no
manifest exists, run bash sage/runtime/mcp/discover.sh . first.SHOULD (violation = inefficient but functional):
MAY (context-dependent):
Monitor your context usage. As conversation grows:
.sage/decisions.md
to avoid losing your place.useState do?" → You know
this. Don't waste a tool call.bash sage/runtime/mcp/discover.sh .
If no MCP config exists at all, tools are Layer 1 only — that's fine.tools
Captures agent mistakes, corrections, and discovered gotchas so they are not repeated. Use when: (1) a command or operation fails unexpectedly, (2) the user corrects the agent, (3) the agent discovers non-obvious behavior through debugging, (4) an API or tool behaves differently than expected, (5) a better approach is found for a recurring task. Also searches past learnings before starting tasks to avoid known pitfalls. Activate alongside the sage-memory skill — they share the same MCP backend but serve different purposes (sage-memory = codebase knowledge, sage-self-learning = agent mistakes and gotchas).
development
Typed knowledge graph stored in sage-memory. Use when creating or querying structured entities (Person, Project, Task, Event, Document), linking related objects, checking dependencies, planning multi-step actions as graph transformations, or when skills need to share structured state. Trigger on "remember that X is Y", "what do I know about", "link X to Y", "show dependencies", "what blocks X", entity CRUD, cross-skill data access, or any request involving structured relationships between things.
tools
Integrates sage-memory into Sage workflows. Teaches the agent when to remember (store findings during work), when to recall (search memory at session start and task start), and how to learn (structured knowledge capture via sage learn). Use when the user mentions memory, remember, recall, learn, capture knowledge, onboard to codebase, or when starting any session where sage-memory MCP tools are available.
tools
Captures agent mistakes, corrections, and discovered gotchas so they are not repeated. Use when: (1) a command or operation fails unexpectedly, (2) the user corrects the agent, (3) the agent discovers non-obvious behavior through debugging, (4) an API or tool behaves differently than expected, (5) a better approach is found for a recurring task. Also searches past learnings before starting tasks to avoid known pitfalls. Activate alongside the sage-memory skill — they share the same MCP backend but serve different purposes (sage-memory = codebase knowledge, sage-self-learning = agent mistakes and gotchas).