A small terminal coding agent written in Python
Project description
nanocode
A small terminal coding agent written in Python.
nanocode is pre-1.0 software. Commands, configuration, and tool behavior may change before a stable release.
Features
- Live turn control: Add follow-up input while the agent is still working, without losing the current tool flow.
- File-state brain: Reads and edits build a current, line-numbered view of the files that matter now.
- Stale-edit protection:
line:hashanchors reject edits when the target code has drifted. - Project-aware navigation: Use the symbol index to jump through outlines, references, implementors, call chains, and changed files quickly.
- Recoverable context: Tool output stays bounded in the prompt, while raw
tr.Nresults remain recallable. - Cache-aware context: Stable sections stay early and noisy working state stays late to improve prompt-cache reuse.
- Focused working memory:
Noteseparates goal, plan, and known facts from noisy execution logs. - MCP integration: Connect to remote (HTTP) or local (stdio) Model Context Protocol servers and call their tools.
- Terminal-first workflow: Model selection, history search, confirmations, live command output, appended input, and status all stay in one CLI.
Install
uv tool install nanocode-cli
Upgrade:
uv tool upgrade nanocode-cli
For local development:
uv sync --extra dev
uv run nanocode
Usage
Start the CLI:
nanocode
Useful arguments:
--config <path>: use a TOML config file.--init-config: create a default config file.--yolo: skip confirmations for mutating tools.-v,--version: show the version.
During a running turn, the +> prompt accepts follow-up input for the next model request.
Commands
/help: show commands and tools./status: show runtime status./config: show active config./api [auto|chat|anthropic]: show or set provider API format./debug [on|off]: toggle model I/O debug traces./compact: compact context now./index [force]: sync or rebuild the code symbol index./mcp [tools|login|logout|refresh] ...: manage MCP servers and tools./provider [NAME]: show or set provider./model [MODEL]: show or set model./reason: choose reasoning effort./set KEY VALUE: set provider/runtime values./yolo: toggle tool confirmations./exit,/quit: exit.
Interactive selectors support j/k, arrows, / search, Enter, and Esc. Input supports history, completion, and Ctrl-R history search.
Tools
- File:
Read,LineCount,List,Find,Search. - Code index:
InspectCode. - Edit:
Editcreates or patches file content. - Shell:
Bash,Git. - Tool results:
Recall. - Working notes:
Note. - MCP:
MCPcalls tools on configured MCP servers.
Read, Search, and InspectCode return line anchors where useful. Edit uses current line:hash anchors to reject stale edits.
Configuration
Run:
nanocode --init-config
Default config location is ~/.nanocode/config.toml.
Main fields:
[provider] active = "name"[provider.<name>]:url,key,model,api,prompt_cache_key,available_models,reasoning,chat_reasoning,temperature,timeout[paths] data_dir[runtime] shell_timeout,max_agent_steps,max_context_tokens,yolo
api = "auto" chooses between Chat Completions and Anthropic Messages using provider/model profiles. prompt_cache_key = "auto" derives a stable key from provider, model, workspace, and tool schema names.
MCP
nanocode connects to Model Context Protocol servers and exposes their tools through the MCP tool. Configure each server under [mcp.<name>]. A server is either url (remote) or command (local), never both.
Remote server over streamable HTTP:
[mcp.example]
url = "https://example.com/mcp"
bearer_token_env_var = "EXAMPLE_MCP_TOKEN" # optional; sends Authorization: Bearer
enabled = true
[mcp.oauth_example]
url = "https://example.com/mcp"
auth = "oauth" # browser login via /mcp login <server>
enabled = true
Local server over stdio (launched as a subprocess):
[mcp.filesystem]
command = "npx"
args = ["-y", "@modelcontextprotocol/server-filesystem", "/tmp"]
env = { SOME_TOKEN = "value" } # optional; merged over the inherited environment
enabled = true
The HTTP auth options (auth, bearer_token_env_var, env_http_headers) apply to url servers only. env_http_headers maps a header name to the environment variable holding its value.
Manage servers at runtime:
/mcp: list configured servers and connection status./mcp tools [server]: list discovered tools./mcp refresh [server]: rediscover servers./mcp login <server>//mcp logout <server>: OAuth login and logout.
Tested Providers
The following providers have been tested with nanocode:
- deepseek: DeepSeek API
- opencode: OpenCode API
- aliyun: Alibaba Cloud (Tongyi Qianwen) API via Chat Completions
- llama.cpp: Local inference via llama.cpp server
Context Design
Each model request is built manually from explicit messages. Stable context comes first, conversation stays as messages, working memory follows, and the latest file state is appended at the end.
model request
+--------------------------------------------------+
| system |
| concise agent contract and tool rules |
+--------------------------------------------------+
| user |
| Environment |
+--------------------------------------------------+
| user/assistant |
| conversation, compacted summaries, tools |
+--------------------------------------------------+
| user |
| Memory: goal, plan, known, date |
+--------------------------------------------------+
| user |
| FILE STATE: latest Read/Edit file view |
+--------------------------------------------------+
Core rules:
- Mid-turn assistant text and appended user input are kept as conversation.
- Earlier conversation is compacted into an explicit summary when the context grows too large.
- FILE STATE is updated by successful
ReadandEdittools and shows current listed file ranges, with recent files first. - Newer file lines overwrite older lines; edit invalidations clear stale ranges.
- File lines are checked against current file stat or line hash before being shown.
- Successful
ReadandEdittool messages point to FILE STATE instead of repeating file bodies. - Other tool outputs are bounded in conversation messages and can be recalled by
tr.N.
Safety
nanocode can edit files and run shell commands in the environment where it is started. It does not provide sandbox protection. Run it inside your own sandbox, container, VM, or other isolated environment when needed.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nanocode_cli-0.6.2.tar.gz.
File metadata
- Download URL: nanocode_cli-0.6.2.tar.gz
- Upload date:
- Size: 76.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b1b9286bc3d9d30df23a79629d584b09715d38287442870fa7268ca78afdf836
|
|
| MD5 |
310eab2b23daf9f024492f50ff26abde
|
|
| BLAKE2b-256 |
e8453de71afad177adac28e8c274832ee52ac00280fb678ca7fd21af408cc170
|
File details
Details for the file nanocode_cli-0.6.2-py3-none-any.whl.
File metadata
- Download URL: nanocode_cli-0.6.2-py3-none-any.whl
- Upload date:
- Size: 71.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c0dc3dceb40d89350d70d1a0e80f6fcab89036ad73d720607a7777d6c34371a9
|
|
| MD5 |
a2554d8379c5be7978faa3432a7e5b02
|
|
| BLAKE2b-256 |
8fee6017288e29a6ddfb633ae26eaaea9b70b9c0f013a648dff269afeae91096
|