Single logo
  • Courses
  • Blog
  • About
Join on SkoolJoin on Skool

In this topic

Claude
  • CLAUDE.md, settings.json and Plugins: Which Claude Code File Advises, Which Enforces, Which Packages
  • Authoring a Claude Skill: SKILL.md, Frontmatter, Progressive Disclosure and the Description That Triggers It
  • One Change, Four Environments: Where a Claude Config Edit Lands in Dev, Staging, Prod and CI
  • Claude in the SDLC: Prompts in Git, a Change Gate by Path, a Claude Review That Advises and a Person Who Merges
  • Hooks That Block Destructive Actions: a PreToolUse Gate That Allows, Asks or Denies
  • Choosing a Claude Code Extension: Skill, Hook, Rules File, Subagent, Slash Command or Plugin
  • Rolling Out Claude Code to a Team: Settings Precedence, dontAsk in CI, a Hook for Every-Time Rules and a Plugin for Five Repos
  • A Claude Code Review Bot in CI: Headless -p, JSON Findings, Team Rules in Git and a Person on the Merge
  • Lab: Three Planted Bugs in a Claude Code CI Repo, a Permission Mode, a Plugin Path and an MCP Token Variable
  • Configuring MCP Servers in Claude Code: A Command or a URL, Three Scopes, and Three Moves When One Breaks
  • The Claude Messages API: Your First Call, Field by Field
  • Claude Tool Use: How tool_use and tool_result Work in the Messages API
  • Claude Client SDKs Wrap One REST API: Raw HTTP, Python, TypeScript and Async Calls Compared
  • Anthropic SDK Timeouts, Retries and Error Classes: Configure the Client Once, Then Give 429, 529, 400 and Timeouts Their Own Move
  • Claude Streaming Events: The Event Order, message_stop, Tool Arguments, Stop Reasons and a WebSocket Relay
  • Images, PDFs and Thinking Blocks in the Claude Messages API: Typed Blocks In, Typed Blocks Out
  • Getting Data Into Claude: PDF Documents, the Files API, Search Results and Citations
  • Opus, Sonnet or Haiku: Pick the Claude Model per Job, and Test the Request When a New Release Arrives
  • Adaptive Thinking and Effort in Claude: Two Dials, Set per Workload, and the Thinking Block You Must Pass Back
  • Claude Cost Tracking From usage: Count Before, Cap During, Read After, Then Find the Line That Drives the Bill
  • Claude Cache Breakpoints: Where to Put cache_control, How to Move It With the Chat, and Why the Reads Stay at Zero
  • Claude Message Batches or Real Time: Choose by Who Is Waiting, Match by custom_id, Resend Only the Failures
  • Calling Claude Through Amazon Bedrock, Google Cloud and Microsoft Foundry: Same Call, Different Door
  • The Life Cycle of a Claude App: Six Phases, a Model That Retires, and a Release Gate for Every Change
  • Pinning Claude Model IDs and Upgrading Safely: One Change at a Time, a Golden-Set Replay and a Staged Rollout
  • Content Boundaries and Schema Design for Claude: Fence the Input in a Tag, Let the Output Say I Don't Know
  • The Agentic Loop and stop_reason: Keep Turning on tool_use, Stop on end_turn, Cap the Turns
  • The Claude Agent SDK: query(), ClaudeAgentOptions and @tool, in Python and TypeScript
  • Fix the Agent: Four Broken Claude Agent SDK Configs, From the Symptom to the One Wrong Line
  • Claude Managed Agents: Cloud Sandbox, Self-Hosted Sandbox or Self-Hosted Service
  • Agent SDK Hooks for Deterministic Actions: PreToolUse, PostToolUse, and Four Hooks That Fail Silently
  • Memory and Context-Window Patterns for Claude Agents: Context Editing, Compaction and the Memory Tool
  • Reading an Agent Trace: Five Signatures, Five Missing Patterns, and How Long a Fact Must Live
  • Tool Descriptions for Claude: How Claude Picks a Tool, and How to Stop It Picking the Wrong One
  • Tool Input Schemas and Error Responses for Claude: Required Fields, Enums, is_error and a Retry Flag
  • Tool Response Shaping and a Lean Tool Set: Give Claude a Sticky Note, Not the Filing Cabinet
  • Fix the Tool Schema: Read the Trace, Fix the Card, Re-Run (Four Real Schema Bugs)
  • Client Tools, Server Tools and Approval Gates: Who Runs the Tool, and Who Says Yes First
  • Built-in Tool, Custom Tool, Skill or MCP Server? Pick the Lightest One That Fits
  • System Prompt or User Turn: Where Each Instruction Goes, and Output Limits Your Code Enforces
  • Refine the Prompt One Line at a Time, Then Clean and Fence the Customer's Text
  • Prompt Revision Driven by Evals: Name the Cause, Change One Thing, Rerun the Whole Suite
  • Long-Running Sessions: Compact, Prune, Isolate or Start Fresh, Decided by Naming the Failure
  • Context Isolation Through Subagents: Read the Logs Elsewhere, Keep One Line
  • Defensive Parsing of Claude Replies: Check the Stop Reason, Read the Block or the Text, Then Validate the Values
  • Full Context or Retrieval: Choose by Corpus Size, Cost and Freshness
  • Skepticism Toward Confident Output: Check the Quote, the Record and the Sum Before You Send
  • Debugging a Claude App: Three Error Types, the Recovery Each One Earns, and the First Failing Row
  • Six Ways a 200 Can Still Be Wrong: Hallucination, Refusal, Under-Acting, Context Loss, Format Drift and Inconsistency
  • Fix the Cause, Not the Symptom: Four Recovery Drills for an LLM App, Each Checked on a New Input
  • Integration Layer or Model Output? Three Taps and Three Questions to Find Where a Wrong Answer Lives
  • Which Test Layer Owns the Failure? Unit, Functional, Integration and End-to-End Tests for a Claude App
  • Designing an Overnight Document Pipeline on Claude: Batch Lane, Live Lane, a Cached Prefix and a custom_id Reconcile
  • Proving a Model Upgrade Is Ready: A Frozen Golden Set, a Calibrated Judge, the Right Layer and a Release Gate
  • From Requirement to Design for a Claude App: Eight Requirements, Five Elements and a Trace With No Gaps
  • Build a Claude Refund App: the Messages API, Two Tools, an MCP Server and a Hook in One Loop
  • Ship a Claude App: an Eval Gate, Two Guardrail Layers, a Cost Check From usage and a Pinned Model
  • Lab: a 30-Case Golden Set, a Calibrated Judge and a Per-Slice CI Gate on a Claude Refund App
  • Lab: Cut a Claude App's Bill by 62 Percent With Usage Data, Layered Cache Breakpoints and a Batch Job
  • Lab: Three Planted Bugs in a Claude App, a Vague Prompt, a Mistyped Tool Schema and a Broken Stream Handler
  • Lab: Three Planted Bugs in a Claude Code CI Repo, a Permission Mode, a Plugin Path and an MCP Token Variable
  • Lab: Harden a Claude App, an Uncalibrated Judge, a Retry Loop That Retries Everything and a Hook Matcher With a Gap
  • Lab: Turn a Claude App Into a Reusable Template, One Pinned Model Id, No Key in Code and Evals Built From Data
  • Building an MCP Server: Tools, Resources and Prompts in Python and TypeScript
  • MCP Transports: stdio or Streamable HTTP, and Who Starts the Server
  • Deploying and Authenticating an MCP Server: Environment Keys for stdio, Bearer Tokens and Scopes for HTTP
  1. Blog
  2. /
  3. Claude
  4. /
  5. Building with the Claude API

