anth-known-pitfalls
Identify and avoid common Claude API anti-patterns and integration mistakes. Use when reviewing code, onboarding developers, or debugging subtle issues with Anthropic integrations. Trigger with phrases like "anthropic pitfalls", "claude anti-patterns", "claude mistakes", "anthropic common issues", "claude gotchas".
Best use case
anth-known-pitfalls is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Identify and avoid common Claude API anti-patterns and integration mistakes. Use when reviewing code, onboarding developers, or debugging subtle issues with Anthropic integrations. Trigger with phrases like "anthropic pitfalls", "claude anti-patterns", "claude mistakes", "anthropic common issues", "claude gotchas".
Teams using anth-known-pitfalls should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/anth-known-pitfalls/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How anth-known-pitfalls Compares
| Feature / Agent | anth-known-pitfalls | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Identify and avoid common Claude API anti-patterns and integration mistakes. Use when reviewing code, onboarding developers, or debugging subtle issues with Anthropic integrations. Trigger with phrases like "anthropic pitfalls", "claude anti-patterns", "claude mistakes", "anthropic common issues", "claude gotchas".
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
Related Guides
AI Agents for Coding
Browse AI agent skills for coding, debugging, testing, refactoring, code review, and developer workflows across Claude, Cursor, and Codex.
Cursor vs Codex for AI Workflows
Compare Cursor and Codex for AI coding workflows, repository assistance, debugging, refactoring, and reusable developer skills.
SKILL.md Source
# Anthropic Known Pitfalls
## Pitfall 1: Wrong Import / Class Name
```python
# WRONG — common mistake from OpenAI muscle memory
from anthropic import AnthropicClient # Does not exist
# CORRECT
import anthropic
client = anthropic.Anthropic()
```
```typescript
// WRONG
import { Anthropic } from '@anthropic-ai/sdk';
// CORRECT
import Anthropic from '@anthropic-ai/sdk'; // Default export
```
## Pitfall 2: Forgetting max_tokens (Required)
```python
# WRONG — max_tokens is REQUIRED, unlike OpenAI
msg = client.messages.create(
model="claude-sonnet-4-20250514",
messages=[{"role": "user", "content": "Hello"}]
) # Error: max_tokens is required
# CORRECT
msg = client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=1024, # Always specify
messages=[{"role": "user", "content": "Hello"}]
)
```
## Pitfall 3: System Prompt in Messages Array
```python
# WRONG — putting system message in messages array (OpenAI pattern)
messages = [
{"role": "system", "content": "You are helpful."}, # Will cause error
{"role": "user", "content": "Hello"}
]
# CORRECT — use the system parameter
msg = client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=1024,
system="You are helpful.", # Separate parameter
messages=[{"role": "user", "content": "Hello"}]
)
```
## Pitfall 4: Accessing Response Wrong
```python
# WRONG — OpenAI response pattern
text = response.choices[0].message.content # AttributeError
# CORRECT — Anthropic response pattern
text = response.content[0].text # content is array of blocks
# SAFER — handle multiple content blocks
text_blocks = [b.text for b in response.content if b.type == "text"]
text = "\n".join(text_blocks)
```
## Pitfall 5: Ignoring Stop Reason
```python
# WRONG — assuming response is always complete
text = msg.content[0].text # Might be truncated!
# CORRECT — check stop_reason
if msg.stop_reason == "max_tokens":
print("WARNING: Response was truncated. Increase max_tokens.")
elif msg.stop_reason == "tool_use":
print("Claude wants to call a tool — process tool_use blocks")
elif msg.stop_reason == "end_turn":
print("Complete response")
```
## Pitfall 6: Not Handling tool_use_id Properly
```python
# WRONG — fabricating tool_use_id
tool_results = [{"type": "tool_result", "tool_use_id": "some-id", "content": "..."}]
# CORRECT — use the exact ID from Claude's response
for block in response.content:
if block.type == "tool_use":
result = execute_tool(block.name, block.input)
tool_results.append({
"type": "tool_result",
"tool_use_id": block.id, # Must match exactly
"content": result
})
```
## Pitfall 7: Hardcoding Model IDs Without Versioning
```python
# RISKY — model aliases may change behavior
model = "claude-3-5-sonnet" # Alias, might point to different version
# BETTER — use dated version for reproducibility
model = "claude-sonnet-4-20250514" # Pinned version
```
## Pitfall 8: Not Using SDK Auto-Retry
```python
# UNNECESSARY — writing custom retry logic for 429/5xx
for attempt in range(3):
try:
msg = client.messages.create(...)
break
except Exception:
time.sleep(2 ** attempt)
# BETTER — SDK handles this automatically
client = anthropic.Anthropic(max_retries=5) # Built-in exponential backoff
msg = client.messages.create(...) # Auto-retries 429 and 5xx
```
## Pitfall 9: Inflated max_tokens
```python
# WASTEFUL — setting max_tokens higher than needed
# Doesn't cost more tokens, but increases latency
msg = client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=200000, # Way more than needed for a classification
messages=[{"role": "user", "content": "Classify: positive or negative?"}]
)
# BETTER — right-size for the task
msg = client.messages.create(
model="claude-haiku-4-20250514", # Use Haiku for classification
max_tokens=16, # Only need one word
messages=[{"role": "user", "content": "Classify: positive or negative?"}]
)
```
## Pitfall 10: No Cost Tracking
```python
# Every response includes usage data — track it
msg = client.messages.create(...)
cost = (msg.usage.input_tokens * 3.0 + msg.usage.output_tokens * 15.0) / 1_000_000
# Log cost per request to catch runaway spend early
```
## Quick Reference: Anthropic vs OpenAI Differences
| Feature | OpenAI | Anthropic |
|---------|--------|-----------|
| `max_tokens` | Optional | **Required** |
| System prompt | In messages array | `system` parameter |
| Response text | `.choices[0].message.content` | `.content[0].text` |
| Default import | Named export | Default export |
| Auto-retry | No | Yes (configurable) |
| Streaming | Yields chunks | SSE events |
## Resources
- [Messages API Reference](https://docs.anthropic.com/en/api/messages)
- [Python SDK](https://github.com/anthropics/anthropic-sdk-python)
- [TypeScript SDK](https://github.com/anthropics/anthropic-sdk-typescript)Related Skills
exa-known-pitfalls
Identify and avoid Exa anti-patterns and common integration mistakes. Use when reviewing Exa code, onboarding new developers, or auditing existing Exa integrations for correctness. Trigger with phrases like "exa mistakes", "exa anti-patterns", "exa pitfalls", "exa what not to do", "exa code review".
customerio-known-pitfalls
Identify and avoid Customer.io anti-patterns and gotchas. Use when reviewing integrations, onboarding developers, or auditing existing Customer.io code. Trigger: "customer.io mistakes", "customer.io anti-patterns", "customer.io gotchas", "customer.io pitfalls", "customer.io code review".
cursor-known-pitfalls
Avoid common Cursor IDE pitfalls: AI feature mistakes, security gotchas, configuration errors, and team workflow issues. Triggers on "cursor pitfalls", "cursor mistakes", "cursor gotchas", "cursor issues", "cursor problems", "cursor tips".
clay-known-pitfalls
Identify and avoid the top Clay anti-patterns, gotchas, and integration mistakes. Use when reviewing Clay integrations for issues, onboarding new team members, or auditing existing Clay table configurations. Trigger with phrases like "clay mistakes", "clay anti-patterns", "clay pitfalls", "clay what not to do", "clay gotchas", "clay code review".
clade-known-pitfalls
Common mistakes when building with the Anthropic API and how to avoid them. Use when working with known-pitfalls patterns. Trigger with "anthropic mistakes", "claude pitfalls", "anthropic gotchas", "common claude errors", "anthropic anti-patterns".
canva-known-pitfalls
Identify and avoid Canva Connect API anti-patterns and common integration mistakes. Use when reviewing Canva code, onboarding developers, or auditing existing Canva integrations for best practices violations. Trigger with phrases like "canva mistakes", "canva anti-patterns", "canva pitfalls", "canva what not to do", "canva code review".
anth-webhooks-events
Implement event-driven patterns with Claude API: streaming SSE events, Message Batches callbacks, and async processing architectures. Use when building real-time Claude integrations or processing batch results. Trigger with phrases like "anthropic events", "claude streaming events", "anthropic async processing", "claude batch callbacks".
anth-upgrade-migration
Upgrade Anthropic SDK versions and migrate between Claude API versions. Use when upgrading the Python/TypeScript SDK, migrating from Text Completions to Messages API, or adopting new API features like tool use or batches. Trigger with phrases like "upgrade anthropic sdk", "anthropic migration", "update claude sdk", "migrate to messages api".
anth-security-basics
Apply Anthropic Claude API security best practices for key management, input validation, and prompt injection defense. Use when securing API keys, validating user inputs before sending to Claude, or implementing content safety guardrails. Trigger with phrases like "anthropic security", "claude api key security", "secure anthropic", "prompt injection defense".
anth-sdk-patterns
Apply production-ready Anthropic SDK patterns for TypeScript and Python. Use when implementing Claude integrations, building reusable wrappers, or establishing team coding standards for the Messages API. Trigger with phrases like "anthropic SDK patterns", "claude best practices", "anthropic code patterns", "production claude code".
anth-reliability-patterns
Implement reliability patterns for Claude API: circuit breakers, graceful degradation, idempotency, and fallback strategies. Trigger with phrases like "anthropic reliability", "claude circuit breaker", "claude fallback", "anthropic fault tolerance".
anth-reference-architecture
Implement Claude API reference architectures for common use cases. Use when designing a Claude-powered application, choosing between direct API vs queue-based, or planning a multi-model architecture. Trigger with phrases like "anthropic architecture", "claude system design", "anthropic reference architecture", "design claude integration".