Skip to content
ReadMe Daily

Search articles, problems, patterns and every cheat sheet topic.

Claude Cheat Sheet

9 groups · 39 topics · Updated

Claude is a family of AI models made by Anthropic. This is an independent guide, checked against Anthropic's documentation in November 2026. Model names and prices change often, so confirm them on the official pages linked at the end.

1

Models

Which model to choose, and what it costs.

Current models

Model ID Use it for
Fable 5.2 claude-fable-5-2 The hardest reasoning, long agent runs
Opus 5.5 claude-opus-5-5 Most work: the usual default
Sonnet 5.5 claude-sonnet-5-5 Everyday coding and agents, faster
Haiku 5.5 claude-haiku-5-5 High volume, simple tasks
  • Use the ID exactly as written, with no date on the end.
  • Start with Opus 5.5. Move down for speed and cost, up for difficulty.

Prices

US dollars per million tokens.

Model Input Output
Fable 5.2 $8 $40
Opus 5.5 $4 $20
Sonnet 5.5 $2 $10
Haiku 5.5 $0.10 $0.50
  • Output costs five times as much as input.
  • The Haiku price is for prompts up to 100K tokens.

Limits

Limit Size
Context window 1M tokens
Longest reply 128K tokens
  • The context window is everything the model can see at once: instructions, history, tools and its own reply.
  • Replies near the top of the range need streaming.

Tokens

  • A token is a chunk of text, often part of a word.
  • You pay for the tokens you send and the tokens you get back.
  • A long conversation costs more each turn, because the whole history is sent again.
2

Prompting

How to ask so that the first answer is usable.

A good prompt

  • Goal. What you want, and what it is for.
  • Audience. Who will read the result.
  • Context. The background a new colleague would need.
  • Material. The text, data or code to work on.
  • Format. Length, structure and tone of the answer.
  • Done. How you will judge that it is right.

Explain the reason behind a rule. "Keep it short, it is read on a phone" works better than "keep it short".

Mark up the material

Wrap pasted material in tags so it cannot be confused with your instructions.

<report>
...paste the report here...
</report>
 
Summarise the report above in five
bullet points for a new team member.
  • Put long material first and the question last.
  • Any tag name works. Be consistent.

Show an example

Write a product description in the
style of this example.
 
<example>
Small, sturdy and bright: a torch
that fits on a key ring.
</example>
 
Product: a folding umbrella.
  • One to three examples is enough.
  • Vary them, or every answer will copy one.

System prompt or message

Put it in What goes there
System prompt The role, the rules and the tone that hold for the whole conversation
User message This task and its material

Fix a weak answer

Problem Try
Too long State a length: "under 100 words"
Too generic Add the audience and the purpose
Wrong format Show the format, or ask for JSON output
Makes things up Supply the source text; allow "I don't know"
Misses a rule Say it once, plainly, with the reason
Stops too early Say what finished looks like
3

Messages API

Calling Claude from JavaScript.

Set up

npm install @anthropic-ai/sdk
export ANTHROPIC_API_KEY="your-key"
import Anthropic from "@anthropic-ai/sdk";
 
// reads ANTHROPIC_API_KEY
const client = new Anthropic();
  • Keep the key on the server. Never ship it in browser code or commit it.

First request

const msg = await client.messages.create({
  model: "claude-opus-5-5",
  max_tokens: 16000,
  messages: [
    { role: "user", content: "Hello" },
  ],
});
Field Meaning
model Which model to use
max_tokens The most the reply may contain
messages The conversation so far

All three are required.

Read the reply

for (const block of msg.content) {
  if (block.type === "text") {
    console.log(block.text);
  }
}
 
msg.stop_reason; // → "end_turn"
msg.usage;       // tokens in and out
  • content is a list of blocks, not a string. Check each block's type.

System prompt

const msg = await client.messages.create({
  model: "claude-opus-5-5",
  max_tokens: 16000,
  system: "You are a patient maths tutor.",
  messages: [
    { role: "user", content: "What is pi?" },
  ],
});

A conversation

