claude-webcache
claude-webcache
Claude Code 的跨会话 WebFetch 缓存。
Claude Code 内置的 WebFetch 仅在单个会话内缓存 15 分钟的结果。claude-webcache 将其扩展到跨会话,并可无限期保留(默认 TTL 为 7 天,可配置)。
Open new session -> your past fetches are still there.
Cache hit -> instant.
Cache miss -> same as built-in WebFetch.为什么使用它
每当你在不同会话中重新获取相同的 URL(如文档、API 参考、研究页面)时,你每次都要支付完整的获取成本。15 分钟的会话内缓存会在你的下一次冲刺(sprint)之前过期。claude-webcache 会保留获取的内容,以便第二个会话可以直接命中缓存。

Related MCP server: ClaudeX
安装
选项 1 -- Claude Code 插件(推荐)
在终端中运行一行命令:
claude plugin marketplace add theYahia/claude-webcache && claude plugin install claude-webcache@theyahia然后将使用模式添加到你的 ~/.claude/CLAUDE.md 中(参见 使用模式)。
💡 为什么使用 CLI 子命令而不是 TUI 的
/plugin install? TUI 流程目前通过 Claude Code 的remoteMarketplaceClient后端路由,该后端存在一个公开的服务器端 Bug,会拒绝所有第三方插件源,并报错Failed to install: This plugin uses a source type your Claude Code version does not support.。参见 anthropics/claude-code#41653 以及约 20 个相关的开放问题。上述 CLI 子命令在本地使用NativeMarketplaceReader,不受此影响。备选方案(如果你的设置中 CLI 子命令也失败):
git clone https://github.com/theYahia/claude-webcache && claude --plugin-dir ./claude-webcache/plugin这将完全绕过市场流水线。
选项 2 -- npm 全局安装
npm i -g @theyahia/claude-webcache需要 Node.js 22.5+(使用内置的 node:sqlite,无原生依赖)。
然后在 ~/.claude/settings.json 中手动注册(将路径替换为 npm root -g 的结果):
{
"mcpServers": {
"claude-webcache": {
"command": "node",
"args": ["/path/from/npm-root-g/claude-webcache/scripts/mcp-server.cjs"]
}
},
"hooks": {
"SessionStart": [
{
"matcher": "startup|clear|compact",
"hooks": [
{ "type": "command", "command": "node /path/from/npm-root-g/claude-webcache/scripts/hook-stats.cjs" }
]
}
]
}
}选项 3 -- 克隆(贡献者)
参见 CONTRIBUTING.md。
使用模式
添加到你的 ~/.claude/CLAUDE.md 中,以便 Claude 通过缓存路由网页获取请求:
## WebFetch caching (claude-webcache)
Before calling WebFetch, call `cached_fetch(url, prompt)` first.
- If it returns text -> use that, do NOT call WebFetch.
- If it returns `[CACHE_MISS] <url>` -> call WebFetch as normal, then call `cache_store(url, prompt, output)` with the result.就是这样。在未来的任何会话中,相同的 URL + 相同的提示词 = 即时命中缓存。
工具 (MCP)
工具 | 参数 | 返回值 |
|
| 缓存的文本,或 |
|
|
|
| -- |
|
|
| 最近的 URL(最近的在前) |
存储
SQLite 位于 ~/.webcache/cache.db(WAL 模式,并发安全)。缓存键 = SHA256(url + "|" + prompt)。
字段 | 类型 |
| TEXT PRIMARY KEY |
| TEXT |
| TEXT |
| TEXT |
| INTEGER (ms epoch) |
| INTEGER |
| INTEGER |
SessionStart 钩子
在每个新会话中,该钩子会注入一行统计信息:
webcache: 142 pages cached, 38 hits, last fetch 3h ago如果缓存为空,则跳过注入。
TTL
默认 7 天。过期条目会在下次读取相同键时被删除。通过引入 src/cache.js 并调用 purgeExpired() 来手动执行清理。
限制
缓存键包含提示词 -> 同一 URL 上的不同提示词是独立的条目。选择一致的提示词(例如始终使用
"extract title and main content")以最大化命中率。输出是 WebFetch 返回的任何内容(已由模型总结)。缓存不会对其进行重新处理。
没有语义搜索,没有嵌入。仅限精确的
(url, prompt)匹配。
许可证
MIT -- 参见 LICENSE。
Available Tools
4 toolscached_fetchA
Look up a URL+prompt pair in the local WebFetch cache. Returns cached output if present (instant), or "[CACHE_MISS] " if not. On CACHE_MISS, call WebFetch, then call cache_store with the result. Same URL+prompt across sessions hits the cache.
| Name | Required | Description | Default |
|---|---|---|---|
| url | Yes | The URL to fetch | |
| prompt | Yes | The prompt/instruction for the WebFetch |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
Fully describes behavior: cache lookup, instant return on hit, cache miss string, and cross-session caching. Since no annotations are provided, the description carries the full burden and meets it.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
Three sentences, front-loaded with purpose, each sentence adds value without redundancy. Fits the required structure.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
Complete for a simple lookup tool: explains input, output, and fallback workflow. No output schema needed as return values are textual and explained.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Adds meaning beyond schema by explaining that url and prompt form a cache key and that prompt is an instruction for WebFetch. Schema coverage is 100%, but description enriches semantics.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
Description clearly states it looks up a URL+prompt pair in a local cache, returning cached output or a cache miss message. This distinguishes it from sibling tools like cache_list, cache_stats, and cache_store.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
Describes when to use (check cache) and provides a workflow on cache miss (call WebFetch then cache_store). However, it doesn't explicitly state when not to use or compare directly to siblings.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
cache_listB
List recently cached URLs (most recent first).
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | Max entries to return (default 50) |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations, the description carries the full burden of behavioral disclosure. It only states the output ordering but does not explain what constitutes 'recently cached', whether the list is global or scoped, or if there are any side effects (e.g., consuming cache entries). No safety or rate-limit information is provided.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is a single, front-loaded sentence that conveys the core purpose with no extraneous words. Every token is meaningful.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
Given the tool's simplicity (1 optional param, no output schema, no nested objects), the description is minimally adequate. However, it could benefit from additional context such as whether the cache is global or per-user, or how 'recent' is defined, but the basic listing functionality is clear.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
The schema has 100% coverage for the single parameter 'limit', and the description adds no additional meaning beyond what the schema already provides. The baseline score of 3 is appropriate since the schema is sufficient.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description uses a clear verb 'List' and specifies the resource 'recently cached URLs' with ordering 'most recent first'. It distinguishes this from sibling tools like cached_fetch (which likely fetches a specific URL) and cache_store (which stores).
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The description provides no guidance on when to use this tool versus alternatives like cached_fetch or cache_stats. There is no mention of prerequisites, use cases, or exclusions. The user is left to infer from the name alone.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
cache_statsA
Return cache statistics: total entries, total hits, last cached timestamp.
| Name | Required | Description | Default |
|---|---|---|---|
No parameters | |||
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
The description indicates a read-only operation (returning statistics) with no explicit destructive behavior. However, it lacks disclosure of potential side effects, authentication requirements, or rate limits. Since no annotations are provided, the description carries the full burden, and it only partially meets that need.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is a single, concise sentence that front-loads the purpose ('Return cache statistics') and lists the specific outputs. Every word is necessary and there is no redundancy.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
Given the tool's simplicity (no parameters, no output schema), the description is sufficiently complete. It clearly lists the three statistics returned. It could optionally mention that the tool is safe to call at any time, but this is not required for basic completeness.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
The tool has zero parameters, so the description adds no parameter-specific information. According to guidelines, baseline score is 4 when there are 0 parameters, as no compensation is needed.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description explicitly states the tool returns cache statistics including total entries, total hits, and last cached timestamp. It uses a specific verb ('Return') and resource ('cache statistics'), and clearly distinguishes from sibling tools like 'cache_list' (which likely returns key listings) and 'cache_store' (which stores items).
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
No guidance is provided on when to use this tool versus its siblings ('cached_fetch', 'cache_list', 'cache_store'). The description only states what it returns, leaving the agent to infer appropriate usage without explicit context or exclusions.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
cache_storeA
Store a WebFetch result in the cache after a CACHE_MISS. Pass the original url, prompt, and the output text returned by WebFetch.
| Name | Required | Description | Default |
|---|---|---|---|
| url | Yes | ||
| output | Yes | The output text returned by WebFetch | |
| prompt | Yes |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations, the description must disclose behavioral traits. It only states the storage action but does not mention what happens if the URL already exists (overwrite?), error cases, or authorization needs. This leaves significant ambiguity.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is concise, consisting of two sentences. The first sentence front-loads the purpose and trigger, and the second lists the parameters. No unnecessary words.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
Given the lack of annotations and output schema, the description provides an adequate but minimal explanation. It identifies the tool's role in caching but omits details about idempotency, error handling, or response format, which would be helpful for a complete understanding.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Schema description coverage is low (33%), but the description adds meaning by associating each parameter with its role: 'original url, prompt, and the output text returned by WebFetch.' This helps clarify the purpose of the url and prompt parameters beyond the schema.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description clearly states the tool's action ('Store a WebFetch result in the cache'), the resource ('cache'), and the trigger condition ('after a CACHE_MISS'). It effectively distinguishes from sibling tools like cached_fetch, cache_list, and cache_stats by specifying its role in the caching workflow.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The description explicitly specifies when to use the tool (after a CACHE_MISS), providing clear context. However, it does not mention when not to use it or offer alternatives (e.g., using cached_fetch for a subsequent lookup).
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
4 tool updates
v0.1.5- First observed
cache_list - First observed
cache_stats - First observed
cache_store - First observed
cached_fetch
TDQS
Scored across 4 tools
Each tool has a distinct function: lookup, list, stats, store. No overlap in purpose.
All tools use 'cache_' prefix, but 'cached_fetch' uses past participle while others use 'cache_' as noun, a minor inconsistency.
4 tools is well-scoped for a caching utility, covering essential operations.
Covers lookup, storage, listing, and stats, but lacks a clear operation to clear or invalidate cache entries.
Maintenance
Related MCP Connectors
Shared knowledge cache for AI coding agents — reuse an answer once it exists.
Persistent memory for Claude Code, Cursor and Codex. Facts retire when they change.
Shared copies of public web pages for AI agents. Search stored pages or fetch a URL.
Reliable web fetching for AI agents with retry, circuit breaker, caching, and anti-bot bypass
Related MCP Servers
- AlicenseAqualityDmaintenanceCross-surface persistent memory for Claude. Bridges context between Claude Chat, Code, and Cowork via local SQLite with full-text search.611 npm6MIT
- AlicenseAqualityCmaintenancePersistent memory + FTS5 full-text search for Claude Code conversation history. Indexes ~/.claude/projects/ JSONL into SQLite, exposes 10 MCP tools (store/recall/search memories, browse sessions, get summaries) plus prompts. Includes a web UI for visual exploration1042 npm93MIT
- AlicenseNot gradedqualityDmaintenanceA lightweight journal/memory system for Claude Code with no ML dependencies, using SQLite for fast local storage.6MIT
- AlicenseBqualityDmaintenanceProvides persistent memory, skill tracking, failure indexing, and context sharing for Claude Code using SQLite with FTS5 full-text search.236 npm1MIT