Lesson

Turn Your AI Agent into a Reusable Command-Line Tool

Turn your custom AI agent into a standalone CLI tool. Learn bun build, add it to PATH, and run your agent anywhere with a simple command.

Access
Included
Transcript
Needs source

A custom agent is only useful if it's easy to run. In this lesson, we'll level up our "French" agent by compiling it into a standalone executable with bun build. You'll learn how to transform a clunky bun run agents/french.ts command into a simple, memorable french command that you can run from anywhere in your terminal. We'll walk through adding the agent to your system's PATH, making your custom AI tools feel like a natural part of your command-line environment.

The Workflow

  1. Compile the Agent: A single Bun command transforms your TypeScript file into a native executable.
  2. Update System PATH: The directory containing your new executable is added to your shell's PATH environment variable.
  3. Reload and Run: After reloading your shell configuration, your custom agent is available as a system-wide command.

Key Benefits

  • Simplicity: Convert complex bun run ... commands into a single, memorable command (e.g., french).
  • Portability: The compiled executable is a single file, making it easy to manage and distribute.
  • System-Wide Access: Run your custom tools from any directory in your terminal without needing to specify the full path.
  • Professional Tooling: Package your scripts in a way that makes them feel like native, professional command-line applications.

Commands and Code

First, compile the TypeScript agent into an executable file located in a bin directory.

bun build agents/french.ts --compile --outfile bin/french

You can now run the agent directly by referencing the new executable file.

bin/french

To make this command globally accessible, open your shell's configuration file. In this case, it's .zshrc.

cursor ~/.zshrc

Add a line to export the path to your bin directory, appending it to the existing PATH.

export PATH="$PATH:/Users/johnlindquist/dev/agents/bin"

Reload your shell's configuration to apply the changes immediately.

source ~/.zshrc

Now, you can run your agent from anywhere on your system by simply typing its name.

french

You can interact with your newly created global agent.

> testing
> hello