Full Context or Retrieval: Choose by Corpus Size, Cost and Freshness

Three document sets, three answers. A small stable handbook is best sent in full with a cache, a 2.4 million token archive must be retrieved, and hourly price notes keep resetting the cache, so retrieval wins.

Chaand Sheikh

·27 November 2026Building with the Claude API

What you will learn

  • Check whether a document set fits in one request before anything else
  • Cost a corpus per day three ways: full, full with a prompt cache, and retrieval
  • Explain why a corpus that changes often resets the cache and favours retrieval
  • Pick full context with a cache for small, stable, busy sets, and retrieval otherwise

Before you start

  • Why RAG exists
  • Prompt caching: keep the start of every request identical

Our support team has three sets of documents, and Claude has to answer from them. Someone asks: can we just paste every document into the request? Sometimes yes, sometimes no. Three things decide it: size, cost and freshness. We'll cost each set both ways with a tiny project of our own.

If you haven't met retrieval yet, why RAG exists explains the idea. This article is the decision, in numbers.

Three document sets

SetSizeQuestions a dayChanges a day
Staff handbook40,000 tokens3000
Support archive2,400,000 tokens1500
Price notes60,000 tokens30024

These are our own example numbers, kept in corpora.py along with the window size (1,000,000 tokens on current models, from the Claude docs page on context windows) and a retrieval budget of 4,000 tokens of passages per question.

