Stop repeating yourself and start automating. This lesson is your first step into building specialized AI agents. You'll learn the foundational skill of creating a simple, reusable "French-speaking" agent by spawning the Claude CLI with a custom system prompt. We'll cover the essential mechanics of using Bun.spawn to create an interactive session, how to externalize prompts in markdown files for easy editing, and the TypeScript setup needed to tie it all together. This is the core workflow we'll build on throughout the course.
How it Works
- Spawn a Process: Use 
Bun.spawnto run theclaudeCLI, inheriting standard I/O to create an interactive session directly in your terminal. - Externalize Prompts: Store system prompts in simple markdown (
.md) files. This separates the agent's "personality" from the code. - Import Prompts as Text: Leverage Bun's ability to import non-JavaScript files. We'll import the 
.mdfile with atype: "text"assertion. - Handle TypeScript Types: Create a custom type declaration file (
types.d.ts) to inform TypeScript how to handle.mdmodule imports, resolving any "Cannot find module" errors. - Dynamically Build Flags: Construct command-line arguments programmatically from a configuration object. This makes it easy to add or change the flags passed to the 
claudeprocess. - Launch the Agent: Run the script to launch a custom Claude agent that consistently follows the instructions from your external prompt file.
 
This workflow provides a powerful and scalable pattern for building a suite of specialized AI agents, making your development process with AI more organized and efficient.
Spoken Prompts
Dictating the content for the markdown prompt file:
Querying the French-speaking agent:
Terminal Commands
Initialize a new Bun project:
Run the agent script:
Code Snippets
Creating a custom type declaration in types.d.ts to allow importing .md files as modules in TypeScript.
Importing the content of a markdown file as a text string using Bun's import attributes.
Dynamically creating an array of command-line arguments from a configuration object to be passed to Bun.spawn.
Spawning the claude CLI process with the dynamically generated arguments using the spread operator.
