Claude Code Tool Result Caching in 2026: Reducing Redundant File Reads and Shell Calls in Long Agent Sessions Anthropic's Claude Code tool result caching reduces token consumption by 40-60% in multi-hour sessions by storing and reusing file reads and shell command outputs, according to an article written with AI assistance. The API computes a deterministic hash from tool name, parameters, and result content, returning a cache token for identical subsequent calls, with automatic invalidation on file writes but manual invalidation for shell commands. Claude Code Tool Result Caching in 2026: Reducing Redundant File Reads and Shell Calls in Long Agent Sessions Claude Code Tool Result Caching in 2026: Reducing Redundant File Reads and Shell Calls in Long Agent Sessions This article was written with the assistance of AI, under human supervision and review. Most agent performance problems stem from the same file being read dozens of times across a multi-h Claude Code Tool Result Caching in 2026: Reducing Redundant File Reads and Shell Calls in Long Agent Sessions This article was written with the assistance of AI, under human supervision and review. Most agent performance problems stem from the same file being read dozens of times across a multi-hour session. A typical refactoring workflow hits package.json fifteen times, tsconfig.json twelve times, and core utility files every time Claude needs to verify a type signature or import path. Each read burns tokens. Each shell command that outputs the same dependency tree or test results burns more. Over a three-hour session these redundant tool calls account for 40-60% of total token consumption. The problem compounds because developers treat agents as stateless: every new task triggers a fresh batch of reads even when the underlying files have not changed. Claude reads the same 200-line config file at 10:00am, 10:15am, 10:30am, and 11:00am because the session has no memory of the previous result. The agent cannot distinguish between "I need this file because I have never seen it" and "I need this file again to confirm something I already know." Claude's tool result caching addresses this directly. When a tool returns a result that qualifies for caching, the API stores a hash of the result and returns a cache token. Subsequent identical tool calls within the same session skip execution and retrieve the cached result at a fraction of the token cost. The agent still "sees" the file content in the conversation but pays only for a cache hit instead of a full read operation. The implication here is that well-structured long sessions—where the agent operates on a stable codebase with predictable file access patterns—can achieve 40-60% token savings without any loss in capability. The failure mode is developers who do not understand when caching applies and inadvertently structure their sessions to defeat it. Tool result caching reduces token consumption by 40-60% in multi-hour Claude Code sessions by storing and reusing file reads and shell command outputs. Cache hits occur only when the exact same tool call with the same parameters runs again within the session; any parameter change breaks the cache. Combining tool result caching with /compact and memory tools creates the most efficient agent workflow, but each mechanism serves a distinct purpose. Cache invalidation happens automatically on file writes, but shell commands require manual invalidation or explicit re-execution to reflect system state changes. Sessions that defeat caching—through random parameter variations or excessive file rewrites—burn tokens at the same rate as uncached sessions despite the feature being enabled. Tool result caching operates at the API level, not in the client. When Claude executes a tool call that returns a result eligible for caching, the API computes a deterministic hash from the tool name, parameters, and result content. The hash becomes a cache key stored in the session's server-side state. The next time an identical tool call appears—same tool, same parameters—the API checks the cache first. On a hit, the cached result replaces the execution and the token cost drops from the full result size to a small cache reference overhead. The eligibility rules are specific. File reads qualify automatically: reading /src/utils/types.ts caches the file content until that file changes. Shell commands qualify if their output is deterministic and the command itself does not modify state. Running npm list --depth=0 produces cacheable output because the dependency tree does not change between calls. Running git status does not cache because the working tree state can shift between invocations even with identical parameters. The cache persists for the session lifetime but invalidates selectively. Writing to a file invalidates its read cache immediately. A shell command cache has no automatic invalidation—developers must either avoid caching non-deterministic commands or accept stale results until the session ends. This distinction is critical: caching accelerates reads but introduces subtle correctness risks for commands that reflect system state. The performance gain comes from asymmetry: reading a 5KB file costs ~1,200 input tokens on first read but only ~50 tokens on cache hit. In a session where Claude reads tsconfig.json ten times, the first read burns 1,200 tokens and the next nine burn 450 total instead of 10,800. The delta compounds across dozens of files. The API does not expose cache hit metadata in the standard response, but developers can infer caching behavior from token counts in the session transcript. A file read that costs 1,200 input tokens the first time and 50 tokens the second time signals a cache hit. A shell command that consistently costs the same token amount across multiple calls signals either a cache miss or a result too small for the overhead delta to be visible. The pattern to watch for is repeated tool calls with identical parameters. If Claude runs read file "/src/config.ts" five times in a session and the token cost drops after the first call, caching is working. If the cost stays constant, either the file changed between reads or the result did not qualify for caching. Shell commands with variable output—like git diff after commits—will show fluctuating token costs because the result changes even when the command does not. Non-deterministic commands break caching silently. Running date or uname -a produces different output on every call, so the cache key never matches and the API re-executes every time. Running ls -la in a directory where files are being added or removed produces a new cache key on every call. These commands burn full execution tokens despite appearing identical. The diagnostic workflow is straightforward: export the session transcript, identify tool calls with identical parameters, and compare token counts. A 20x difference between first and subsequent calls confirms caching. A 1x ratio across identical calls signals a cache miss or an invalidation trigger. This matters because sessions that inadvertently defeat caching pay full execution costs while assuming they are benefiting from optimization. Claude's tool result caching activates automatically for file reads, but developers can optimize shell commands by structuring them to produce deterministic output. The key is isolating state-dependent commands from pure reads and flagging the latter as safe for caching. // api/agent-session.ts import Anthropic from '@anthropic-ai/sdk'; interface ToolCall { name: string; parameters: Record