Learn/Claude Academy: Build with the APIguide

Building with the Claude API, part 4: Claude Code, computer use and agents

Modules 8 and 9: Claude Code, computer use, workflows and agents, plus review flashcards.

Series Claude Academy: Build with the API Part 4 of 6
  1. Building with the Claude API, part 1: Requests, evals and prompting
  2. Building with the Claude API, part 2: Tool use and RAG
  3. Building with the Claude API, part 3: Claude features and MCP
  4. Building with the Claude API, part 4: Claude Code, computer use and agents
  5. Claude with Amazon Bedrock
  6. Claude on Google Cloud's Vertex AI

A walkthrough of the Claude Academy course Building with the Claude API (Build with the API track, 67 lessons, 8 quizzes), split into four parts; this is part 4. Each lesson is summarised with my own tables and examples; take the course for the full lessons. All the courses are listed in the Claude Academy course index.

Note: This summary comes mainly from the public lesson text. A few details were added from docs.claude.com or the sibling Bedrock/Vertex courses, such as reranking, contextual retrieval and adaptive thinking. Verify those details against the lessons and current docs.

8. Anthropic Apps: Claude Code and Computer Use

Claude Code

  • Claude Code is a terminal-based coding agent. Install it with npm install -g @anthropic-ai/claude-code, then run claude. It works on macOS, Linux and WSL.
  • /init scans the repo and writes CLAUDE.md. Memory files come in three scopes:
    • Project: CLAUDE.md, committed to the repo.
    • Local: CLAUDE.local.md, not committed.
    • User: ~/.claude/CLAUDE.md, applies to all your projects.
  • # quickly adds a note to memory. /clear resets the context.
  • Effective workflows:
    1. Give context: point Claude at the relevant files.
    2. Ask it to plan first, optionally with extended thinking.
    3. Ask it to implement.
    • Alternatively, use TDD: Claude writes the tests, then code until the tests pass.
  • MCP servers extend Claude Code. For example, claude mcp add documents uv run main.py. Popular servers include Sentry, Playwright, Figma context, Atlassian, Firecrawl and Slack.
  • From the sibling courses:
    • Parallel instances: run several copies in separate git worktrees so they don’t conflict. Custom commands go in .claude/commands/*.md and can use $ARGUMENTS.
    • Automated debugging: a GitHub Action runs Claude to read production logs, fix errors and open a PR.

Computer use

  • Claude controls a desktop: it takes screenshots, clicks, types and scrolls. A typical use is QA testing a UI, such as an @-mention autocomplete component.
  • It is ordinary tool use. You send a small special tool schema that is expanded server-side into a full list of mouse, keyboard and screenshot actions. Your environment carries out those actions.
  • Anthropic’s reference implementation is a Docker container with a desktop and Firefox, available in the anthropic-quickstarts repo. Always run it isolated.

9. Agents and Workflows

  • Workflow: you know the steps in advance and code them as a series of Claude calls.
  • Agent: you give Claude a goal and tools, and Claude decides the steps.

Workflow patterns

Pattern Idea Course example
Evaluator-optimizer A producer generates output, a grader evaluates it, and feedback loops back until it passes Image → CadQuery 3D model → render → compare to original
Parallelization Split into independent subtasks, run them concurrently, aggregate Rate each material (metal, polymer, ceramic…) in parallel, then pick the best
Chaining Sequential steps, each focused on one job Write an article, then a revision pass to remove emojis and “As an AI” text
Routing Classify the input first, then send it to a specialized pipeline Video-script topic → genre-specific prompt (educational, entertainment…)
  • Chaining helps when a long prompt with many constraints gets ignored. Split the constraints into a later fix-up step.

Agents and tools

  • Give agents abstract, combinable tools rather than hyper-specific ones. Claude Code’s set is bash, read, write, edit, glob and grep.
  • Environment inspection: agents need to see the effect of their actions.
    • Read a file before editing it.
    • Take a screenshot after each computer-use action.
    • Check outputs, for example run ffmpeg or whisper to verify that a generated video has captions.
  • Qualities of effective agents (sibling courses):
    • Focused tool sets run in loops.
    • Context gathered through tools.
    • High-value tasks where errors are cheap.
    • Continuous evaluation.

Workflows vs agents

Workflows Agents
Predictability High; easy to test and evaluate Lower
Flexibility Limited to the designed steps Handles novel tasks
Reliability Higher success rate Lower success rate
UX Fixed inputs Conversational, open-ended
  • Recommendation: use workflows whenever you can. Use agents only when you truly need their flexibility, because users want products that work reliably.

Quick-Review Flashcards

  1. Q: Why must API calls go through your own server? → A: The API key is a secret and would be exposed in client-side code.
  2. Q: What are the four required pieces of a Messages API request? → A: API key, model, messages and max_tokens.
  3. Q: What does max_tokens do? → A: It is a hard ceiling on output length, not a target.
  4. Q: How do you keep a multi-turn conversation going when the API is stateless? → A: Store the user and assistant messages and resend the full history each time.
  5. Q: Which temperature range suits data extraction, and which suits brainstorming? → A: 0–0.3 for extraction; 0.8–1.0 for brainstorming.
  6. Q: Which stream event carries the generated text? → A: ContentBlockDelta. Use stream.text_stream and get_final_message() to make this simpler.
  7. Q: How do you get clean JSON without commentary using only prompting? → A: Prefill the assistant turn with “json" and set `stop_sequences=["”]`.
  8. Q: What are the three grader types, and why ask a model grader for reasoning? → A: Code, model and human. Without reasoning, models tend to give middling scores of about 6.
  9. Q: Which two “be specific” techniques does the course teach? → A: Output quality guidelines (almost always) and process steps (for complex problems).
  10. Q: What must each tool_result block include? → A: The matching tool_use_id and the content, optionally with is_error. It is sent in a user message.
  11. Q: How does the tool loop know when to stop? → A: When response.stop_reason != "tool_use".
  12. Q: How do the text editor tool and the web search tool differ? → A: For the text editor, Claude knows the schema but you implement the file operations. Web search runs entirely on Anthropic’s side.
  13. Q: Why combine BM25 with vector search? → A: Embeddings capture meaning but can miss exact terms or IDs. BM25 favours rare exact terms. RRF merges the two rankings.
  14. Q: What is the RRF formula? → A: Σ 1/(k + rank) over each index; k is usually 60.
  15. Q: What are the minimum thinking budget and its constraint? → A: 1024 tokens, and max_tokens must be greater than the budget.
  16. Q: Why do thinking blocks have a signature? → A: It detects tampering when reasoning is sent back. Redacted blocks are passed back unchanged.
  17. Q: What is the token cost of an image? → A: Roughly width × height / 750.
  18. Q: What does a cache breakpoint cache, and what invalidates it? → A: Everything up to and including the breakpoint, in tools → system → messages order. Any change to that prefix invalidates it.
  19. Q: Which MCP primitive is controlled by whom? → A: Tools by the model, resources by the app, prompts by the user.
  20. Q: Name the four workflow patterns, and say when to prefer an agent. → A: Evaluator-optimizer, parallelization, chaining and routing. Prefer an agent only when the steps can’t be known in advance; otherwise workflows are more reliable.

Practice Ideas

  • Build a CLI chatbot with streaming output, a configurable system prompt and temperature, and full history management.
  • Write an eval pipeline for a prompt of your own:
    1. Generate 10 test cases with Claude.
    2. Add a model grader that returns strengths, weaknesses, reasoning and score.
    3. Add a code grader.
    4. Iterate through clear & direct → specific → XML → examples, and record each score.
  • Build the reminder agent (date-time, add duration, set reminder) with error-returning tool results. Then add a batch tool and a forced-tool structured-extraction step.
  • Build a hybrid RAG over a Markdown report: chunk by section, index with VoyageAI vectors and BM25, merge with RRF, then add LLM reranking and contextual retrieval. Compare the results on ID-style queries.
  • Send a PDF with citations enabled and render the numbered citations with their page ranges.
  • Add prompt caching to a tool-heavy chat function and log cache_creation_input_tokens and cache_read_input_tokens across calls. Then deliberately break the cache by editing one character.
  • Extend the FastMCP document server with a summarize prompt and a docs://documents/{id}/meta resource. Test both in the MCP Inspector, then connect the server to Claude Code with claude mcp add.
  • Build a routing workflow (classify, then a specialized prompt) and an evaluator-optimizer loop. Compare how reliable they are against a single agent with generic tools.