◆ Vibe EngineeringSMIT · AI Agentic Engineering Urdu
Class 14 · 14.3

Driving Claude Code with the Agent SDK

Now the fun part — a quick tour of related tools you don’t need to memorise. First up: the Claude Agent SDK. Despite the name, it isn’t an agent framework. It’s a way to drive Claude Code from code — all the power of the agent, controlled programmatically.

🎯 Goal: control Claude Code from Python⏱ Read: 13 min🌶 Type: spicy demo

You don’t need to take notes on this — it’s a tour so you know it exists. But it clears up a common confusion, so it’s worth understanding.

01What the Agent SDK actually is

Not a framework — a remote control

The name “Claude Agent SDK” suggests an agent framework. It isn’t. It’s a way to programmatically drive Claude Code — you write code that hands Claude a prompt and a set of tools, and Claude does the agentic work. (It used to be called the Claude Code SDK; note the name is agent, singular.)

your main.pyprompt + tools Claude Code enginequery(prompt, options)reads / writes / edits files createdindex.html …
Same engine as the CLI — but you call it from code, choosing exactly which tools it may use.

02Set up a tiny uv project

We’ll use uv (fast Python tooling). From an empty folder:

terminal
uv init --bare              # a clean, empty project
uv python pin 3.13
uv add python-dotenv requests claude-agent-sdk   # like pip install
# drop in a .env with your ANTHROPIC_API_KEY, and a .gitignore

03The whole program

That’s the entire thing. Read it top to bottom — it is shorter than you’d expect:

main.py
import asyncio
from dotenv import load_dotenv
from claude_agent_sdk import query, ClaudeAgentOptions

load_dotenv(override=True)   # .env wins over system env vars

prompt = "Make a vanilla HTML + JS + CSS game of Space Invaders. " \
         "Write the code to files in the current directory, including index.html."

tools = ["Read", "Write", "Edit", "Bash"]   # the tools we allow Claude to use

async def main():
    options = ClaudeAgentOptions(
        allowed_tools=tools,
        model="claude-opus-4-6",   # splashing out for the demo — see the warning!
    )
    async for message in query(prompt=prompt, options=options):
        print(message)

asyncio.run(main())
Don’t use Opus in a tight loop

The demo uses claude-opus-4-6 purely for entertainment value. For real programmatic use — especially anything looping — pick a cheaper, faster model. Running your most expensive model in a loop is how you get a nasty bill.

04Run it: a game appears

terminal
uv run main.py
# messages stream back — a file appears — it’s working…
# done. index.html created.

Open index.html and there it is: a playable Space Invaders — start screen, arrow-key controls (never even mentioned in the prompt), sound, a score, and the alien marching across the top. A complete working game, in vanilla HTML/JS/CSS, built by Claude Code — driven entirely from that little script.

Yes, this one’s frivolous

Week one promised only one frivolous build. Consider this the exception that proves the point: the SDK will build whatever the prompt asks — commercial or fun — because it’s the same Claude Code engine underneath.

05When you’d reach for it

You won’t use the SDK day-to-day. But if you want to build an application on top of the whole Claude Code ecosystem — using its skills, plugins and tools from inside your own program — the Agent SDK is how you do it. Think of it as the door from “chatting in a terminal” to “embedding an agent inside software you ship”.

✓ Key takeaways

  • The Claude Agent SDK drives Claude Code from code — it is not an agent framework.
  • You give it a prompt and a list of allowed tools; query() streams back messages.
  • A ~20-line script built a full, playable Space Invaders game, zero-shot.
  • Use a cheap model for real / looping work — Opus in a loop is expensive.
  • Reach for it when embedding the Claude Code ecosystem inside your own app.