const messages = [
  { role: "user", content: "I am Asha." },
  { role: "assistant", content: "Hi Asha!" },
  { role: "user", content: "Who am I?" },
];
  • The API remembers nothing between requests. Send the whole history every time.
  • The first message must come from user.

Stop reasons

stop_reason Meaning
end_turn Finished normally
max_tokens Cut off: raise max_tokens
stop_sequence Hit a stop sequence you set
tool_use Wants to call a tool
pause_turn Paused: send it back to continue
refusal Declined for safety reasons

Check stop_reason before trusting the reply.

4

Shaping the reply

Streaming, effort, structured output and images.

Streaming

const stream = client.messages.stream({
  model: "claude-opus-5-5",
  max_tokens: 64000,
  messages,
});
 
stream.on("text", (text) => {
  process.stdout.write(text);
});
 
const msg = await stream.finalMessage();
  • Text arrives as it is written.
  • Use it for long replies: a slow non-streaming request can time out.

Effort

output_config: { effort: "low" },
Level Use it for
low Quick, simple tasks
medium Default on Opus 5.5 and Haiku 5.5
high Default on Fable 5.2 and Sonnet 5.5
xhigh Hard coding and agent work
max When being right matters more than cost

Higher effort means more thinking, more tokens and a slower reply.

Thinking

thinking: {
  type: "adaptive",
  display: "summarized",
},
  • Current models reason before they answer and decide how much by themselves.
  • display: "summarized" returns a summary of that reasoning. By default it is left out.
  • On Fable 5.2 and Opus 5.5 thinking cannot be turned off. Lower the effort instead.
  • The older budget_tokens setting is rejected by current models.

JSON output

import { z } from "zod";
import { zodOutputFormat }
  from "@anthropic-ai/sdk/helpers/zod";
 
const Person = z.object({
  name: z.string(),
  email: z.string(),
});
 
const msg = await client.messages.parse({
  model: "claude-opus-5-5",
  max_tokens: 16000,
  messages,
  output_config: {
    format: zodOutputFormat(Person),
  },
});
 
msg.parsed_output.name;
  • The reply is guaranteed to match the schema.
  • parsed_output is null if parsing failed, so check it.

Images

content: [
  {
    type: "image",
    source: {
      type: "url",
      url: "https://example.com/cat.png",
    },
  },
  { type: "text", text: "Describe this." },
],
  • Put the image before the question.
  • A local file is sent as type: "base64" with a media_type.
5

Tools

Letting Claude call your code.

What a tool is

  • A function you describe to Claude: its name, what it does and what input it takes.
  • Claude never runs it. It asks, your code runs it, and you send back the result.
  • The description is what Claude reads to decide when to use it. Make it specific.

Define a tool

const tools = [
  {
    name: "get_weather",
    description: "Weather in a city now",
    input_schema: {
      type: "object",
      properties: {
        city: { type: "string" },
      },
      required: ["city"],
    },
  },
];

Pass it as tools in the request.

The tool loop

  1. Send the request with tools.
  2. If stop_reason is tool_use, find the tool_use blocks in content.
  3. Run each one with its input.
  4. Add Claude's reply to messages, then a user message holding the results.
  5. Send again. Repeat until stop_reason is end_turn.

Send a result back

messages.push({
  role: "assistant",
  content: msg.content,
});
 
messages.push({
  role: "user",
  content: [
    {
      type: "tool_result",
      tool_use_id: block.id,
      content: "18°C, cloudy",
    },
  ],
});
  • block is the tool_use block being answered.
  • Put every result for one turn in a single user message.
  • If the tool failed, add is_error: true. Do not leave the result out.

Built-in tools

These run on Anthropic's servers. There is no loop to write.

Tool type name
Web search web_search_20260209 web_search
Web fetch web_fetch_20260209 web_fetch
Run code code_execution_20260521 code_execution
tools: [
  {
    type: "web_search_20260209",
    name: "web_search",
  },
],
6

Cost and speed

Paying less and waiting less.

Prompt caching

const msg = await client.messages.create({
  model: "claude-opus-5-5",
  max_tokens: 16000,
  cache_control: { type: "ephemeral" },
  system: longInstructions,
  messages,
});
  • Caches the start of the request so the next one reuses it.
  • The repeated part must be identical, character for character.
  • Put what stays the same first and what changes last.
  • A cached read costs about a tenth of the normal input price.
  • The cache lasts 5 minutes; add ttl: "1h" for an hour.

