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
- Building with the Claude API, part 1: Requests, evals and prompting
- Building with the Claude API, part 2: Tool use and RAG
- Building with the Claude API, part 3: Claude features and MCP
- Building with the Claude API, part 4: Claude Code, computer use and agents
- Claude with Amazon Bedrock
- 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 runclaude. It works on macOS, Linux and WSL. /initscans 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.
- Project:
#quickly adds a note to memory./clearresets the context.- Effective workflows:
- Give context: point Claude at the relevant files.
- Ask it to plan first, optionally with extended thinking.
- 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/*.mdand can use$ARGUMENTS. - Automated debugging: a GitHub Action runs Claude to read production logs, fix errors and open a PR.
- Parallel instances: run several copies in separate git worktrees so they don’t conflict. Custom commands go in
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
ffmpegorwhisperto 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
- 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.
- Q: What are the four required pieces of a Messages API request? → A: API key, model, messages and max_tokens.
- Q: What does
max_tokensdo? → A: It is a hard ceiling on output length, not a target. - 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.
- Q: Which temperature range suits data extraction, and which suits brainstorming? → A: 0–0.3 for extraction; 0.8–1.0 for brainstorming.
- Q: Which stream event carries the generated text? → A:
ContentBlockDelta. Usestream.text_streamandget_final_message()to make this simpler. - Q: How do you get clean JSON without commentary using only prompting? → A: Prefill the assistant turn with “
json" and set `stop_sequences=["”]`. - 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.
- Q: Which two “be specific” techniques does the course teach? → A: Output quality guidelines (almost always) and process steps (for complex problems).
- Q: What must each
tool_resultblock include? → A: The matchingtool_use_idand the content, optionally withis_error. It is sent in a user message. - Q: How does the tool loop know when to stop? → A: When
response.stop_reason != "tool_use". - 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.
- 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.
- Q: What is the RRF formula? → A: Σ 1/(k + rank) over each index; k is usually 60.
- Q: What are the minimum thinking budget and its constraint? → A: 1024 tokens, and
max_tokensmust be greater than the budget. - Q: Why do thinking blocks have a signature? → A: It detects tampering when reasoning is sent back. Redacted blocks are passed back unchanged.
- Q: What is the token cost of an image? → A: Roughly width × height / 750.
- 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.
- Q: Which MCP primitive is controlled by whom? → A: Tools by the model, resources by the app, prompts by the user.
- 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:
- Generate 10 test cases with Claude.
- Add a model grader that returns strengths, weaknesses, reasoning and score.
- Add a code grader.
- 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_tokensandcache_read_input_tokensacross calls. Then deliberately break the cache by editing one character. - Extend the FastMCP document server with a
summarizeprompt and adocs://documents/{id}/metaresource. Test both in the MCP Inspector, then connect the server to Claude Code withclaude 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.