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.
pal-code on npm
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.
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.
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.
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.
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.
Everything below ships in the 0.0.x line - no roadmap required.
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.
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.
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.
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.
Same provider first, then others. Quota exhaustion switches immediately; rate limits back off and retry. A turn survives a flaky model instead of dying.
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.
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.
fetch_url and web_search as an extension - DuckDuckGo, SearXNG, Tavily, or Brave.
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.
SQLite-backed history you can list and resume, context compaction with LLM-backed summaries, and pre-edit file snapshots with /undo.
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.
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.
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 │
└─────────┘ └──────────────┘ └─────────────┘ └─────────────┘
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.
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.
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.
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.
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.
onTurnStart, onTurnEnd, onToolCall, onError - to observe turns, tool calls, and failures without wrapping core../<name>.json and ~/.pal/<name>.json, so pal's config stays clean.
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.
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;
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.
/copy yanks the last reply or code block over SSH via OSC 52./effort low|medium|high to steer reasoning per turn.There are many capable coding agents. pal is built for a specific set of priorities:
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.
Bring your own key to any OpenAI-compatible endpoint, and route different agents to different models and effort levels with token budgets.
An 18k-line TypeScript codebase with a stated architecture, 366 tests, and an eval harness. Inspectable by design, not a black box.
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.
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
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.
No account, no hosted service, no telemetry. Set a provider key on first run and pal talks directly to the model API you chose.
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.
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.
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.
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.
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.
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.
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.
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.
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.