AnyAgent

Quickstart

Install AnyAgent, detect an installed agent, and run your first prompt.

This page takes you from install to a working script: detect a coding agent CLI installed on your machine and run one prompt on it.

Prerequisites

  • Node.js 22.18 or later, or Bun, so the example .ts file runs without a build step; AnyAgent itself runs on Node.js 18 or later
  • At least one supported agent installed and signed in

Install

npm i anyagent

Write the script

Create a file named run-agent.ts:

import { create, detect } from "anyagent";

const [first] = await detect();
if (!first) {
  throw new Error("No supported coding agent found.");
}

const agent = create(first);
const result = await agent.run(
  "List the scripts in package.json and what each one does."
);

console.log(result.text);

detect() scans your PATH for supported agents, and create() wraps one in a runnable handle.

Run the script

Run it from a project directory, since the prompt asks about that project’s package.json:

node run-agent.ts

When the run finishes, the agent’s answer prints, worded by whichever agent you have installed:

package.json defines three scripts:

- build: compiles src/ to dist/ with tsc
- test: runs the unit test suite
- lint: checks the source with eslint

Next steps

On this page