# sakuracode [English](README.md) · [简体中文](README.zh-CN.md) **sakuracode is an open-source terminal coding agent (a command-line AI coding assistant).** It reads and edits your code, runs shell commands and tests, and works toward a goal on its own, using any model endpoint that speaks Chat Completions (you choose it in a config file; OpenAI, Anthropic and DeepSeek are built in). Every tool call is checked by an automatic review before it runs. It is built on the [Sakura agent framework](../README.md) (npm package `sakura-agent`) and is similar in use to OpenAI Codex CLI and Claude Code. ```bash npm install -g sakuracode export MY_API_KEY=... # the key of the endpoint you set up in ~/.sakura/config.toml (see below) sakuracode "explain this repository" ``` * Interactive inline session: your terminal's scrollback is kept, the prompt and the status line stay on the last rows of the window. A big paste is shown as `[Pasted Content N chars]` and sent in full. * Replies are rendered as **Markdown** (headings, lists, tables, fenced code, links). `exec` writes Markdown too. * Slash commands, `!shell`, `@file` mentions, resume, fork, undo, `/compact`, long-running goals (`/goal`), MCP servers, image input. * Steer, queue or cancel while the agent works. * `exec` mode for scripts and CI, with a `--json` event stream; config file with profiles. * Automatic review of every tool call (hard rules, then a reviewer model); every decision is recorded in the session file. * Long sessions: the conversation is compacted when the context fills, and sessions can be resumed later. * Not tied to a provider: any Chat Completions endpoint works by adding a model record to the config file; OpenAI, Anthropic and DeepSeek are built in. ## Defaults | | | |---|---| | Working directory | The agent starts in the directory where you launched the command and **may go anywhere**. Nothing is restricted to the directory and no outside-directory rule is enabled. (`-C DIR` only changes where it starts.) | | Review | **On.** The default uses hard rules and a reviewer model. Select `manual` to approve or reject each tool call yourself. | | Redaction | **Off.** Turn it on with `--redact`, `redaction = true` in the config, or `/redaction on`. It hides secrets from the model provider; the session file on disk keeps the real values. | | Output | Markdown. | | Thinking | **Medium** when the selected compatibility preset supports reasoning; otherwise no effort setting is sent. Use `--thinking off` to request no reasoning on a supported model. | | Idle compaction | **On.** After 5 minutes without activity, compact contexts of at least 20,000 tokens. Activity resets the timer; running work and a nonempty prompt defer it. | | Run time limit | None unless `--time-limit` or `time_limit_seconds` is set. | ### Is it safe to let it run commands? It is **not sandboxed**: the agent runs with your user's permissions and may read and change files anywhere you can, and run any command. What stands between it and your machine is the automatic review (hard rules first, then a reviewer model), which checks writes, command expansions, credential access and catastrophic patterns, refuses what it judges harmful, and records every decision in the session file. A review is a judgement, not a wall: for untrusted work run sakuracode inside a container or virtual machine you provide. The conversation, including the content of files the agent reads, is sent to the model provider you chose (the reviewer is a second request to the same provider unless you configure another); with `--redact`, secrets are replaced by placeholders before a request leaves, while the session file on your disk keeps the real values. ## Install and run Requires Node 22.18 or newer (older versions print an npm warning). For a local checkout, run these commands from the repository root. They build and launch that checkout without replacing a global installation: ```bash npm --prefix code run build node code/dist/code/bin/sakuracode.mjs --version node code/dist/code/bin/sakuracode.mjs --permissions manual ``` The startup banner uses the original `✿ sakuracode` character mark on its first line. ```bash npm install -g sakuracode ``` ### First start: tell it which model to use sakuracode is not tied to one provider. It works with any endpoint that speaks Chat Completions (streaming and tool calls). You describe your endpoint once in `~/.sakura/config.toml`; the API key stays in an environment variable and is never stored by sakuracode. ```bash mkdir -p ~/.sakura cat > ~/.sakura/config.toml <<'EOF' provider = "myprovider" [providers.myprovider] base_url = "https://api.example.com/v1" # your endpoint model = "your-model-name" key_env = "MY_API_KEY" # the environment variable that holds the key context_window = 128000 # the model's context window, in tokens compat = "deepseek" # a compatibility preset: deepseek, deepseek-flash, commandcode-deepseek, moonshot, openai, qwen # headers = { "x-team" = "a" } # extra request headers, if your endpoint wants them # session_header = "x-session-id" # a header that gets the session id, if it wants one EOF export MY_API_KEY=... cd your-project sakuracode "explain this repository" ``` `context_window` matters: the status line and automatic compaction count against it. `sakuracode providers` shows which providers are known and whether their key is set (never the key itself). It creates `~/.sakura/sessions/` on the first start. For convenience, OpenAI, Anthropic and DeepSeek are built in: with only `OPENAI_API_KEY`, `ANTHROPIC_API_KEY` or `DEEPSEEK_API_KEY` set and no config file, sakuracode uses their built-in settings and picks the first one whose key is set. Any other OpenAI-compatible (Chat Completions) endpoint works by adding a model record as above. `--provider NAME` picks a provider for a single run. If something is missing, it says what to do: | Situation | What you see | Exit code | |---|---|---| | No key set for any provider | `no API key found; set one of: ...` | 2 | | The provider you chose has no key | `provider "myprovider" needs the environment variable MY_API_KEY` | 1 | | Interactive command in a pipe or script | `the interactive session needs a terminal; use sakuracode exec for pipes and scripts` | 2 | ### Commands ```bash sakuracode # interactive session sakuracode "fix the failing test" # interactive, the prompt is sent at once sakuracode --provider anthropic # choose the provider sakuracode -i error.png "what does this error mean?" # attach an image sakuracode resume --last # continue the latest session (a picker without --last) sakuracode fork --last # copy the latest session into a new one sakuracode review --base main # review the changes against main, print the review sakuracode exec "summarise this repo" # one run, Markdown on stdout sakuracode exec --json "list the TODOs" | jq . # events as JSON lines echo "explain this error" | sakuracode exec - # prompt from stdin sakuracode sessions # list sessions sakuracode providers # providers and whether their key is set (never the key) sakuracode acp # serve the Agent Client Protocol on stdin/stdout (see below) ``` ### Options | Option | Meaning | |---|---| | `--provider NAME` | `deepseek`, `openai`, `anthropic`, or a provider from the config file | | `-p, --profile NAME` | settings profile from the config file | | `-m, --model NAME` | model of the provider | | `--permissions NAME` | `auto` (default), `read-only`, `strict`, `manual`, `full-access` | | `-i, --image FILE[,FILE]` | attach images to the first prompt (png, jpg, gif, webp, bmp); `@pic.png` in a prompt or a dropped file path does the same | | `--redact` / `--no-redact` | redaction on / off (default off) | | `--thinking LEVEL` | `off`, `low`, `medium`, `high`. DeepSeek also offers `xhigh` and `max`. A level the model does not offer becomes the nearest one above it, or its highest. | | `--max-tokens N` | output limit per model request | | `-C, --cwd DIR` | directory to start in (with `--ssh`/`--docker`: the absolute path on the other side) | | `--ssh HOST` | run the tools on another machine over ssh (a name from `~/.ssh/config` or `user@host`); the agent and the session stay here | | `--docker CONTAINER` | run the tools in a running container (`docker exec`) | | `--time-limit SECONDS` | how long one run may take: the agent sees the time left and is asked to finish near the end (also `time_limit_seconds` in the config) | | `--resume REF` | continue a session (id, id prefix, `last`) | | `--json` | `exec`: events as JSON lines (first line `session`, last line `result`) | | `--raw` | `exec`: write the Markdown as it is even on a terminal | | `-q, --quiet` | `exec`: no progress lines on stderr (warnings and errors are still shown) | | `--output-last-message FILE` | `exec`: also write the final reply to FILE | | `--no-color` | no colours | `exec` exit codes: 0 done, 1 error, 2 usage error or paused by the review breaker, 3 the time limit (`--time-limit`) was reached, 130 cancelled. In `exec`, progress goes to stderr (one line per tool call) and the final reply goes to stdout; on a terminal it is rendered, in a pipe it is the raw Markdown. ## In the session | Key | While idle | While the agent works | |---|---|---| | Enter | send | **steer**: delivered before the agent's next model request | | Tab | complete a slash command | **queue**: handled when the agent would stop | | Shift-Tab | cycle auto, strict and read-only. Select manual or full-access with `/permissions`. | applied when the run ends | | Esc | close the popup | **cancel** the run | | Ctrl-C | clear the prompt; twice on an empty prompt leaves | cancel the run | | Ctrl-D | leave (empty prompt) | | | Shift-Enter, Alt-Enter, Ctrl-J, or `\` then Enter | new line in the prompt | | | Up / Down | history, or move between lines | | | Ctrl-A/E/K/U/W/Y, Alt-arrows | readline-style editing | | Messages typed during a run show above the prompt as "steering" or "queued" until the agent takes them. Foreground shell commands show a bounded output preview while they run. The final tool result supplies the exit status and final output. ACP supports the same preview; custom execution environments can still return only final output. Model IDs can contain slashes. Both `/model commandcode deepseek/deepseek-v4.1-flash` and `/model commandcode/deepseek/deepseek-v4.1-flash` preserve the full model ID when `commandcode` is configured. ### Slash commands | Command | | |---|---| | `/help` | list the commands | | `/status` | session, directory, model, permissions, context left, input (cached and new), cache hit rate, output | | `/model [provider[/model]]` | show or switch provider and model (the agent is closed and recreated on the same session file) | | `/thinking [level]` | show the current effort and open an arrow-key picker; a level changes it within the same conversation | | `/permissions [auto\|read-only\|strict\|manual\|full-access]` | show or change what is reviewed | | `/redaction [on\|off]` | hide secrets from the model | | `/rename ` | give the session a name | | `/compact` | summarise the conversation to free context | | `/new`, `/clear` | start a new session (`/clear` also clears the screen) | | `/resume [id\|last]` | continue an earlier session (a picker without argument) | | `/fork` | copy this session into a new one and continue there | | `/undo` | go back to before your last message and put it back in the prompt (Esc twice on an empty prompt does the same) | | `/init` | have the agent write an `AGENTS.md` | | `/review [focus]` | have the agent review the uncommitted changes | | `/diff` | show `git diff` | | `/goal [objective\|clear]` | show the goal; with text, set it and start working on it; `clear` ends it | | `/loop [interval prompt]` | run a prompt again and again while the session is open (`/loop 10m check the build`); alone it lists the jobs; `/loop stop\|pause\|resume [id]` | | `/in ` | run a prompt once, later (`/in 20m look at the deploy`) | | `/mcp` | show MCP servers | | `/exit`, `/quit` | leave | `!command` runs a shell command yourself and shows the output (the agent does not see it). `@path` in a prompt names an existing file or directory to the agent. ### Permission presets | Preset | | |---|---| | `auto` (default) | review on | | `read-only` | review on, and the agent only gets the `read` tool | | `strict` | review on; three refusals in a row pause the run | | `manual` | wait for your approval on each tool call | | `full-access` | review off | None of them restricts the working directory: the review plugin runs with `directoryRules: false`, so a path outside the launch directory is not a reason to refuse. In the automatic review presets, the hard rules and the reviewer model check writes, command expansions, credentials and destructive commands. ### Scheduled prompts `/loop 10m ` and `/in 20m ` start a turn by themselves later, as if you had typed the prompt; the agent can also ask to be woken (the `schedule_wakeup` tool: 1 to 60 minutes, one pending at a time). Times are `30s`, `5m`, `every 2h`, `in 1d`. A job fires only when the session is idle and you are not typing, once (never a burst to catch up), with the permission mode the session already has. `⏰ 2` in the status line counts the active jobs; `/status` shows the next one. Jobs are saved in the session: `/resume` brings them back, and a time that passed while the program was closed fires once. They live only while the session is open; there is no background service. A job ends after 3 failed turns, on a quota or rate-limit stop, after 200 runs or after 30 days, and a session holds at most 10. Settings are in the `[schedule]` table (see Config). For work with no session open, use the system scheduler with `exec`, for example this crontab line (every day at 9, the reply goes to a file): ```cron 0 9 * * * cd ~/project && sakuracode exec -q --output-last-message ~/daily.md "check for new failing tests and summarise them" ``` ## Use with T3 Code and other ACP clients `sakuracode acp` speaks the [Agent Client Protocol](https://agentclientprotocol.com) (ACP, version 1) on stdin and stdout, so an ACP client can run it as its coding agent. Stdout carries only protocol messages; logs go to stderr (`SAKURACODE_ACP_LOG=off|error|warn|info|debug`, default `warn`). **T3 Code:** Settings, Providers, Add provider, Show more, **Local ACP command**. Fill in the form like this. Use **absolute paths** everywhere: T3 Code starts the command from its own working directory, so a relative path fails, and a desktop app often has a shorter `PATH` than your shell. Find the paths in a terminal with `which node` and `which sakuracode` (or `npm root -g`). | Field | Value | |---|---| | Name | `Sakura Code` (any name) | | Executable | the absolute path of `node`, for example `/opt/homebrew/bin/node` | | Arguments | one row each: `--disable-warning=ExperimentalWarning`, then the absolute path of `sakuracode.mjs` (for a global install: `/sakuracode/dist/code/bin/sakuracode.mjs`; in a checkout: `/code/bin/sakuracode.mjs`), then `acp` | | Environment | the key of your provider, for example `DEEPSEEK_API_KEY`, `OPENAI_API_KEY` or `ANTHROPIC_API_KEY` (a desktop app does not see the variables of your shell) | If your `PATH` is complete in the app, the executable can be the absolute path of the `sakuracode` command (`which sakuracode`) with the single argument `acp`. Then start a chat with that provider. To check it by hand, run `sakuracode acp` and paste `{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":1,"clientCapabilities":{}}}` followed by Enter: one JSON line comes back. The model picker lists every configured and built-in provider. Pick a provider to switch within the same conversation. Models with a reasoning effort have a thinking selector. The review selector offers `auto`, `read-only`, `strict` and `manual`. To expose `full-access`, start ACP with `--permissions full-access`. To approve calls in the terminal, start with `--permissions manual` or enter `/permissions manual`. The terminal shows the tool arguments. Use Up/Down or Tab to select Allow once or Reject, then Enter to confirm. Esc or Ctrl-C cancels the turn. Typed letters and pasted text cannot approve a call. ACP also supports native session discovery and resume. In T3, set **Review mode** in the model menu to **Manual** to make Sakura send approval requests. Set **Permissions** below the prompt to **Supervised** to make T3 display them. ACP clients can find saved chats with `session/list`, replay them with `session/load`, or continue them without replay with `session/resume`. The DeepSeek selector offers Off, Low, Medium, High, Extra high, and Max. The selected level is restored with the session. What works now: chat with streamed replies and reasoning, cancelling a running turn, several chats at once (one prompt at a time in each). New chats use the review mode `auto` (every call is reviewed); `--permissions strict` or `read-only` after `acp` changes it, and `full-access` only runs when you ask for it on that command line. Tool calls show as cards (reads, edits with diffs, commands with output), the context meter follows each reply, and an idle chat is compacted in the background after the cache lifetime (the same `auto_compact_*` and `cache_ttl_minutes` settings as the terminal), and `/compact`, `/status` and `/goal` work in the chat, and so do `/loop` and `/in` (scheduled prompts, experimental here: a fired job streams its turn to the client without a prompt request, and a client may not show it; it is in the conversation either way and appears when the chat is opened again) (`/goal ` sets a goal and works on it until a check says it is reached; `/goal` shows it, `/goal clear` ends it). You can attach images and files, open an earlier chat again (it is replayed), and the MCP servers your client lists (stdio) are started with the chat. See `docs/acp-design.md`. Published 0.5.5 has known ACP defects: the configured run limit is not applied, saved thinking overrides explicit startup thinking on resume, and idle compaction can use a stale measurement after a rebuild. Version 0.5.6 fixes these issues and the generic wrapped-tool title. T3 icon and timeline-fold policies belong to T3 and are not changed by installing Sakura. ## Config ACP sends provider retry notices and tool-image previews. Reopened sessions use the saved image bytes. A result can show up to four previews, at most 2 MB each and 3 MB combined; unavailable or larger images get an omission notice. Clients choose how to display these protocol values. `~/.sakura/config.toml` (set `SAKURA_HOME` to use another directory; sessions are stored in `sessions/` beside it). Precedence: defaults < file < profile < environment (`SAKURA_PROVIDER`, `SAKURA_MODEL`) < flags. Settings are read at startup. Restart to apply file changes. `/status` shows the effective model, thinking, review, redaction, compaction, run time limit and output limit. `/thinking`, `/model`, `/permissions` and `/redaction` apply within the open conversation. They do not edit the config file. Thinking defaults to medium on a supported preset. On resume, an explicit startup thinking value (file, profile or flag) overrides the saved session value; otherwise the saved value is restored for the same provider/model. A different model uses its supported default if the previous effort is unavailable. A level the model does not offer becomes the nearest one above it, or the model's highest (Max on a model up to High is High); the status line shows the level in use. With `compat = "qwen"` (Qwen through Model Studio's OpenAI-compatible mode) Off sends `enable_thinking: false`, Low and Medium send a thinking budget of 4,096 and 16,384 tokens, and High leaves the budget to the model. ```toml provider = "deepseek" permissions = "auto" redaction = false thinking = "medium" max_tokens = 32000 # idle auto-compaction: after cache_ttl_minutes without activity, a context of at least # auto_compact_min_tokens (never below 1000) is compacted; a profile may set these too cache_ttl_minutes = 5 auto_compact_min_tokens = 20000 auto_compact_idle = true # time_limit_seconds = 1800 # how long one run may take; the agent sees the time left in every request and is asked to finish at 80% [schedule] # scheduled prompts (/loop, /in and the agent's schedule_wakeup tool) enabled = true min_interval_minutes = 1 max_jobs = 10 # per session max_runs = 200 # per job; also the self wake-ups of a session expire_days = 30 wakeup_tool = true # the agent may wake itself jitter_percent = 0 # a recurring job may fire up to this share of its period late [profiles.cheap] provider = "deepseek" thinking = "low" [providers.lab] # any Chat Completions endpoint base_url = "https://example.com/v1" model = "some-model" key_env = "LAB_API_KEY" context_window = 128000 compat = "deepseek" # a framework compat preset: deepseek, deepseek-flash, commandcode-deepseek, moonshot, openai, qwen headers = { "x-team" = "a" } session_header = "x-session-id" # header that gets the session id, if the endpoint wants one [mcp.servers.files] command = "npx" args = ["-y", "some-mcp-server"] ``` ### Providers | Name | Endpoint | Model | Key | |---|---|---|---| | `deepseek` | `https://api.deepseek.com` | `deepseek-flash` | `DEEPSEEK_API_KEY` | | `openai` | `https://api.openai.com/v1` | `gpt-5` | `OPENAI_API_KEY` | | `anthropic` | `https://api.anthropic.com/v1/` | `claude-sonnet-5-5` | `ANTHROPIC_API_KEY` | DeepSeek uses the framework's `compatPresets["deepseek-flash"]` (Extra high and Max are offered; Extra high is sent as High). Any other Chat Completions endpoint works by adding a model record with its preset. Without `-p`, the first provider whose key is set is used. Keys are read from the environment and never printed or stored. ## Frequently asked questions **Which models does it work with?** Any endpoint that speaks Chat Completions (streaming and tool calls), set up under `[providers.NAME]` in `~/.sakura/config.toml`. OpenAI, Anthropic and DeepSeek are built in. **Where are my sessions stored, and how do I continue one?** In `~/.sakura/sessions/` (set `SAKURA_HOME` to use another directory), one append-only file per session. `sakuracode resume --last` continues the latest one; `sakuracode sessions` lists them; `/fork` copies one. **What happens when the conversation gets too long?** It is summarised automatically when the context fills (and after a few idle minutes), or when you type `/compact`; the recent part stays word for word. `/status` shows how full the context is and how much of the input came from the provider's cache. **Can I use it in scripts and CI?** Yes: `sakuracode exec "task"` runs one prompt without a screen, writes the reply to stdout and progress to stderr, and exits with 0 (done), 1 (error), 2 (usage error or paused by the review) or 130 (cancelled). `--json` gives the events as JSON lines. **Can I keep it working toward a goal on its own?** Yes: `/goal "make the tests pass"` sets a goal and starts working; the agent is checked against it before it may stop. **How is it different from Codex CLI?** Codex CLI is OpenAI's product with sandbox modes and approval policies. sakuracode is the reference terminal of the open-source Sakura framework: it offers automatic review and manual approvals, works with any Chat Completions endpoint, and is built only on the public SDK, so everything it does you can also do in your own agents with `sakura-agent`. ## Development Run these commands from the repository root: ```bash npm ci npm --prefix code start npm --prefix code test # includes pseudo-terminal tests (needs python3) npm --prefix code run typecheck npm pack ./code # build the release tarball (npm publish ./code publishes it) ``` The suite uses no network. To test a real provider, run `node --disable-warning=ExperimentalWarning code/test/live/interactive.ts PROVIDER WORKDIR [HOME]`. Documents: [docs/design.md](docs/design.md) (modules and interfaces), [docs/test-report.md](docs/test-report.md) (what was run, including failures), [docs/framework-gaps.md](docs/framework-gaps.md) (what the framework lacks, with proposed changes). ## Not done Clipboard image paste, wake-up of the agent by finished background commands, sub-agent definitions, a `--full-auto` style flag (use `--permissions full-access`), themes, and a TOML array-of-tables config. See `docs/framework-gaps.md` for why some of them wait on the framework.