Nudge

Introduction

Type-safe prompt builder with AI-powered codegen.

Nudge is in pre-release. Expect breaking changes.

What is Nudge?

Nudge is a TypeScript library for building AI prompts. You define what your prompt should do with a fluent builder-Nudge uses AI to generate the actual system prompt.

import { prompt } from "@nudge/core";

const reviewer = prompt("code-reviewer", (p) =>
  p
    .persona("senior engineer")
    .input("code snippet")
    .output("review with suggestions")
    .do("explain reasoning")
    .dont("nitpick style")
);

Run npx @nudge/cli generate → get an optimized system prompt. It's cached, so unchanged definitions skip the AI call.

Why use it?

  • Type-safe - Full autocomplete. Typed variables and options.
  • AI-generated - Your structure becomes a polished prompt. No hand-tuning.
  • Cached - Hash-based caching. Only regenerate what changed.
  • Composable - Share rules with .use(). Toggle sections with .optional().

Example

const assistant = prompt("assistant", (p) =>
  p
    .persona("assistant for {{company}}")
    .do("be concise")
    .optional("formal", (p) => p.do("use formal language"))
);

// Variables and options are fully typed
assistant.toString({ company: "Acme", formal: true });

Packages

PackageDescription
@nudge/coreThe prompt builder
@nudge/cliCodegen CLI

On this page