Skip to content

Lich documentation ​

What you'll learn: what Lich is, what it ships, and which page to read next — plus a 60-second quickstart.

Lich is a TypeScript AI agent harness: a library and a CLI that run a chat model inside a Think-Act-Observe loop. A chat wrapper forwards one prompt and prints one completion. A harness keeps going: the model plans (think), calls tools such as read_file or terminal (act), reads the tool results (observe), and repeats until it can produce a final answer. Lich wraps that loop with the machinery real deployments need: provider failover with bounded retries, path confinement and output clamps on every tool, context compression when the transcript grows past a token budget, and append-only JSONL session transcripts.

One package, four ways to drive the same agent: a one-shot CLI, an interactive chat REPL, an ink-based terminal UI, and a long-running messaging gateway that bridges Telegram, Discord, Twitch, and a zero-config HTTP webhook. All four share the same builtin tools, the same provider configuration, and the same session store. lich init, lich config, lich update, and lich mcp do not start that loop.

Feature overview ​

CapabilityWhat it gives you
Providersopenai_compat, anthropic, and ollama with automatic failover between configured providers; 429/5xx and network errors retry with backoff before failing over.
ToolsBuiltins (file read/write/edit, directory listing, shell, grep, HTTP fetch/request, web search, process list, disk usage, env inspection, run_tests), all confined to the working directory. git_commit is the gatekeeper's tool, not a config plugin.
Context compressionTranscript summarized in place when estimated tokens cross compress_threshold of context_budget_tokens; the 8 most recent turns always stay verbatim.
SessionsEvery run persists a .jsonl transcript under .lich/sessions/, labeled by origin (tui, gw:<platform>:<chat>).
CLIOne-shot tasks, chat REPL, TUI, gateway, init, update, config, and (in this source) lich mcp. Flag, env, and config-file configuration.
TUILive ink transcript with tool-call rows, status bar (model, turns, tokens, session path), and slash commands.
GatewayOne shared agent behind webhook/Telegram/Discord/Twitch with per-conversation memory (40-message history cap) and per-platform message splitting.
Librarycreate_agent / run_agent with typed events (AgentEmitter), multi-turn history, and ProviderError kinds for error handling.
PluginsUser-supplied tools and lifecycle hooks (before_tool_call veto, run lifecycle) loaded at startup from explicit module paths.

Page map ​

PageRead it to
Getting startedInstall, configure a provider, and get your first reply in any mode.
CLI referenceModes, flags, provider resolution, config files, and lich mcp.
TUI guideRun the terminal UI and use slash commands and the status bar.
Ossuary guideOpen the Electron desktop shell from a clone and chat via serve.
Gateway guideWire Telegram, Discord, Twitch, and the HTTP webhook to one agent.
Library guideEmbed the agent in TypeScript with events and multi-turn history.
Plugins guideAdd your own tools and lifecycle hooks, and run the self-improvement loop.
Godot guideRun lich beside a Godot game and drain .lich/game/ orders each tick.
Redot guideAdd editor MCP servers (Redot catalog entry). Play still uses the game bridge, the opposite direction.
Games guideReplay session JSONL as a combat log, including token totals.
Architecture overviewUnderstand how the harness works inside.

How it works ​

For the internals — the agent loop, provider failover, tool guardrails, and how to extend each layer — read the architecture track: overview, agent loop, providers, tools, plugins, serve, and extending.

60-second quickstart ​

Requires Node >= 20 (or Bun) and access to one model endpoint (local Ollama, OpenAI, Anthropic, or any OpenAI-compatible API such as OpenRouter).

sh
# install the CLI globally
npm install -g @moikapy/lich

# generate a starter config, then edit the model name
mkdir -p .lich && lich config > .lich/config.json

# chat TUI (exit with /exit or Ctrl+C)
lich tui

# or a one-shot task
lich "list the files in this repo and summarize it"

# or a messaging gateway on http://localhost:8089
lich gateway webhook

Working from a clone of the repository? bun install, then run the same commands as bun src/cli.ts ... — see getting started.

Version compatibility ​

The published npm package is 0.8.0. lich --version reads package.json. Editor MCP (mcp_servers, lich mcp) has shipped since 0.7.0. Node >= 20 (engines in package.json); Bun is the recommended runtime for development from a clone (bun src/cli.ts ...). The TUI needs a TTY; the gateway and library run headless on both runtimes.

Released under the MIT License.