AI

How to Use Claude

Anthropic's Claude for chat, Projects, API, and long-context reasoning.

Interview tip Claude strengths: long context, careful reasoning, structured output. Use Projects for persistent knowledge.

① What you must know (30 sec)

Claude (by Anthropic) excels at long-context reasoning, careful analysis, and structured writing. Surfaces: claude.ai (chat, Projects, Artifacts), API (Messages API, tool use, batch), and Claude Code (terminal agent for repositories). Models: Opus (best), Sonnet (balance), Haiku (fast/cheap).
Analogy: Claude Projects are like giving the assistant a permanent filing cabinet for one client or codebase — not re-uploading docs every chat.

② How it works

claude.ai — browser chat, Artifacts (live docs/code), Projects with persistent knowledge
API — Messages API with system/user/assistant roles, streaming, tool_use blocks
Claude Code — CLI agent that reads, edits, and commits in your git repo
Long context — 200K+ tokens for full codebases or document sets in one prompt
Structured output — XML tags, JSON mode, and tool schemas for reliable parsing
API message flow
System promptUser + contextClaude responseTool result (optional)Final answer
Put critical instructions at the beginning AND end of long system prompts — Claude weighs both positions heavily.

③ Step-by-step (hands-on)

Step 1 — Pick the right surface

Quick questions → claude.ai. Automation → API. Large repo refactor → Claude Code. Batch jobs → Batch API (50% cost).

Step 2 — Choose model tier

Haiku for classification/speed; Sonnet for daily dev; Opus for architecture and hard reasoning.

Step 3 — Structure prompts with XML

......... — reduces ambiguity.

Step 4 — Use Projects for persistence

Upload specs, style guides, API docs once. Every chat in the Project inherits that knowledge.

Step 5 — API integration

anthropic SDK, messages.create with model, max_tokens, system. Handle stop_reason for tool_use.

Step 6 — Evaluate outputs

For critical work, ask Claude to critique its own answer against a rubric before you accept.

④ Code / config patterns

TechniqueWhenExample
XML tagsLong or multi-part prompts...
Chain of thoughtMath, logic, debugging"Think step by step, then answer"
Few-shotFixed output format2 examples of input → JSON output
Tool useAgents, API actionsDefine tools in API call
ProjectsRepeat work same domainClient docs always in context
import anthropic
client = anthropic.Anthropic()
msg = client.messages.create(
    model="claude-sonnet-4-20250514",
    max_tokens=1024,
    system="You are a code reviewer. Be concise.",
    messages=[{"role":"user","content":"Review this diff: ..."}]
)
print(msg.content[0].text)

⑤ Production & pitfalls

PitfallWhy it hurtsFix
Wall of text promptsMissed constraintsUse XML sections and bullet constraints
Wrong model for taskSlow or shallow answersHaiku for simple; Opus only when needed
Ignoring context limitsTruncated middle of huge pasteUse Projects or file references; summarize first
No output format specifiedUnparseable responses in pipelinesRequest JSON, markdown table, or max words
Skipping API streamingPoor UX for long answersUse stream=True for chat interfaces
Assuming web accessStale facts unless tools enabledUse search tools or RAG for current data
Production tips:
  • Batch API for offline eval and bulk processing
  • Rate limit handling with retries on 529/overloaded
  • Log request IDs for Anthropic support escalation
  • Enterprise for SSO, audit logs, and data retention controls

⑥ Interview / on-the-job Q&A

QuestionAnswer
Opus vs Sonnet vs Haiku?Opus: hardest tasks. Sonnet: best balance. Haiku: speed and cost.
What are Projects?Workspaces with persistent uploaded knowledge applied to every chat.
What are Artifacts?Side-panel live documents/code Claude generates you can edit and export.
Claude Code vs Cursor?Claude Code is terminal-first autonomous repo agent; Cursor is IDE-integrated.
How long is context?200K+ tokens on recent models — full books or large codebases.
What is tool use?API feature where Claude returns structured tool calls your app executes.

⑦ Tools & ecosystem

  • Surfaces: claude.ai, Anthropic API, Claude Code CLI
  • SDKs: anthropic (Python/TS)
  • Integrations: Amazon Bedrock, Google Vertex (Claude models)
  • Features: Batch API, tool use, prompt caching
claudeanthropicprojectsapilong-context

⑧ Revision checklist

  • Model tier matched to task complexity
  • Prompts use XML or clear sections for long context
  • Projects set up for recurring domain work
  • Output format specified for pipeline use
  • API keys in env vars, not client-side
  • Streaming enabled for user-facing chat
  • Tool use for actions requiring fresh data
  • Self-check step for high-stakes outputs
  • Data policy reviewed for sensitive content