content-hash-cache-pattern

content-hash-cache-pattern is a skill for Claude Code from shennawardana23/skillme. It costs 89 tokens per session (1,819 once invoked), scanned A, original, Apache-2.0.

A pattern for caching results from expensive file processing by using a SHA-256 fingerprint of each file's contents. File processing can include reading PDFs, extracting text, or analyzing images.

In plain words
What is it for?
Use it when building or updating a file-processing tool that needs cache and no-cache options or must reuse results across runs.
Why use it?
It avoids repeating work for unchanged files and still detects changes when a file is renamed or edited.

Skill for Claude Code

Written for Claude Code: shipped in a Claude Code plugin.

Part of the skillme plugin — 137 skills, 2 commands shipped together

Good fit Use it when building or updating a file-processing tool that needs cache and no-cache options or must reuse results across runs.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/shennawardana23/skillme/content-hash-cache-pattern
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add shennawardana23/skillme --skill content-hash-cache-pattern
Clone the repo
git clone --depth 1 https://github.com/shennawardana23/skillme

Made for: Claude Code.

Or install skillme, the plugin that ships this one along with the rest of its 137 skills, 2 commands.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for content-hash-cache-pattern

README.md
[![agentmods](https://agentmods.dev/badge/skills/shennawardana23/skillme/content-hash-cache-pattern/github.svg)](https://agentmods.dev/skills/shennawardana23/skillme/content-hash-cache-pattern)
Your own site
<a href="https://agentmods.dev/skills/shennawardana23/skillme/content-hash-cache-pattern"><img src="https://agentmods.dev/badge/skills/shennawardana23/skillme/content-hash-cache-pattern/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for content-hash-cache-pattern

Your own site · 80×15
<a href="https://agentmods.dev/skills/shennawardana23/skillme/content-hash-cache-pattern"><img src="https://agentmods.dev/badge/skills/shennawardana23/skillme/content-hash-cache-pattern.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 89 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,819 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00089 $0.01819
Opus 5 $0.00044 $0.00910
Sonnet 5 $0.00018 $0.00364
Haiku 4.5 $0.00009 $0.00182

Measured 8d ago against content hash 668b1e4dd656, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-08, from the pricing page.

Security

Grade A, and why

content-hash-cache-pattern scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 8d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills/content-hash-cache-pattern/SKILL.md · 202 lines

How it starts

The opening of the file, as written. The whole thing — 202 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Content-Hash File Cache Pattern

Cache expensive file-processing results using a SHA-256 hash of the file's content as the cache key. Unlike path-based caching, this survives file moves and renames, and auto-invalidates the moment content changes — no separate invalidation logic needed.

When to Activate

  • Building a file-processing pipeline (PDF parsing, OCR, text extraction, image analysis) where the same files reappear across runs
  • Processing cost is high enough that reprocessing unchanged files is wasteful
  • Adding a --cache/--no-cache flag to a CLI tool
  • Retrofitting caching onto an existing pure function without modifying that function

Core Pattern (Go)

1. Content hash as the cache key

Hash the file in chunks — never load the whole file into memory:

package cache

import (
	"crypto/sha256"
	"encoding/hex"
	"fmt"
	"io"
	"os"
)

func ComputeFileHash(path string) (string, error) {
	f, err := os.Open(path)
	if err != nil {
		return "", fmt.Errorf("open %s: %w", path, err)
	}
	defer f.Close()

	h := sha256.New()
	if _, err := io.Copy(h, f); err != nil {
		return "", fmt.Errorf("hash %s: %w", path, err)
	}
	return hex.EncodeToString(h.Sum(nil)), nil
}

io.Copy streams the file into the hasher in fixed-size buffers, so this scales to large files without loading them fully into memory.

2. Cache entry type

type CacheEntry struct {
	FileHash   string   `json:"file_hash"`
	SourcePath string   `json:"source_path"`
	Document   Document `json:"document"` // the cached result
}

3. File-based storage: {hash}.json

O(1) lookup by hash, no separate index file:

package cache

import (
	"encoding/json"
	"fmt"
	"os"
	"path/filepath"
)

func WriteEntry(cacheDir string, entry CacheEntry) error {
	if err := os.MkdirAll(cacheDir, 0o755); err != nil {
		return fmt.Errorf("create cache dir: %w", err)
	}
	data, err := json.Marshal(entry)
	if err != nil {
		return fmt.Errorf("marshal cache entry: %w", err)
	}
	path := filepath.Join(cacheDir, entry.FileHash+".json")
	return os.WriteFile(path, data, 0o644)
}

// ReadEntry returns (entry, true) on a cache hit, (zero, false) on a
// miss — including a miss on corrupted or unreadable cache files, so
// corruption degrades to a re-process rather than a crash.
func ReadEntry(cacheDir, fileHash string) (CacheEntry, bool) {
	path := filepath.Join(cacheDir, fileHash+".json")
	data, err := os.ReadFile(path)
	if err != nil {
		return CacheEntry{}, false
	}
	var entry CacheEntry
	if err := json.Unmarshal(data, &entry); err != nil {
		return CacheEntry{}, false
	}
	return entry, true
}

Read the full file on GitHub · 202 lines

Files

What ships with it

1 file beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 8d ago First seen · 202 lines · 89 tokens per session scan A 668b1e4dd656

Subscribe to this mod's changes

content-hash-cache-pattern is a skill published in the GitHub repository shennawardana23/skillme (2 stars, last pushed 11d ago), licensed Apache-2.0. It adds 89 tokens to every session and 1,819 once invoked, about $0.0004 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.

Related

Other skills, from other repositories

ai-model-wechat

A guide to calling AI text models from a WeChat Mini Program, a small app that runs inside WeChat, using CloudBase. It covers generated text and streamed responses, where text arrives piece by piece, through callback functions.

sutchan/Agent-Skills-Hub · 254 tokens

ai-model-nodejs

Use this skill for Node.js backend AI via @cloudbase/node-sdk (>=3.16.0) — cloud functions, CloudRun, Express, Koa, NestJS, serverless APIs, scheduled jobs, LLM proxies. Only SDK supporting image generation (ai.createImageModel + generateImage). Text models via ai.createModel with groups cloudbase, hunyuan-exp, or…

sutchan/Agent-Skills-Hub · 230 tokens

gemini-interactions-api

Guides the usage of Gemini Interactions API on Gemini Enterprise Agent Platform. Use when the user wants to use the stateful, server-managed Interactions API for multi-turn conversations, background execution, streaming, structured output, and function calling on the Agent Platform.

google/skills · 58 tokens

notebooklm

Install, authenticate, troubleshoot, and operate Gemini Notebook through the notebooklm-py CLI or typed async Python API. Use for notebook and source management, grounded chat and research, and artifact generation or download when the user mentions Gemini Notebook, notebooklm-py, the notebooklm CLI, or its Python API.…

teng-lin/notebooklm-py · 79 tokens

gemini-live-api

Generates a Gemini LiveAPI client service class in the user's chosen programming language. Use when the user wants to build, scaffold, or integrate a client that connects to the Gemini Enterprise LiveAPI websocket endpoint, handles session setup/resumption, bearer token refresh, and sending/receiving…

google/skills · 119 tokens

gemini-api-dev

Use this skill when writing code that calls the Gemini API for text generation, multi-turn chat, multimodal understanding, image generation, video generation, streaming responses, background research tasks, function calling, structured output, or migrating from the old generateContent API. Covers SDK usage and best…

google-gemini/gemini-skills · 73 tokens