pal-code on npm

pal runs in your terminal.
Its brain is a library.

pal reads and edits your project through a streaming TUI, bring your own key to any OpenAI-compatible model, and extend it at runtime - tools, MCP servers, web search, multi-agent roles - without touching pal's core.

Requires Bun ≥ 1.1. Install with npm install -g pal-code, then run pal.

Coding agents are usually a monolith

Most terminal agents are one program: the agent loop, the tools, the model clients, and the UI all tangled together. That's fine until you want to change something the author didn't anticipate - add a tool, retarget a sub-agent, wire an MCP server, or reuse the engine somewhere that isn't the terminal.

pal is split on a single rule, enforced across the codebase:

Logic lives in @pal-code/core. Rendering lives in @pal-code/cli.

Engine as a package

The round loop, tool execution, provider registry, sessions, and compaction ship as a library. Any front-end can consume the same event stream the TUI does.

Extensions at runtime

A capability is an npm package that default-exports a small object. pal resolves it at runtime and never recompiles - adding a tool needs zero changes to pal.

Honest boundaries

Core never imports the UI; the CLI never re-decides engine behaviour. One loop, one event protocol, one place to look when a tool misbehaves.

What it does today

Everything below ships in the 0.0.x line - no roadmap required.

Agentic editing loop

Reads, writes, and edits files; runs shell commands; verifies its own work. Read-only tools dispatch in parallel; writers run one at a time so two edits can't race the same file.

Structural search & edit

Regex, glob, and AST search. When an exact-string edit misses on whitespace churn, edit_file falls back to a structural ast-grep pattern with $A captures.

Self-verification

A verify tool runs your project's typecheck/tests. On top of that, auto-diagnostics after every edit run your linter/typechecker (debounced, ~2s budget) and inject a one-line ✓ edit ok / ✗ file:line into the model's next round.

Model & provider freedom

One OpenAI-compatible adapter drives DeepSeek, Gemini, OpenRouter, OpenAI, Groq, xAI, Mistral, and custom endpoints from ~/.pal/providers.json. Key-shape detection, live /models, per-provider fallback and retry.

Reliability policy

Same provider first, then others. Quota exhaustion switches immediately; rate limits back off and retry. A turn survives a flaky model instead of dying.

Multi-agent orchestration

delegate and delegate_parallel spawn child agents with their own context, model, effort, and token budget. Named read-only roles and implementation lanes, with a live subagent indicator.

MCP client

Connect Model Context Protocol servers over stdio or remote HTTP. Discovered tools are merged into the agent's toolset and routed back to the right server.

Web access

fetch_url and web_search as an extension - DuckDuckGo, SearXNG, Tavily, or Brave.

Skills & roles as files

Shareable .md agents and skills with YAML frontmatter, loaded from the project or your home dir. Bodies load on demand so you don't pay tokens for what you don't use.

Sessions & undo

SQLite-backed history you can list and resume, context compaction with LLM-backed summaries, and pre-edit file snapshots with /undo.

Guardrails

Glob-based permissions with built-in rules for secrets, an always-deny list for catastrophic shell commands, and a read-only plan mode the agent can switch itself into.

Terminal craft

Streaming markdown, syntax-highlighted boxed code fences, an OSC 52 /copy, message queuing while a turn runs, and Esc to interrupt any in-flight delegation.

The architecture, briefly

One agent loop. One event stream. Two layers that never reach around each other.

  ┌──────────────┐        ┌──────────────┐        ┌──────────────┐
  │  TUI         │        │  sub-agent   │        │  future      │
  │  (@pal-code/ │        │  (delegate)  │        │  front-end   │
  │   cli)       │        │              │        │  (ACP, etc.) │
  └──────┬───────┘        └──────┬───────┘        └──────┬───────┘
         │  renders events        │  nested run           │
         └───────────┬────────────┴───────────┬──────────┘
                     │   AgentRunEvent stream  │
                     ▼                         ▼
         ┌───────────────────────────────────────────────┐
         │            @pal-code/core                     │
         │                                               │
         │   runAgent ── the one round loop               │
         │   runWithFallback ── retry / provider policy   │
         │   executeTool ── dispatch + permissions       │
         │   providers · sessions · compaction           │
         │   snapshots · diagnostics · config            │
         └───────────────────────────────────────────────┘
                     ▲
                     │  resolved at runtime (never compiled in)
   ┌─────────────────┼─────────────────┬─────────────────┐
   │                 │                 │                 │
┌──┴──────┐   ┌──────┴───────┐  ┌──────┴──────┐   ┌──────┴──────┐
│ web-    │   │ agents       │  │ mcp         │   │ your own    │
│ search  │   │ (roles)      │  │ (servers)   │   │ extension   │
└─────────┘   └──────────────┘  └─────────────┘   └─────────────┘

The boundary rule

Core has no knowledge of the TUI. The CLI does not re-decide what the agent does - it only renders events. Every capability has exactly one home: the split is by responsibility, not convenience.

The event protocol

runAgent yields a small vocabulary - model-start, round-start, text-delta, tool-start/tool-end, notice, aborted, done - and never touches the screen. Adding a front-end means consuming this stream.

Injected executor

The loop is handed its executeTool rather than importing the registry, avoiding a cycle and letting callers inject permission gates - the CLI gates children; tests inject fakes.

Scoped sub-runs

Because core keeps a little state for ergonomics (the todo list, the tracked shell cwd), delegate wraps children in captureRunScope/restoreRunScope so a child can't clobber the parent's plan or working directory.

