/claude-pack:clade-known-pitfallsfrom claude-pack
Documents ten common Anthropic API mistakes and fixes: missing max_tokens, wrong system prompt placement, non-alternating messages, unchecked stop_reason, client-per-request, missing 529 handling, hardcoded models, expensive output tokens, no streaming, and unnecessary PII.
Ships in claude-pack. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Ten common mistakes when building with the Anthropic API and how to avoid them: forgetting max_tokens (required), system prompt in messages array (wrong), non-alternating messages, unchecked stop_reason, creating client per request, no 529 handling, hardcoded model IDs, expensive output tokens, no streaming, and unnecessary PII.
max_tokensUnlike OpenAI, max_tokens is required. Omitting it returns a 400 error.
// BAD
await client.messages.create({ model: 'claude-sonnet-4-20250514', messages });
// GOOD
await client.messages.create({ model: 'claude-sonnet-4-20250514', max_tokens: 1024, messages });
Claude uses a top-level system parameter, not a system message in the array.
// BAD — this sends "system" as a user message role, which will error
messages: [{ role: 'system', content: '...' }, { role: 'user', content: '...' }]
// GOOD
system: 'You are helpful.',
messages: [{ role: 'user', content: '...' }]
Messages must strictly alternate between user and assistant.
// BAD — two user messages in a row
messages: [
{ role: 'user', content: 'Hello' },
{ role: 'user', content: 'How are you?' }, // ERROR
]
// GOOD — combine into one or add assistant between
messages: [
{ role: 'user', content: 'Hello. How are you?' },
]
stop_reasonIf stop_reason === 'max_tokens', the response was truncated.
if (message.stop_reason === 'max_tokens') {
// Response is incomplete — increase max_tokens or handle truncation
}
Each new Anthropic() creates a new connection pool. In serverless, this adds latency.
// BAD — new client every request
app.post('/chat', async (req, res) => {
const client = new Anthropic(); // Cold connection every time
});
// GOOD — reuse across requests
const client = new Anthropic();
app.post('/chat', async (req, res) => {
await client.messages.create({ ... });
});
529 (overloaded) is common during peak hours. The SDK retries automatically, but you should handle it for critical paths.
Model IDs change with new versions. Use environment variables.
const MODEL = process.env.CLAUDE_MODEL || 'claude-sonnet-4-20250514';
Output tokens cost 5x more than input tokens. A 4096 max_tokens response on Opus costs ~$0.30. Use the smallest max_tokens that works.
Without streaming, users stare at a blank screen for 5-30 seconds. Always stream for interactive use.
Don't include user PII in prompts unless the task requires it. Redact before sending.
| Pitfall | Fix |
|---|---|
Missing max_tokens | Always include it |
| System in messages | Use top-level system param |
| Non-alternating messages | Combine or interleave |
Unchecked stop_reason | Check for max_tokens truncation |
| Client per request | Module-level singleton |
| No 529 handling | SDK retries + fallback model |
| Hardcoded model IDs | Environment variable |
| Expensive output | Minimize max_tokens |
| No streaming | Always stream for UI |
| Unnecessary PII | Redact before sending |
max_tokens present on every messages.create callsystem parameterstop_reason checked for truncation| Error | Cause | Solution |
|---|---|---|
| API Error | Check error type and status code | See clade-common-errors |
See ten numbered pitfall sections above, each with BAD/GOOD code comparisons. Quick Reference table at the end summarizes all fixes.
Each section contains production-ready code examples. Copy and adapt them to your use case.
Integrate the patterns that match your requirements. Test each change individually.
Run your test suite to confirm the integration works correctly.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
32 skills in this plugin
/clade-advanced-troubleshootingDebug complex Claude issues — inconsistent outputs, tool use failures,
Use when working with advanced-troubleshooting patterns.
streaming problems, and edge cases.
Trigger with "claude inconsistent", "anthropic advanced debug",
"claude tool use broken", "anthropic streaming issues".
/clade-architecture-variantsBuild different types of Claude-powered applications — chatbots, RAG systems,
Use when working with architecture-variants patterns.
agents, content pipelines, and code generation tools.
Trigger with "claude architecture", "anthropic rag", "build with claude",
"claude agent pattern", "anthropic app design".
/clade-ci-integrationTest and validate Claude integrations in CI/CD pipelines —
Use when working with ci-integration patterns.
GitHub Actions, mocking strategies, and cost control.
Trigger with "anthropic ci", "test claude in ci", "anthropic github actions",
"claude automated testing".
/clade-common-errorsDiagnose and fix Anthropic API errors — authentication, rate limits,
Use when working with common-errors patterns.
overloaded, context length, and content policy issues.
Trigger with "anthropic error", "claude 429", "claude overloaded",
"anthropic not working", "debug claude api".
/clade-core-workflow-aRedirect to claude-model-inference for Messages API streaming,
vision, and structured output patterns.
Use when looking for the primary Anthropic workflow.
Trigger with "anthropic workflow", "claude main workflow".
/clade-core-workflow-bRedirect to claude-embeddings-search for tool use (function calling)
and agentic loop patterns with Claude.
Use when looking for the secondary Anthropic workflow.
Trigger with "anthropic tools", "claude function calling".
npx claudepluginhub jeremylongshore/tons-of-skills-marketplace --plugin claude-packOther plugins' skills for the same job