Get the FREE Ultimate OpenClaw Setup Guide →

context7-efficient

npx machina-cli add skill aiskillstore/marketplace/context7-efficient --openclaw
Files (1)
SKILL.md
5.8 KB

Context7 Efficient Documentation Fetcher

Fetch library documentation with automatic 77% token reduction via shell pipeline.

Quick Start

Always use the token-efficient shell pipeline:

# Automatic library resolution + filtering
bash scripts/fetch-docs.sh --library <library-name> --topic <topic>

# Examples:
bash scripts/fetch-docs.sh --library react --topic useState
bash scripts/fetch-docs.sh --library nextjs --topic routing
bash scripts/fetch-docs.sh --library prisma --topic queries

Result: Returns ~205 tokens instead of ~934 tokens (77% savings).

Standard Workflow

For any documentation request, follow this workflow:

1. Identify Library and Topic

Extract from user query:

  • Library: React, Next.js, Prisma, Express, etc.
  • Topic: Specific feature (hooks, routing, queries, etc.)

2. Fetch with Shell Pipeline

bash scripts/fetch-docs.sh --library <library> --topic <topic> --verbose

The --verbose flag shows token savings statistics.

3. Use Filtered Output

The script automatically:

  • Fetches full documentation (934 tokens, stays in subprocess)
  • Filters to code examples + API signatures + key notes
  • Returns only essential content (205 tokens to Claude)

Parameters

Basic Usage

bash scripts/fetch-docs.sh [OPTIONS]

Required (pick one):

  • --library <name> - Library name (e.g., "react", "nextjs")
  • --library-id <id> - Direct Context7 ID (faster, skips resolution)

Optional:

  • --topic <topic> - Specific feature to focus on
  • --mode <code|info> - code for examples (default), info for concepts
  • --page <1-10> - Pagination for more results
  • --verbose - Show token savings statistics

Mode Selection

Code Mode (default): Returns code examples + API signatures

--mode code

Info Mode: Returns conceptual explanations + fewer examples

--mode info

Common Library IDs

Use --library-id for faster lookup (skips resolution):

React:      /reactjs/react.dev
Next.js:    /vercel/next.js
Express:    /expressjs/express
Prisma:     /prisma/docs
MongoDB:    /mongodb/docs
Fastify:    /fastify/fastify
NestJS:     /nestjs/docs
Vue.js:     /vuejs/docs
Svelte:     /sveltejs/site

Workflow Patterns

Pattern 1: Quick Code Examples

User asks: "Show me React useState examples"

bash scripts/fetch-docs.sh --library react --topic useState --verbose

Returns: 5 code examples + API signatures + notes (~205 tokens)

Pattern 2: Learning New Library

User asks: "How do I get started with Prisma?"

# Step 1: Get overview
bash scripts/fetch-docs.sh --library prisma --topic "getting started" --mode info

# Step 2: Get code examples
bash scripts/fetch-docs.sh --library prisma --topic queries --mode code

Pattern 3: Specific Feature Lookup

User asks: "How does Next.js routing work?"

bash scripts/fetch-docs.sh --library-id /vercel/next.js --topic routing

Using --library-id is faster when you know the exact ID.

Pattern 4: Deep Exploration

User needs comprehensive information:

# Page 1: Basic examples
bash scripts/fetch-docs.sh --library react --topic hooks --page 1

# Page 2: Advanced patterns
bash scripts/fetch-docs.sh --library react --topic hooks --page 2

Token Efficiency

How it works:

  1. fetch-docs.sh calls fetch-raw.sh (which uses mcp-client.py)
  2. Full response (934 tokens) stays in subprocess memory
  3. Shell filters (awk/grep/sed) extract essentials (0 LLM tokens used)
  4. Returns filtered output (205 tokens) to Claude

Savings:

  • Direct MCP: 934 tokens per query
  • This approach: 205 tokens per query
  • 77% reduction

Do NOT use mcp-client.py directly - it bypasses filtering and wastes tokens.

Advanced: Library Resolution

If library name fails, try variations:

# Try different formats
--library "next.js"    # with dot
--library "nextjs"     # without dot
--library "next"       # short form

# Or search manually
bash scripts/fetch-docs.sh --library "your-library" --verbose
# Check output for suggested library IDs

Troubleshooting

IssueSolution
Library not foundTry name variations or use broader search term
No resultsUse --mode info or broader topic
Need more examplesIncrease page: --page 2
Want full contextUse --mode info for explanations

References

For detailed Context7 MCP tool documentation, see:

Implementation Notes

Components (for reference only, use fetch-docs.sh):

  • mcp-client.py - Universal MCP client (foundation)
  • fetch-raw.sh - MCP wrapper
  • extract-code-blocks.sh - Code example filter (awk)
  • extract-signatures.sh - API signature filter (awk)
  • extract-notes.sh - Important notes filter (grep)
  • fetch-docs.sh - Main orchestrator (ALWAYS USE THIS)

Architecture: Shell pipeline processes documentation in subprocess, keeping full response out of Claude's context. Only filtered essentials enter the LLM context, achieving 77% token savings with 100% functionality preserved.

Based on Anthropic's "Code Execution with MCP" blog post.

Source

git clone https://github.com/aiskillstore/marketplace/blob/main/skills/92bilal26/context7-efficient/SKILL.mdView on GitHub

Overview

Context7-efficient is a token-conscious tool that fetches library docs, code examples, API references, and best practices for JavaScript, Python, Go, Rust, and more. It uses an intelligent shell pipeline to surface only code samples, API signatures, and key notes, helping users learn libraries quickly, find usage patterns, or troubleshoot framework-specific details.

How This Skill Works

From the user query, identify the target library and topic, then run the token-efficient workflow (bash scripts/fetch-docs.sh --library <name> --topic <topic>). The output is filtered to code examples, API signatures, and essential notes, reducing noise while preserving practical guidance.

When to Use It

  • You need library documentation or API references fast.
  • You require concrete code examples to understand usage patterns.
  • You want syntax references or API usage patterns for a library.
  • You are learning a new framework or library and need guided references.
  • You are troubleshooting library-specific behavior and need concise docs.

Quick Start

  1. Step 1: Identify library and topic from the user query.
  2. Step 2: Run the token-efficient fetch: bash scripts/fetch-docs.sh --library <library> --topic <topic> (add --verbose to see savings).
  3. Step 3: Read the filtered output (code examples + API signatures + key notes) and apply it directly.

Best Practices

  • Always specify --library and --topic to fetch targeted results.
  • Use --library-id for faster lookups when you know the exact ID.
  • Choose --mode code for practical code samples; --mode info for conceptual explanations.
  • Add --verbose to review token savings and content scope.
  • Narrow topics (e.g., hooks, routing, queries) to avoid overly broad results.

Example Use Cases

  • Show me React hooks
  • How do I get started with Prisma
  • What’s the Next.js routing syntax
  • How do I use Express middleware
  • Where can I find Vue.js component lifecycle references

Frequently Asked Questions

Add this skill to your agents
Sponsor this space

Reach thousands of developers