Skip to content

Build your own coding agent in TypeScript.

createAgent() sends the prompt, runs the tools the model asks for and feeds back the results until the task is done.

TypeScript
import { createAgent } from 'zidane'
import { basic } from 'zidane/presets'
import { anthropic } from 'zidane/providers'

const agent = createAgent({
  ...basic,
  provider: anthropic({ apiKey: process.env.ANTHROPIC_API_KEY }),
  behavior: { codemode: true },
})

await agent.run({
  model: 'claude-opus-5-5',
  prompt: 'Retry GitHub calls that fail with a 502 or 503.',
})
agent.run()Opus 5.5
Retry GitHub calls that fail with a 502 or 503.
    • request now retries a 502 or 503 up to three times, waiting 0.5s, then 1s. Any other error still throws at once, so the three callers keep their handling. The 12 client tests pass.

      Opus 5.528s4$0.0512k940
    Run finished

    A hook on every turn.

    Hooks see each text delta, tool call, MCP event and budget, and can change most. A tool:gate hook stops a shell command before it runs and tells the model why.

    Hooks
    TypeScript
    // Every delta, tool call and budget event is a hook.
    agent.hooks.hook('tool:gate', (ctx) => {
      if (ctx.name === 'shell' && /\brm -rf\b/.test(String(ctx.input.command))) {
        ctx.block = true
        ctx.reason = 'Destructive command: ask the user first.'
      }
    })
    
    agent.hooks.hook('stream:text', ({ delta }) => process.stdout.write(delta))
    
    agent.hooks.hook('turn:after', ({ usage }) => {
      console.log(`${usage.input} in / ${usage.output} out`)
    })

    Choose where the tools run.

    Shell and file tools run on your machine, in Docker, or in an E2B or Daytona sandbox. Locally, Seatbelt (macOS) or bubblewrap (Linux) can fence each command.

    Execution contexts
    node:22-slim/workspace
    Run the server tests and tell me where they ran.
      • All 44 tests pass in a node:22-slim container, with the project mounted at /workspace.

        Opus 5.57s2$0.013.9k120

      Parts of the loop you can replace.

      Start with the quickstart.

      Install the package, sign in to a provider and run your first agent.

      Other ways to use Zidane.