Foil Wizard
The Foil Wizard is an AI-powered CLI tool that analyzes your codebase and automatically adds Foil instrumentation. Instead of manually wrapping every LLM call and agent workflow, the wizard reads your code, understands your architecture, and writes the integration for you.How It Works
The wizard is built on the Claude Agent SDK. When you run it, an AI agent:- Scans your project structure and identifies LLM calls, agent loops, and tool usage
- Determines the best instrumentation strategy (manual spans vs auto-instrumentation)
- Installs the Foil SDK
- Modifies your source files to add tracing
- Verifies the integration works
Prerequisites
- A Foil account with an API key
- Node.js 18+ installed
Usage
The wizard edits your source files. We recommend running it on a separate branch.
FOIL_API_KEY in your environment.
When it’s done, review the changes with git diff. The wizard will have:
- Installed
@getfoil/foil-js(orfoil-sdkfor Python projects) - Added Foil initialization at your app’s entry point
- Wrapped LLM calls with tracing spans
- Added tool call instrumentation if applicable
- Set up proper shutdown handling
What the Wizard Instruments
The wizard detects and instruments:| Pattern | What It Does |
|---|---|
| OpenAI SDK calls | Wraps with auto-instrumentation or manual ctx.llmCall() spans |
| Anthropic SDK calls | Adds tracing spans around message creation |
| Agent loops | Creates parent agent spans with nested LLM and tool spans |
| Tool/function calls | Instruments tool execution with ctx.executeTools() |
| Multi-file agents | Follows imports to trace across files |
Rate Limits
The wizard is rate-limited to 5 sessions per hour per user. Each session makes approximately 10-30 AI calls depending on the size of your codebase.Troubleshooting
Wizard made incorrect changes
Wizard made incorrect changes
Since you’re on a separate branch, you can reset the changes and try again:
Wizard times out
Wizard times out
Large codebases may cause the wizard to hit the 5-minute timeout on individual steps. Try running it from a subdirectory containing your main application code:
Rate limit exceeded
Rate limit exceeded
The wizard allows 5 sessions per hour. Wait for the rate limit to reset, or integrate manually using the Quickstart guide.