Agent skill
context-efficient-tools
Filter and transform tool results before they reach the model — prevent context bloat from large outputs
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/other/context-efficient-tools
SKILL.md
Skill: context-efficient-tools
What I do
I prevent large tool results from bloating the context window. When tools return large datasets, I apply filtering, aggregation, and summarisation in code before the result reaches the model. Anthropic found this reduces token usage by up to 98.7% on large MCP tool chains.
When to use me
- When MCP tools might return large datasets (files, search results, database queries)
- When chaining multiple tool calls with large intermediate results
- When bash commands produce verbose output
- When token budget is constrained and tool results are the bottleneck
Core principles
- Filter before returning — Never pass raw large results to the model
- Summarise, don't dump — Return counts + samples, not full datasets
- Store externally, reference internally — Write large results to files, pass the path
- Progressive disclosure — Start with metadata, drill down only if needed
- Code does the work — Use bash/scripts to process, not the model
Patterns
Large file reading
# Bad: model sees entire file
cat large_config.json
# Good: extract only what's needed
jq '.database' large_config.json
grep -A5 "relevant_key" large_config.json
Search results
# Bad: 500 matches flood context
grep -r "pattern" .
# Good: count + sample + file list
grep -r "pattern" . | wc -l
grep -r "pattern" . | head -10
grep -rl "pattern" .
Large dataset filtering
# Bad: all 10,000 rows
cat data.csv
# Good: summary + sample
wc -l data.csv && head -5 data.csv
awk -F',' '$3 == "pending"' data.csv | head -10
Storing large outputs
# Store externally, return reference + metadata
some_tool > /tmp/output.txt
echo "Stored $(wc -l < /tmp/output.txt) lines → /tmp/output.txt"
head -5 /tmp/output.txt
Build/install output
# Bad: full verbose output
npm install
# Good: errors and warnings only
npm install 2>&1 | grep -E "error|warn|ERR" | head -20
echo "Exit: $?"
Decision matrix
| Result size | Action |
|---|---|
| < 50 lines | Pass directly |
| 50–500 lines | Filter to relevant subset |
| 500–5000 lines | Summarise + sample + store to file |
| > 5000 lines | Store to file, pass path + metadata only |
Anti-patterns to avoid
- ❌
caton files > 100 lines without filtering - ❌ Passing full grep output when count + sample suffices
- ❌ Reading entire JSON configs when only one key is needed
- ❌ Letting verbose build output fill context
- ❌ Passing intermediate tool results verbatim to the next tool call
KB Reference
~/vaults/baphled/3. Resources/Knowledge Base/AI Development System/Skills/Session-Knowledge/Context Efficient Tools.md
Related skills
token-efficiency— Prompt-level efficiency (complements this skill)scope-management— Scope determines which tools are calledparallel-execution— Run independent tool calls simultaneouslyperformance— Efficient data processing patterns
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?