Agents that remember beat agents that re-learn.
Plan-first REPL, persistent memory, checkpoints, result refs. ~130kB, zero deps, any model.
$npx @elementics/ag
ag is a tool-calling loop with bash, built as a persistent AI coding agent. Started as 60 lines of code, grew to ~9500 lines as persistent memory, guardrails, permissions, plans, skills, checkpoints, result caching, interaction modes, and a full REPL earned their place.
It remembers context across sessions with a 3-tier memory system — global preferences, project architecture decisions, and timestamped plans. All stored as plain markdown files you can read and edit directly.
Works with any model via OpenRouter, or point it at a local LLM. No lock-in, no abstractions, no dependencies beyond Node.js.
Press Tab while the agent is working to open a steer> prompt. Type a new direction, press Enter. The agent sees your message on the next turn and adjusts — current tool calls finish uninterrupted.
Tab opens the steer prompt and pauses output. Enter submits and resumes. Escape aborts the current run.
Steer messages are queued and injected before the next LLM call. You can steer multiple times — each message is delivered in order.
Every coding agent on the market treats a session as disposable. You open a terminal, load context, do work, close the terminal, and everything the agent learned evaporates. Next session starts from scratch. It's session zero, every time.
ag's memory, checkpoints, result refs, and turn summaries aren't four separate features bolted together. They're one coherent system for persisting reasoning over time. Memory preserves decisions across sessions. Checkpoints snapshot conversation and file state at every turn, so you can rewind without fear. Result refs cache large tool outputs to disk and replace them with summaries, keeping your context window clean without losing information. Turn summaries compress history into structured state—goals, outcomes, file paths, errors—so the agent remembers what it did, not just what it said.
Together they mean the agent accumulates competence on your project. Session two is better than session one. Session twenty knows your architecture, your test patterns, your past mistakes. This isn't chat history you scroll through. It's state that compounds.
ag isn't a smaller Claude Code or a bigger pi. It's a different bet about what coding agents are for.
.mjs file in ~/.ag/tools/ or call agent.addTool() from an extension.plan mode so you can review the approach first. Press Shift+Tab to switch to auto and carry the work through. Plans stay as plain markdown./checkpoint lists newest first; /rewind shows a change preview before rollback.result(action=get).history.jsonl. Search or browse past turns with history(action=search) and history(action=recent). Session state is restored on restart.contextLength for local models.web(fetch|search), are auto-approved.$npx @elementics/ag
$npm i -g @elementics/ag
Prompts for your OpenRouter API key on first use. REPL starts in plan mode; press Shift+Tab to switch to auto.
The core is a tool-calling loop in agent.ts. It sends messages to any OpenAI-compatible API, executes tool calls, and repeats. Sub-agents spawn parallel workers. Extensions hook into 12 lifecycle events. Steering lets you course-correct mid-execution. Checkpoints snapshot files and conversation at every turn. A per-turn ledger tracks edits, reads, verification, and guard stops. Memory is injected into every system prompt. Context auto-compacts at 90%.
Every tool is a single file with a type definition and an execute function. Custom tools and skills are scanned by guardrails before loading. Permissions use glob-based patterns across three scopes. Dangerous bash commands are blocked before they run.
Drop a .mjs file in ~/.ag/tools/ for global tools or .ag/tools/ for project-local tools. Export a tool object with a name, description, parameters, and an execute function.
Add a permissionKey to wire your tool into the permission system. The qualifier maps a tool argument to permission patterns — so deploy(staging) and deploy(production) can have separate rules.
Guardrails automatically scan every custom tool for injection patterns, exfiltration attempts, and hidden content before it loads.
Extensions are TypeScript files that hook into the agent's lifecycle. Place them in .ag/extensions/ (project) or ~/.ag/extensions/ (global). They're loaded at startup and can intercept, modify, or extend any behavior.
Each extension exports a default function that receives the agent instance. Use agent.on() to subscribe to events and agent.log() for spinner-safe output. Handlers run sequentially — each sees mutations from the previous one.
Extensions can block tool calls, inject context into every LLM request, customize compaction behavior, add tools at runtime, and programmatically steer the agent.
The agent object passed to your extension exposes these methods:
event.block = true), rewrite the system prompt via before_request, provide a custom compaction summary, or add tools dynamically with addTool(). Check agent.isSilent() to skip output when running inside a sub-agent.
rm -rf /, fork bombs, and pipe-to-shell patterns are always blocked regardless of permissions.
~/.ag/. Nothing is sent to elementics.ag -b http://localhost:11434/v1 -m gemma4 for Ollama — no API key needed. Set it permanently with /config set baseURL ... and /config set contextLength 131072 for context tracking./permissions deny bash(rm:*) blocks all rm commands. When prompted, press d to deny for the session or D to save a deny rule permanently. See the full permissions docs.ag -y "run tests and fix failures" auto-approves all tool calls. Combine with -m to choose a model and -n to limit iterations..ag/ directory to version control. Project memory, plans, skills, custom tools, and permissions are all plain files that version-control normally./content add photo.png attaches it to your next message. /content paste grabs from clipboard, /content screenshot captures a screen region. Supports PNG, JPEG, GIF, WebP, and PDF./rewind restores any checkpoint. Checkpoints are created automatically at every turn, so you can always go back. Choose to restore code, conversation, or both./skill search frontend to browse the registry, /skill add <name> to install. Or drop a SKILL.md in .ag/skills/ for project-local skills. See the skills docs.