Dev Environment & Foundations
Before writing any code, you need three things working: VS Code as your editor, Jupyter notebooks for interactive development, and the Anthropic Python SDK connected to a valid API key. This module gets all three running and ends with a verified "Hello Claude" test.
1. What You'll Need
- Python 3.9 or later, check with
python --versionorpython3 --version - VS Code, download from
code.visualstudio.com - An Anthropic API key, obtained from
console.anthropic.com - ~10 minutes and a terminal
2. Install VS Code Extensions
Open VS Code and install these two extensions from the Extensions panel (Ctrl+Shift+X / Cmd+Shift+X):
- Python, publisher: ms-python. Enables Python language support, linting, and virtual environment detection.
- Jupyter, publisher: ms-toolsai. Lets you run
.ipynbnotebooks directly inside VS Code without launching a browser.
3. Create Your Project Folder
Pick a home for your lab files. All 10 modules will build on the same notebook, so one folder is all you need.
mkdir claude-architect-lab
cd claude-architect-lab
4. Set Up a Virtual Environment
A virtual environment keeps the SDK and its dependencies isolated from the rest of your system, important when you're working with multiple Python projects.
# Create the environment
python -m venv .venv
# Activate it
# macOS / Linux:
source .venv/bin/activate
# Windows (PowerShell):
.venv\Scripts\Activate.ps1
# Windows (Command Prompt):
.venv\Scripts\activate.bat
Your terminal prompt should now show (.venv) to confirm it's active.
5. Install Dependencies
pip install anthropic python-dotenv ipykernel
- anthropic, the official Python SDK for the Claude API
- python-dotenv, loads your
.envfile so the API key is never hardcoded - ipykernel, registers your virtual environment as a Jupyter kernel so VS Code can find it
6. Get Your API Key
- Go to
console.anthropic.comand sign in (or create a free account). - Navigate to API Keys in the left sidebar.
- Click Create Key, give it a name like "architect-lab", and copy the key, it starts with
sk-ant-.
You only see the full key once, so copy it immediately.
7. Store Your Key Safely
Create two files in your project folder:
ANTHROPIC_API_KEY=sk-ant-api03-YOUR-KEY-HERE
.env
.venv/
__pycache__/
*.pyc
.ipynb_checkpoints/
.gitignore above ensures .env stays local. If you accidentally push a key, rotate it immediately in the Anthropic console, old keys can be used by anyone who finds them in your git history.
8. Create Your Lab Notebook
- Open your project folder in VS Code:
File → Open Folder - Create a new file named
lab.ipynb(File → New File, then save with the.ipynbextension). - VS Code will open it as a notebook. In the top-right corner, click Select Kernel.
- Choose Python Environments → select the
.venvyou just created. If it doesn't appear, runPython: Select Interpreterfrom the command palette first.
9. Hello Claude, Your First Cell
Add a new code cell and paste the following. Run it with Shift+Enter.
import anthropic
from dotenv import load_dotenv
load_dotenv() # reads ANTHROPIC_API_KEY from your .env file
client = anthropic.Anthropic()
message = client.messages.create(
model="claude-sonnet-4-6",
max_tokens=256,
messages=[
{"role": "user", "content": "In one sentence, what is the Claude API?"}
]
)
print(message.content[0].text)
If everything is configured correctly, you should see a one-sentence response from Claude. That's your environment confirmed.
10. Understanding the Response Object
Before moving to Module 2, it's worth knowing what the API returned. Add a second cell:
print("Stop reason:", message.stop_reason)
print("Input tokens:", message.usage.input_tokens)
print("Output tokens:", message.usage.output_tokens)
print("Model:", message.model)
- stop_reason,
"end_turn"means Claude finished naturally. The exam tests this heavily. - usage, input and output token counts used to calculate cost.
- model, confirms which model version actually ran your request.
API Signal to Remember: tool_use vs. end_turn
Agentic control flow starts with this one field:
stop_reason == "tool_use"means the loop continues. Your application must execute the requested tool, append a matchingtool_result, and call Claude again with the full updated history.stop_reason == "end_turn"means the loop terminates. Claude completed its turn without requesting another tool.
Do not check whether Claude said it is done. Use the structured stop_reason value.
lab.ipynb. A well-structured notebook with clear headings and focused cells is also good practice for the structured output modules later in the lab.
Troubleshooting
| Problem | Most likely cause | Fix |
|---|---|---|
AuthenticationError | .env not found or key is wrong | Check the file is in the project root, not a subfolder. Confirm no extra spaces around the =. |
| Kernel not listed | .venv not registered with Jupyter | Run python -m ipykernel install --user --name .venv inside your activated environment. |
ModuleNotFoundError: anthropic | Wrong Python environment active | Confirm (.venv) is in your terminal prompt, then re-run pip install anthropic. |
| VS Code shows "No kernel" | Jupyter extension not installed | Install the Jupyter extension from the Extensions panel and reload VS Code. |
Lab Exercise: Environment Verification & Response Anatomy
Self-driven lab Module1_Self_Driven_Lab.ipynbObjective: confirm your dev environment and master the identification of critical API signals like stop_reason and usage.
- Stateless request: use the Messages API to send a
"Hello Claude"prompt. Print the entire Message object. - Signal inspection: identify the
stop_reason. Verify it is"end_turn". Explain why parsing response text for phrases like"I am finished"is a loop termination anti-pattern. - Token auditing: inspect the
usageblock. Identifyinput_tokensandoutput_tokens. Calculate the cost of the request, applying the 1.1x multiplier for Opus 4.6+ wheninference_geo: "us"is used. - Signal simulation: manually modify a request to include a mock tool. Verify that the API returns
stop_reason: "tool_use". Explain how this signal drives the next iteration of the loop.