context-index-claudecode

Installs a Claude Code PostToolUse hook that indexes large tool outputs with a local Ollama model.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Large tool outputs from commands like Bash, Grep, or WebFetch consume excessive context tokens in Claude Code sessions, forcing agents to re-run commands or re-quote raw blobs. This Skill installs a hook that saves oversized outputs to disk, indexes them with a local model, and replaces the agent's view with a compact summary and chunk index. ## Core Features & Use Cases - Automatic Output Indexing: A PostToolUse hook fires after every tool call, saves outputs exceeding a token threshold (default 2000) to ~/.claude/tool-results/, and generates a semantic chunk index via qwen3.5:4b on Ollama. - Context Replacement: Returns the index through hookSpecificOutput.updatedToolOutput so the agent sees only the summary and chunk table instead of the raw output. - On-Demand Chunk Retrieval: The agent fetches specific line ranges later using Read offset/limit from the saved file instead of re-running commands. - Fail-Open Design: Any error (Ollama down, missing model, timeout) passes the original tool result through unchanged. - Use Case: After running a command that lists thousands of library files, the agent receives a chunk index grouped by subsystem and reads only the relevant 40-line chunk when answering a follow-up question. ## Quick Start Install the context-index hook for Claude Code by setting up Ollama with the qwen3.5:4b model, copying the indexer scripts to ~/.claude/hooks/, and registering the PostToolUse hook in ~/.claude/settings.json.

Frequently Asked Questions about context-index-claudecode

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

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

Install a PostToolUse hook that intercepts tool responses exceeding a token threshold, saves them to disk, and replaces the agent's view with a compact summary and chunk index. The agent then reads specific chunks via Read offset/limit instead of re-running commands.

How to set up a PostToolUse hook in Claude Code settings.json?▼

Add a hooks.PostToolUse block to ~/.claude/settings.json with a matcher and a command entry pointing to the hook script, plus a timeout value. Settings reload on session start, so restart Claude Code and verify with the /hooks command.

Does the context-index hook work without Ollama running?▼

The hook fails open when Ollama is unavailable: the wrapper exits with empty output and the original tool result passes through unchanged. No indexing occurs until Ollama is started and the qwen3.5:4b model is pulled.

Which Claude Code version supports updatedToolOutput for hooks?▼

The hookSpecificOutput.updatedToolOutput mechanism shipped in Claude Code v2.1.121. Earlier versions cannot replace the raw tool_response with the index, so upgrade before installing the hook.

Why does the agent still see raw output instead of the chunk index?▼

The hook likely errored and failed open. Check ~/.claude/tool-results/<session>/ for _hook_error.json files, verify the wrapper produces stdout on a manual run, and confirm Claude Code is v2.1.121 or newer.

Can I adjust the token threshold that triggers output indexing?▼

Set the INDEXER_THRESHOLD_TOKENS environment variable in your shell profile or in the env block of settings.json. The default is 2000 tokens; lower it to 500 for aggressive indexing or raise it to 5000+ to reduce Ollama latency.