tool-cache
Category: cache · Cloud + Local · Status: v1.0 — observation mode
Solves the “agent reads the same file 14 times in one session” problem.
v1 limitation: the module observes and records tool calls + results, and detects when a future request would hit cache (visible via metadata). It does NOT yet rewrite requests to inject cached results in place of tool_use blocks — that needs deeper IPC work because Anthropic strictly requires every tool_use to be answered by a real tool_result from the client. v1.1 will flip that switch and start saving the round trip too.
What it does (v1)
- Post hook: scans the request for
tool_use → tool_resultadjacency pairs and records each(tool_name, sha256(input))→resultin storage.kv with a TTL. - Pre hook: scans the latest assistant message for
tool_useblocks whose params hash matches a stored entry. Recordstool-cache.would_hit_countin metadata so you can measure the cache hit rate today, before v1.1 flips the switch. - Excluded tools: side-effecting tools (
bash,shell_exec,send_email,write_file, etc.) are NEVER recorded. A stale cache for those would be actively harmful.
When to use it
- MCP-using agents (Claude Code, Cline, custom).
- Any workflow where deterministic tool calls repeat within a session.
Configuration
tool-cache:
ttlSeconds: 60 # default: short TTL — file content can change
excludeTools: # never cache side-effecting tools
- bash
- shell_exec
- send_email
- write_file
perToolTtl: # override TTL per tool
read_file: 30
git_log: 300Default exclusions
The following tool names are always excluded, even if you don’t list them:
bash,shell_exec,shellsend_emailwrite_file,edit_file,create_file,delete_filecommit,push,deployexecute_sqlhttp_request
You can add to this list via excludeTools, but you cannot remove from it.
Metrics emitted
tool-cache.observed_calls— how many tool calls were in the latest assistant turn.tool-cache.would_hit_count— how many of those would be served from cache in v1.1.tool-cache.would_hit_details— array of{ tool, key }for the would-be hits.tool-cache.recorded_count— how many new pairs were recorded in this turn.
Safety
Failed tool calls (isError: true) are never cached — caching errors would prevent the agent from ever recovering. The TTL defaults are short (60s) because tool results are by nature time-sensitive (a file’s contents can change between calls).