An extension is one object

Adding a tool to pal should not require forking it. An extension is a normal npm package whose default export contributes tools, handlers, an optional setup(), and optional lifecycle hooks.

  • Tools in OpenAI function-calling format, with handlers returning a string.
  • setup() for process-wide capabilities (the agents extension registers the role provider here).
  • lifecycle hooks - onTurnStart, onTurnEnd, onToolCall, onError - to observe turns, tool calls, and failures without wrapping core.
  • Own config in ./<name>.json and ~/.pal/<name>.json, so pal's config stays clean.
  • Failure-isolated - a broken extension never stops pal from starting; failures surface in the sidebar.

Ship it as @yourname/pal-extension-name, drop it in ~/.pal/extensions/, or point at a path. Name it in config and pal finds it at runtime.

See how to install it →

import {ToolExtension} from '@pal-code/core';

export default {
  name: 'hello',
  tools: [{
    type: 'function',
    function: {
      name: 'echo',
      description: 'Echoes input text back.',
      parameters: {
        type: 'object',
        properties: {
          text: {type: 'string'},
        },
        required: ['text'],
      },
    },
  ],
  handlers: {
    echo: async (args) => String(args.text ?? ''),
  },
} satisfies ToolExtension;

Built for the terminal

The TUI is the product surface: streaming markdown, boxed code fences, a status line that names the model actually serving the turn, a live subagent counter, and a sidebar with token, cost, and context-fill stats.

Stay in flow

  • Type while a turn runs - messages queue and drain on settle.
  • Esc interrupts the turn, including a running delegation.
  • /copy yanks the last reply or code block over SSH via OSC 52.
  • Keybindings for scrollback; the transcript stays navigable.

See the cost

  • Live input/output/cache tokens, cache-hit %, and estimated cost.
  • Context-fill % against your configured window.
  • /effort low|medium|high to steer reasoning per turn.
  • Honest "(unpriced)" markers for models without pricing data.

When to reach for pal

There are many capable coding agents. pal is built for a specific set of priorities:

You want to extend, not fork

If your plan involves adding a tool, hooking an MCP server, or retargeting a sub-agent, pal's runtime extension model is the whole point.

You pick the model, per-role

Bring your own key to any OpenAI-compatible endpoint, and route different agents to different models and effort levels with token budgets.

You want a legible engine

An 18k-line TypeScript codebase with a stated architecture, 366 tests, and an eval harness. Inspectable by design, not a black box.

You keep control

Permissions, plan mode, per-turn tool allowlists, dangerous-command denies, and snapshots with /undo.

pal is MIT-licensed and pre-1.0 - the extension interface and internal APIs may still move. It targets developers who want control over their own setup, not a fully managed team service.

Install it in about a minute

pal is published to npm under pal-code and is MIT-licensed. Install it globally, run pal in any project, and point it at your own provider key.

# Bun 1.1+ or Node 18+ required
npm install -g pal-code
# or, with Bun:
bun add -g pal-code

$ pal

Bun first, Node works too

pal is built and tested on Bun and runs on Node 18 or newer as well. The published package carries prebuilt binaries for macOS, Linux, and Windows.

Bring your own key

No account, no hosted service, no telemetry. Set a provider key on first run and pal talks directly to the model API you chose.

Extend it yourself

Write an extension as a small npm package, drop it in ~/.pal/extensions, and it loads at runtime - no fork or rebuild of pal required.

View on npm Read the FAQ

Questions worth answering plainly

What is pal, exactly?

A bring-your-own-key terminal coding agent written in TypeScript that runs on Bun. It works inside your own project directory: it reads and edits files, searches the codebase, runs shell commands, and verifies its own changes. You supply your own model provider API key - there is no hosted service and no account with pal.

How do I install it?

Bun 1.1 or newer is required. Run npm install -g pal-code (or bun add -g pal-code), then start the agent with pal inside any project directory.

Which models and providers can I use?

Adapters ship for DeepSeek, Gemini, OpenRouter, OpenAI, Groq, xAI, and Mistral, all speaking the OpenAI-compatible streaming protocol. pal discovers each provider's live model list and can fall back to another configured provider when one runs out of quota or rate-limits.

Does my code leave my machine?

pal itself runs locally and reads your project directly. Prompt and file content go to whichever model provider you configured, under that provider's own terms and retention policy. pal does not proxy, mirror, or store your code, and this site sets no cookies and runs no analytics.

Can I add my own tools?

Yes - that is the core of the design. Extensions resolve at runtime and are never compiled in. An extension is an npm package whose default export declares a name, tool definitions, handlers, an optional setup(), and optional lifecycle hooks such as onTurnStart, onTurnEnd, onToolCall, and onError. Drop it in ~/.pal/extensions or name it in your config.

Is the tool calling model-safe?

No - and it does not pretend to be. Permissions are glob-based allow/ask/deny rules with prompts for sensitive files and a deny list for catastrophic shell commands. That is guardrailing, not a sandbox: an allowed command runs as your user. Run pal in a container if you need containment.

Is pal open source?

Not yet. pal ships as the published npm package pal-code, but its source repository is not public at the time of writing. It is licensed under MIT, and the public source release is planned once the project is polished.

How stable is this?

pal is MIT licensed and pre-1.0 at version 0.0.14. The extension interface and some internal APIs may still change between minor versions. The agent loop, tool executor, and event protocol are the parts most worth depending on.