context-index

Install hooks that index large tool outputs with a local Ollama model to reduce token usage.

Updated May 13, 2026
One-click install
npx skills add https://github.com/onesmash/slm-as-harness --skill context-index-onesmash
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: context-index
Source: https://github.com/onesmash/slm-as-harness/tree/main/skills/context-index
Command: npx skills add https://github.com/onesmash/slm-as-harness --skill context-index-onesmash

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) components.

What problem does it solve? Large Bash and MCP tool outputs flood the agent's context window with raw text, wasting tokens and degrading performance. This Skill installs a progressive-disclosure system that intercepts oversized outputs, saves them to disk, indexes them with a local small model, and returns only a compact summary plus chunk index to the agent. ## Core Features & Use Cases - Progressive Disclosure: Replaces raw tool outputs over ~2000 tokens with a summary and semantic chunk table, cutting token usage by roughly 70-80%. - Multi-Platform Support: Ships sub-skills for Codex CLI (PostToolUse hook), Claude Code and Cursor (updatedToolOutput hook), and pi (tool_result extension), all sharing one Python indexing engine. - Local Semantic Indexing: Uses qwen3.5:4b via Ollama to split saved outputs into line-addressable chunks, with fail-open behavior so errors never block the agent. - Use Case: An agent runs find /usr/lib -name '*.dylib' producing thousands of lines. Instead of ingesting the raw dump, it receives a chunk index and retrieves only the relevant line ranges via offset/limit reads. ## Quick Start Ask the agent to install the context-index system for your platform, for example: "Set up context indexing for Claude Code so large tool outputs get summarized instead of dumped into context."

Frequently Asked Questions about context-index

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I reduce token usage from large tool outputs in Claude Code?▼

Install the context-index PostToolUse hook, which saves outputs over 2000 tokens to ~/.claude/tool-results and replaces them with a summary plus chunk index via hookSpecificOutput.updatedToolOutput. The agent then fetches specific chunks with Read offset/limit instead of re-running commands.

How to set up progressive disclosure for Codex CLI tool results?▼

Copy lib_indexer.py and indexer_codex.py to ~/.codex/hooks, register a PostToolUse hook in ~/.codex/hooks.json, and enable codex_hooks = true under [features] in config.toml. The hook returns {continue: false, stopReason: <index>} to replace raw output.

Does the context-index hook work with Cursor?▼

Yes, Cursor's hook system accepts the Claude Code hook schema, so the same indexer_claudecode.py wrapper works. Adjust the settings file path to ~/.cursor/hooks.json and the results directory to ~/.cursor/tool-results.

What happens if Ollama is down when the hook fires?▼

The system fails open: any error such as Ollama being unreachable, a missing model, or a timeout causes the hook to exit silently, and the original tool output passes through to the agent unchanged. Error details are written to a _hook_error.json metadata file.

Which local model does the output indexer use?▼

The indexer uses qwen3.5:4b served through Ollama at http://localhost:11434 by default. You can override it with the INDEXER_MODEL environment variable and adjust the endpoint with OLLAMA_URL.

What are the limitations of the Codex PostToolUse hook?▼

The Codex PostToolUse hook does not fire for the built-in WebSearch tool, so only Bash and mcp__* tool outputs are interceptable. Additionally, sed -n chunk-retrieval commands are deliberately skipped to avoid recursive self-indexing.