The binder or the index

You need answers from your files in a meeting. One way is to bring the whole binder: nothing can be missed, but it's heavy, you carry it every time, and a whole library won't fit in the bag. The other way is to ask the index which pages matter and carry only those. It's light and quick, but the index can miss a page and has to be kept current. Full context is the binder. Retrieval is the index plus a few pages.

Three questions, in this order

Size first, then freshness and cost 1. Size: does it fit in one request? no retrieve yes 2. Freshness: does it change often? yes retrieve, keep the index current no 3. Cost: full cached vs retrieval, per day close: full context, cached (simpler)
Size can rule full context out on its own. Cost and freshness decide the rest.

How the bill adds up

  • Full, no cache: the whole set at full price, on every question.
  • Full, cached: the first request writes the set at 1.25 times the base price (the 5-minute cache). After that each read costs a tenth. Every change forces a new write, because the stored copy is out of date.
  • Retrieval: only the passages, 4,000 tokens a question. The index itself has its own cost and isn't priced here.

The unit is one base input token. The multipliers come from the Claude docs page on prompt caching; some models list a lower read price.

"""Daily input cost in base units: 1 unit = one base input token."""
from corpora import PASSAGES, WINDOW

# 5-minute cache write, times the base price
WRITE_5M = 1.25
# cache read, times the base price
READ = 0.1


def full_plain(c):
    return c["questions"] * c["tokens"]


# assumes questions arrive less than 5 minutes apart: the cache stays warm
def full_cached(c):
    writes = 1 + c["changes_per_day"]
    reads = c["questions"] - writes
    return writes * WRITE_5M * c["tokens"] + reads * READ * c["tokens"]


def retrieval(c):
    return c["questions"] * PASSAGES


def fits(c):
    return c["tokens"] <= WINDOW

Note the assumption on full_cached: questions arrive less than five minutes apart, so the cache stays warm. Every read refreshes the five-minute window.

Run choose.py

def choose(c):
    if not fits(c):
        return "retrieve: it does not fit in one request"
    if c["changes_per_day"] > 0:
        return "retrieve: every change resets the cache"
    return "full context, cached: stable, and about the same cost"

No model is called, so no key is needed:

Staff handbook: 40,000 tokens, 300 questions, 0 changes a day
  full, no cache     12,000,000
  full, cached        1,246,000
  retrieval           1,200,000
  -> full context, cached: stable, and about the same cost
Support archive: 2,400,000 tokens, 150 questions, 0 changes a day
  full             does not fit in one request
  retrieval             600,000
  -> retrieve: it does not fit in one request
Price notes: 60,000 tokens, 300 questions, 24 changes a day
  full, no cache     18,000,000
  full, cached        3,525,000
  retrieval           1,200,000
  -> retrieve: every change resets the cache

