agentleFS
salmandevsalmandev/everything-gemini/skills/context-caching/SKILL.md

context-caching

Skill2 starsChanged 28 days agoApache-2.0View on GitHub

Use this skill when managing large-context Gemini operations (1M-2M tokens), architecting prefix-cached repository indexes, optimizing prompt structures for cost and latency, or structuring session memory for long-running agent workflows.

1 other project uses a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

3 rules. About 0 are common, 2 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Never mutate the prefix: Avoid injecting dynamic timestamps, random IDs, or changing session metadata at the beginning of the context.

    line 31
  2. Distinctive:

    Cluster Static Assets: Place unchanging documentation, API contracts, and core schemas at the very top of context assemblies.

    line 32
  3. Very specific:

    Session Compaction: When conversation histories grow long, trigger the Stop or PostInvocation summarizer to compress intermediate thoughts …

    line 39

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Gemini Context Caching & Large-Context Optimization

Overview

Gemini's 1M-to-2M token context window combined with explicit and implicit Context Caching allows agents to ingest entire codebases, documentation sets, and transaction logs. This skill outlines architectural strategies to maximize caching efficiency, cut API token costs by up to 75%, and minimize time-to-first-token (TTFT).

Context Architecture: Prefix Optimization

Gemini caching relies on deterministic prefix matching. To ensure cache hits across agent invocations:

┌─────────────────────────────────────────────────────────────┐
│ 1. STATIC PREFIX (Cached - High Hit Rate)                    │
│    - System Instructions & Repository Rules (GEMINI.md)     │
│    - Architecture Specs & Database Schemas                  │
│    - Base Codebase Index / AST Dump                         │
├─────────────────────────────────────────────────────────────┤
│ 2. DYNAMIC SUFFIX (Uncached - Fast Processing)              │
│    - Current User Prompt / Incremental Task Diff            │
│    - Recent Terminal Command Output                         │
│    - Real-Time Conversation Turn                            │
└─────────────────────────────────────────────────────────────┘

Golden Rules for Caching

  1. Never mutate the prefix: Avoid injecting dynamic timestamps, random IDs, or changing session metadata at the beginning of the context.
  2. Cluster Static Assets: Place unchanging documentation, API contracts, and core schemas at the very top of context assemblies.
  3. Chunking Thresholds: Context caching provides optimal return on investment when static context exceeds 32k tokens.

Progressive Ingestion Strategies

  1. Skeleton First: Ingest file tree maps and interface definitions before pulling full function implementations.
  2. Selective Hydration: Ingest full source files only for components identified during initial skeleton mapping.
  3. Session Compaction: When conversation histories grow long, trigger the Stop or PostInvocation summarizer to compress intermediate thoughts into high-density Knowledge Items (KI).

Cost & Latency Economics

  • Cached Input Cost: ~75% cheaper than non-cached input tokens.
  • Cache Hit Latency: Reduces initial TTFT from seconds to milliseconds on large contexts.

Verification Checklist

  • Static instructions positioned consistently at the head of context
  • No variable timestamps or nonces in the static prefix block
  • Cache hit rates monitored during multi-turn batch workflows

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.