# 🦬 yk
An AI coding agent for the terminal built in Rust, and _**stupid simple™️**_ by design.
yk is a port of [Pi](https://github.com/earendil-works/pi) under a different constraint: it stops
growing. pi keeps adding surface area, so yk takes the part that works and refuses the rest.
The concept is that sensible, minimal defaults, combined with extensibility via [Luau](https://luau.org/)
results in an extremely powerful tool which conforms to its use case with none of the bloat of other
tools.
## Beta
yk is pre-1.0, it is at version 0.1.0, and it has no users yet. Nothing here has to keep working for
anybody, so the design is expected to change while it is still cheap to change. Concretely, and
without warning:
- Flags, subcommands, and their names can change or go away.
- The session file format can change. A session written by one build may not load in the next.
- Tool names and their argument schemas can change.
- The Lua extension API can change, including `register_tool` and the `host` table.
There is no deprecation period, because there is nobody to deprecate for. A prompt is a flag
for exactly this reason, and `yk show me what this does` being a runnable prompt instead of a
usage error is what that buys. Expect the pattern: pick the shape that is right, then break the old
one.
What the label does not cover is quality. The gate, the panic lints, and the docs are
unchanged: a break costs a note in the README, not a migration path.
## Install
```sh
cargo install yk
```
From a clone, `mise run install` builds and installs with `--locked` instead.
## Try it
yk talks to any OpenAI-shaped endpoint. The defaults point at OpenRouter with Claude Sonnet 4, so a
key from there is the shortest path to a first run.
```sh
yk auth # paste a key for the default provider; not echoed
mise run yk -- -p "read Cargo.toml and tell me what this project is"
```
A provider is a named record in `~/.config/yk/providers.toml`, which is readable and
editable: a name, an endpoint, a model, and any headers the endpoint needs. Its key goes in
`~/.config/yk/credentials.toml`, readable only by you, keyed by that name.
```sh
yk auth --base-url https://opencode.ai/zen/go/v1 --model deepseek-v4-pro
```
An endpoint that refuses a request without a header yk does not otherwise send gets it from
the record, which `yk auth` does not write and you can add by hand:
```toml
[[provider]]
name = "opencode-go"
base_url = "https://opencode.ai/zen/go/v1"
model = "deepseek-v4.1-flash"
headers = { "x-opencode-session" = "yk-4f6c1a2e" }
```
OpenCode Go is the endpoint that needs one: it answers 400 `MissingSessionID` without
`x-opencode-session`, and asks for a value that stays the same for a conversation. yk sends
the value the file repeats rather than inventing one per run, so a conversation keeps its
identity across `--continue`.
`YK_PROVIDER` picks which record to use, and without it the first one is used. `YK_BASE_URL`,
`YK_MODEL` and `YK_API_KEY` still win over all of it, so CI and scripts are unchanged. A
project's `.yk/config.toml` can change how yk looks and nothing else: an endpoint or a
credential in one is an error naming the file, because a repository should not be able to
redirect a session.
Settings that should persist live in `~/.config/yk/config.toml`, and `yk config
set theme kanagawa` writes one. A project can pin a theme for everyone working
in it with a `.yk/config.toml`, and one in every parent directory applies too,
with the closest winning. `YK_THEME` still wins over all of it. A project file may
only set how yk looks: an endpoint or a trust flag in one is an error naming the
file, because a repository should not be able to redirect a session.
Or without mise, once you have a release binary on your `PATH`:
```sh
yk -p "read Cargo.toml and tell me what this project is"
```
A prompt may also arrive on stdin, so `cat file | yk` works. `yk --help` prints every flag,
subcommand, and environment variable.
## What it can do
Six built-in tools, and it takes a prompt on `-p`:
| `read` | Reads a file verbatim, and pages past the first screenful |
| `write` | Creates or overwrites a file |
| `edit` | Replaces exact strings, and refuses an ambiguous one |
| `bash` | Runs a command and reports its exit code |
| `glob` | Finds files whose path matches a pattern like `**/*.rs` |
| `grep` | Finds lines containing a literal string |
`read`, `write`, and `edit` resolve paths inside the working directory and refuse absolute paths,
any `..` that climbs out, and any path a symlink carries outside it. Every tool refuses arguments it
does not recognise and quotes the tool's own schema back to the model, so a hallucinated parameter
produces a correction rather than a silent change of meaning.
The model is told where it is and what the project expects. yk reads `AGENTS.md` from the working
directory and every directory above it, and sends that, plus a short base prompt, as the system
message. Nothing is cached, so editing `AGENTS.md` changes the next prompt rather than the next
session.
Sessions are append-only JSONL, one per run. A launch starts a new conversation;
`yk --continue` resumes this project's most recent one, and `yk --session NAME`
names one explicitly. They live under `~/.yk/sessions/<project>/`, so two projects
never share a `--continue`. You can go back:
```sh
yk show # list the active branch
yk rewind 3 # move the head back three entries
yk fork experiment # copy the session so you can diverge
yk compact # summarize the branch and shadow what came before
```
A session that grows past `YK_CONTEXT_WINDOW` is compacted automatically before
the next request, so a long conversation keeps working instead of failing at the
model.
### Terminal interface
`yk tui` draws the session in a terminal and takes prompts from the keyboard.
```sh
yk tui # open the session in the terminal
YK_THEME=kanagawa yk tui # ...in one of the shipped themes, over any config file
```
The themes are `dark` and `light`, plus `kanagawa`, `catppuccin`,
`catppuccin-latte`, `gruvbox`, `tokyonight`, `github`, `dracula`, `nord`, and
`one-dark`. Each is a small override over the dark or light palette, so a theme
sets the colors the interface uses and inherits the rest.
A prompt that starts with a slash is a command: `/new`, `/compact`, `/clear`,
`/session <name>`, `/model <name>`, `/theme <name>`, `/help`, and `/quit`. Typing a slash lists what
matches above the prompt, the arrow keys move, and Tab completes. `/session`, `/model`, and
`/theme` with no argument open a picker instead, where typing narrows the list and
Enter applies it. `/model` switches the client a turn runs against and records the
choice in the session, so a resumed conversation comes back on the model it left off on.
Nothing is drawn against the left or right edge of the terminal; there is one
column of margin on each side.
The transcript scrolls with `PageUp` and `PageDown`, `Alt+Up` and `Alt+Down`, or the wheel. The
answer streams in as the model writes it, and Enter sends what is in the prompt box. Up and Down in
the box walk the prompts already sent. Enter while a turn is running queues that message for the
next request instead of waiting for the turn to end, so you can correct course mid-answer. Ctrl+C
cancels the turn, or quits when nothing is running.
### Extensions
You can write your own tools in Lua. They run in an embedded Luau VM where `io`, `package`, and
`os` do not exist, so the filesystem is reachable only through the functions an extension is handed:
```lua
register_tool("count_lines", "Count the lines in a file.", {
type = "object",
properties = { path = { type = "string" } },
required = { "path" },
}, function(args)
return host.read_file(args.path):gsub("\n", ""):len() + 1
end)
```
| `read_file` | Reads a file, confined to the working directory |
| `http_get` | Fetches a URL as text |
| `http_post_json` | Posts JSON with headers you choose, returns status and body |
| `env` | Reads one environment variable by name, or nil |
| `json` | Decodes JSON into a table |
| `json_encode` | Encodes a table as JSON |
| `register_tool` | Declares a tool for the model |
The six `host` members are capabilities the built-in tools already have; `register_tool` is the
global an extension declares a tool with. `http_post_json` and `env` exist
because `http_get` alone cannot reach any hosted API: they authenticate with a request header and
answer on POST, and without reading a key there is nowhere to put the token. `json_encode` is the
mirror of `json`, because a request body has to be written in something.
An extension that needs another binary asks the host to run it: `runner.spawn_tool(command, args)`
returns `{code, stdout, stderr}` and runs the child as a separate OS process. There is no FFI and no
native module loading, so an extension is still plain Lua you can read, plus a list of processes it
asked the host to run.
Drop it in `.yk/extensions/` and it loads for this session. Anything the model writes there stays
session-scoped until you type `yk promote NAME`, which copies it to `~/.config/yk/lua/` where it
loads for every run. That path is under `XDG_CONFIG_HOME`, or `~/.config` if you have not set it,
because a promoted extension is configuration you wrote rather than project data.
The model can run `yk promote` too, through `bash`. That is deliberate rather than an oversight, and
it is the shape of the guarantee: anything permanent is plain Lua in a directory yk can show you.
An extension is trusted code with your own permissions, and it reaches anything `bash` reaches. What
contains it is the run: an instruction limit that kills a runaway loop, a ten second deadline as a
backstop for long native calls, a 64MB heap cap, and bytecode refused at load. If you
want a restriction the built-in tools do not provide, write an extension that adds it, and use
`on_tool_call` to refuse the calls you do not want:
```lua
on_tool_call(function(name)
if name == "bash" then return "block: this repo is read-only" end
end)
```
Extensions are Lua. They reach the system through the `host` functions and the `runner` process
gateway, never through in-process native code. `bash` is the agent's tool, not part of the extension
surface.
### A worked example
`docs/examples/decision-gate.lua` is a gate that asks a **decision model** whether a tool call should
proceed. A decision model is not a small language model: it takes a bounded state and a few typed
questions and returns calibrated probabilities, in tens of milliseconds, without generating a token.
**It is an example, not a supported extension.** yk does not load it, does not install it, and makes
no compatibility promise for it. It lives under `docs/` because it is documentation: it shows what the
`host` members above make possible. Read the banner at the top of the file before copying it
anywhere.
It names no vendor, because it does not have to. TypeSafe published `POST /v1/systemone` for Jev,
and Kev, Laya, Ollama, and Cloudflare's Clef all accept the same body, so a config block picks the
endpoint and an adapter picks where the answer sits in the reply. Ollama runs the same thing locally
with no API key:
```sh
ollama pull nimble
```
Copy the file to `~/.config/yk/lua/` and edit the config block at the top. It ships in **shadow mode**:
it asks, prints one JSON verdict per call to stdout, and blocks nothing.
```json
{"event":"allowed","question":"privilege","score":0.03,"tool":"bash"}
{"event":"would_block","question":"destructive","score":0.97,"tool":"bash"}
```
Read that log, then set `threshold` from it and change `mode` to `"enforce"`. Do not take the
threshold from a blog post: published calibration figures are measured on somebody else's data, and
the one thing every integration agrees on is that you re-measure it on your own.
Two things to know before you turn it on. It **fails open**: a dead endpoint, a 401, a 429, or a
reply in an unexpected shape all mean the gate has no opinion, and the call proceeds. A gate that
blocked on those would freeze every session the first time the vendor rate-limited you. And it is
not free: it costs a round trip per distinct watched call, so it is a safety tool rather than a speed
one. `docs/extensions.md` has the reasoning, including the case for why the speed argument does not
apply to yk's loop at all.
### Editors
`yk acp` serves the [Agent Client Protocol](https://agentclientprotocol.com) on stdio, which is how
Zed, JetBrains, and Paseo drive an agent.
```sh
yk acp # speak ACP on stdio until the client disconnects
```
The prompt arrives over the protocol, tokens come back as they arrive, every tool call is shown and
offered to the client for approval, and `session/load` reopens the JSONL sessions above. The model
picker lists whatever `GET {YK_BASE_URL}/models` returns, so it cannot drift from what your key can
actually reach; an endpoint with no such route just shows the configured model.
Two things are worth knowing. Only allow-once and reject-once are offered, because yk has no memory
between calls and a client that wants to remember can remember on its own side. And `session/cancel`
stops a turn between tool calls rather than mid-answer, because the provider stream is not
interruptible yet.
## What it will not do yet
- **No syntax highlighting, one session per process.** The transcript is the
conversation.
- **One provider shape.** The URL is configurable, the wire format is not.
- **No MCP.** yk serves no MCP server, so a client that injects one has nothing to inject.
- **No telemetry, no crash logs, no session export.**
## Working on yk
mise owns the toolchain. It pins Rust, dprint, bacon, graphite, and hk, so there is one place that
says what runs.
```sh
./setup.sh # first time only. Installs mise if needed, then everything else
mise run check # clippy with warnings denied, tests, and formatting
mise run bacon # watch loop while you work
```
`./setup.sh` installs the pinned toolchain, fetches the crates, and points git at the committed
pre-commit hook. That last step cannot be committed, because `core.hooksPath` lives in
`.git/config`, so it has to run once per clone. After it, a commit that breaks the gate does not
land.
`cargo:bacon` compiles from source, so the first run takes about 2.5 minutes. `mise run setup`
does the same three steps if mise is already installed.
Two rules shape the code more than anything else. `yk-core` holds the agent loop and depends on
nothing, so a crate that teaches it HTTP or a terminal has leaked. And no panic path is reachable:
clippy denies `unwrap`, `expect`, indexing, unchecked arithmetic, `as` casts, and explicit exits,
workspace-wide, plus every warning on top of that. For an agent that runs shell commands on
someone's machine, "usually right" is not the bar.
A third-party crate is a question about who maintains the code, not a quota. A dependency is allowed
when owning the code would cost more than the dependency does, and the review is where that is
answered.
[`AGENTS.md`](AGENTS.md) has the full working rules, [`docs/architecture.md`](docs/architecture.md)
has the system, [`docs/extensions.md`](docs/extensions.md) and [`docs/tui.md`](docs/tui.md) the two
interfaces, [`docs/design.md`](docs/design.md) the rules and the refusals, and
[`docs/plan.md`](docs/plan.md) the phase plan.