Making an Email Agent using the Claude Code SDK
If I wasn’t at Anthropic, I would be making agents using the Claude Code SDK.
But doing > talking. So I’m building in public and open sourcing a local email agent.
This is part one on agentic search.
First, why the Claude Code SDK?
Whenever I’ve built an agent in the past I ended up hand rolling the same patterns that are now just way easier to use the Claude Code SDK.
In this example I’m using it for subagents, context management, the file system & code generation.
Building Context
Email has a ton of context on me. My ideal agent should be able to (with permission):
- Know info about me like my address, phone number, etc
- Write intros based on the context I have with contacts
- Find all relevant emails to draft a response
Previous generation LLMs would use RAG to find relevant emails to put into context.
RAG is fast, but noisy and hard to maintain. In this case, I would have to index my entire inbox and keep it up to date with each email.
imo this is why a lot of lastgen AI email didn't work
With the Claude Code SDK you can use Agentic Search.
Instead of passing it in a fixed context, you let it search your inbox like a human would (e.g. by email addresses and text) to find and build its context
I have a search subagent that can search my inbox, but here’s the twist-
Instead of the tool call returning an array of emails, it writes it to a log file and then it uses grep to search across these files.
This performed way better and is super easy with the SDK.
What does this mean? I can get my agent to build a profile for me from scratch just by agentically searching my inbox.
This is what that looks like right now, it honestly surprised me by how much it was able to find.
Open source repo coming soon!
Share this Scrolly Tale with your friends.
A Scrolly Tale is a new way to read Twitter threads with a more visually immersive experience.
Discover more beautiful Scrolly Tales like this.