Standard AI SDKs are powerful for text generation, but they can't read your local files, understand your code's context, or write changes back to your project. This lesson demonstrates how to break past that limitation using the @anthropic-ai/claude-code
SDK, which leverages the full power of the Claude Code executable installed in your environment.
You'll learn how to create simple yet powerful scripts that are aware of your codebase and can perform actions like reading files and writing output, all driven by natural language prompts.
Workflow demonstrated in this lesson:
- Initialize a new project with Bun and install the
@anthropic-ai/claude-code
SDK. - Use the
query
function to stream responses from the AI. - Filter streamed events to isolate and handle the final successful text result.
- Craft prompts that instruct the AI to read the script's own source code and analyze its contents.
- Grant permissions to the AI to perform file system actions, such as writing its findings to a new text file.
Key benefits:
- Go Beyond Text Generation: Build scripts that can read, understand, and interact with your project files.
- Leverage Built-in Tool Use: Directly access Claude Code's ability to perform actions without complex API integrations.
- Automate Code Analysis: Create tools that can analyze variables, summarize files, or perform other code-related tasks with a simple prompt.
- Secure by Default: Learn how to explicitly grant permissions for actions like file editing, ensuring you remain in control.