Check the cache

msg.usage.input_tokens;
msg.usage.cache_creation_input_tokens;
msg.usage.cache_read_input_tokens;
Field Tokens that were
input_tokens Not cached: full price
cache_creation_input_tokens Written to the cache
cache_read_input_tokens Read from the cache

If the last one stays at 0, something near the start of the prompt changes every time, such as a date.

Count tokens first

const count =
  await client.messages.countTokens({
    model: "claude-opus-5-5",
    messages,
  });
 
count.input_tokens;

Spend less

Situation Use
Same long prompt each time Prompt caching
The answer can wait Batches: half price
A simple task Haiku 5.5, or lower effort
Replies too long Ask for a length in the prompt
History keeps growing Start a new conversation from a summary
7

Errors

What went wrong, and whether to try again.

Status codes

Code Meaning Retry?
400 The request is malformed No
401 Missing or wrong API key No
402 Billing problem No
403 Not allowed for this key No
404 Unknown model or address No
413 Request too large No
429 Too many requests Yes
500 Problem at Anthropic Yes
529 Service overloaded Yes

Catch errors

const { RateLimitError } = Anthropic;
const { APIError } = Anthropic;
 
try {
  await client.messages.create(params);
} catch (error) {
  if (error instanceof RateLimitError) {
    // wait, then try again
  } else if (error instanceof APIError) {
    console.error(error.status);
  } else {
    throw error;
  }
}
  • Check the most specific class first.
  • Test the class, not the text of the message.

Retries and timeouts

const client = new Anthropic({
  maxRetries: 2,    // the default
  timeout: 600_000, // 10 min, in ms
});
  • The SDK already retries 408, 409, 429, 5xx and connection errors.
  • The timeout is in milliseconds.

Refusals

if (msg.stop_reason === "refusal") {
  msg.stop_details.category;
  msg.stop_details.explanation;
}
  • A refusal is a normal response, not an error. Nothing is thrown.
  • stop_details is only filled in for a refusal.
8

Claude Code

Claude as a coding assistant in your terminal.

Install

curl -fsSL https://claude.ai/install.sh \
  | bash
System Command
Windows PowerShell irm https://claude.ai/install.ps1 | iex
Homebrew brew install --cask claude-code
npm npm install -g @anthropic-ai/claude-code
  • Check with claude --version.
  • It needs a paid Claude plan or a Console account.

Start and resume

Command Does
claude Start a session in this folder
claude "query" Start with a first prompt
claude -p "query" Answer once, then exit
claude -c Continue the last conversation here
claude -r Pick a past session to resume
claude update Update to the latest version
cat logs.txt | claude -p "explain"

Useful flags

Flag Does
--model Choose the model: opus, sonnet, haiku, fable
--permission-mode Start in a mode such as plan or acceptEdits
--add-dir Give access to another folder
--output-format With -p: text, json or stream-json

Commands in a session

Command Does
/help List the commands
/init Create a CLAUDE.md for the project
/clear Start a new conversation
/compact Summarise the conversation to free space
/context Show what is filling the context
/model Switch model
/effort Set the effort level
/plan Plan first, change nothing yet
/rewind Go back to an earlier point
/resume Reopen a past conversation
/permissions Choose what runs without asking
/mcp Manage connections to outside tools
/usage Show cost and plan limits
/code-review Review the current changes

CLAUDE.md

  • A file of instructions for the project, loaded at the start of every session.
  • Put in it what a new teammate would need: how to build, how to test, the rules of the codebase.
  • Create it with /init, edit it with /memory.
  • Keep it short. Everything in it uses context in every session.
  • How it fits a wider workflow: the AI-native SDLC.
9

More help

The official pages this sheet was checked against.

Official documentation

Topic Page
Models Models overview
Prices Pricing
Prompting Prompt engineering
Requests Create a message
Tools Tool use
Caching Prompt caching
Errors Errors
Claude Code CLI reference and commands