The choice, set by set

  • Staff handbook. Cached full context costs 1,246,000 a day against 1,200,000 for retrieval: about the same. Full context with a cache wins because it's stable and simpler, with no index to maintain, as long as questions keep the cache warm. Without the cache it would be 12,000,000, ten times more.
  • Support archive. 2,400,000 tokens is over the 1,000,000 window. Size decides; retrieval is the only way.
  • Price notes. 24 changes a day means 25 cache writes. Cached full context costs 3,525,000 against 1,200,000 for retrieval. Retrieve, and re-index on every change. A stale document gives an old answer that still sounds sure.

Limits of caching the full set

  • Cached tokens still count toward the window. The price drops; the size doesn't.
  • More context isn't automatically better. As the token count grows, recall can degrade. The Claude docs call this context rot.
  • Caching pays only when many questions arrive inside the five minutes and the set stays put.

The caching mechanics are in prompt caching. Whichever route you pick, the request should still cite its sources and be able to say not found, as in citations and abstention.

Recap

CorpusDeciding factorChoice
Small, stable, busyCost is about equalFull context, cached
Bigger than the windowSizeRetrieve
Changes oftenFreshness resets the cacheRetrieve, keep the index current

Pick the answer that weighs size, cost and freshness together, not one that always pastes everything or always retrieves.

Keep going in Claude · 46 of 66

Previous
Defensive Parsing of Claude Replies: Check the Stop Reason, Read the Block or the Text, Then Validate the Values
Next post
Skepticism Toward Confident Output: Check the Quote, the Record and the Sum Before You Send
Community · Free to join
Single logo

StudyEasy AI Community

Hosted onSkool

Learn AI engineering, share what you build, and connect with other learners.

  • Free resources: lesson files, notebooks and code

  • Ask questions and join engineering discussions

  • Meet real people learning and building with AI

Join free on Skool

Related course on Udemy

Claude Certified Developer - Foundations (CCDV-F) Exam Prep

Build and ship Claude apps: the API, agents, tools and MCP, prompts, evals, security and model choice.View on Udemy ↗: Claude Certified Developer - Foundations (CCDV-F) Exam Prep (paid course, opens in a new tab)

Related posts

The Claude Messages API: Your First Call, Field by Field

One request in, one Message out. The four fields of a Messages API call (model, max_tokens, system, messages), how to read content blocks, stop_reason and usage, and why every turn resends the history.

Claude Tool Use: How tool_use and tool_result Work in the Messages API

Follow one order question through Claude's tool round trip: define a tool, read the tool_use block, run your own function and send a matching tool_result back, including parallel calls and is_error.

Claude Client SDKs Wrap One REST API: Raw HTTP, Python, TypeScript and Async Calls Compared

Every Claude client SDK wraps the same REST request: a POST to /v1/messages with a JSON body. See it built by hand, through the Python and TypeScript SDKs, as typed errors, and as async calls that wait together.

Anthropic SDK Timeouts, Retries and Error Classes: Configure the Client Once, Then Give 429, 529, 400 and Timeouts Their Own Move

Configure the Anthropic SDK client (timeout, max_retries, with_options, async, pagination), see which errors it retries by itself, then repair a retry wrapper so a 429, a 529, a 400 and a timeout each get the move the docs support.

On this page

  • Three document sets
  • The binder or the index
  • Three questions, in this order
  • How the bill adds up
  • Run choose.py
  • The choice, set by set
  • Limits of caching the full set
  • Recap
Community · Free to join
Single logo

StudyEasy AI Community

Hosted onSkool

Learn AI engineering, share what you build, and connect with other learners.

  • Free resources: lesson files, notebooks and code

  • Ask questions and join engineering discussions

  • Meet real people learning and building with AI

Join free on Skool

Related course on Udemy

Claude Certified Developer - Foundations (CCDV-F) Exam Prep

Build and ship Claude apps: the API, agents, tools and MCP, prompts, evals, security and model choice.View on Udemy ↗: Claude Certified Developer - Foundations (CCDV-F) Exam Prep (paid course, opens in a new tab)

Single logo

Empowering Education, One Course at a Time

About
About usContact usFAQs
Legal
Terms of ServicePrivacy Policy

© 2026 StudyEasy Organization. All rights reserved.