Skip to main content

A Python Implementation of Gemini Code

Project description

Shows the nano-code logo

nano-code

A tiny agent in your terminal

uvx nano-code@latest

nano-code is a tiny, batteries-included code-assistant written in Python. Inspired by Google’s Gemini Code, it lets you spin up an interactive CLI agent powered by OpenAI (or any compatible) LLM and a growing toolbox of actions such as reading files, listing directories, searching text and more.

The project aims to be small enough to grok in one sitting yet powerful enough to be genuinely useful when navigating or refactoring real-world codebases.


✨ Features

  • Agent CLI – run nano-code and start chatting immediately.
  • 🛠 Basic Tools – easily add new tools. Out-of-the-box you get:
    • list_dir, find_files, read_file, write_file, search_text
    • add_tasks for quick TODO-list capture.
  • 🧠 Session memory – every run stores context (working dir, conversation, cost tracking).
  • 🔌 Pluggable LLM – ships with an OpenAI client but the design allows dropping in other providers.

🚀 Installation

We recommend the blazingly fast uv package manager, but classic pip works too.

# 1. Clone the repo (optional – the package can also live on PyPI later)
git clone https://github.com/gusye1234/nano-code.git
cd nano-code

# 2. Install (requires Python ≥ 3.11)
uv sync

# or for editable dev installs (includes test dependencies)
uv pip install -e '.[dev]'

# fallback (slower) – replace `uv pip` with classic pip if you don't have uv

Make sure you have an OpenAI-compatible API key in your environment:

export OPENAI_API_KEY="sk-..."
# Optional – point to an OpenAI-compatible endpoint
export LLM_BASE_URL="https://api.openai.com/v1"

⚙️ Configuration

nano-code supports configuration via environment variables and an optional config file. You must provide an OpenAI-compatible API key, and can customize the LLM endpoint or other defaults if desired.

Option 1: Environment variables (recommended for quickstart)

Option 2: config.json file

You can optionally create a config file at:

~/.nano_code/config.json

Where ~ is your home directory (e.g., /home/yourname/.nano_code/config.json on Linux/macOS, or C:\Users\yourname\.nano_code\config.json on Windows).

Example contents:

{
  "llm_api_key": "sk-...",
  "llm_base_url": "https://api.openai.com/v1",
  "llm_main_model": "gpt-4.1"
}
  • Any keys matching the Env class (see nano_code/env.py) are supported.
  • File-based config takes effect if present, otherwise environment variables are used as fallback.

🏃‍♀️ Quickstart

uvx nano-code

🗂 Project structure

nano-code/
├── nano_code/                 # Library package
│   ├── agent/                 # Agent implementations (interactive / non-interactive)
│   ├── agent_tool/            # Tool registry & concrete tools
│   │   ├── os_tool/           # File-system helpers (list_dir, read_file, ...)
│   │   └── util_tool/         # Misc utilities (add_tasks)
│   ├── core/                  # Session handling, cost tracking
│   ├── llm/                   # LLM client abstraction & OpenAI driver
│   ├── utils/                 # Shared helpers (logger, file paths)
│   ├── constants.py           # Global paths & limits
│   ├── env.py                 # Runtime configuration loader
│   └── __main__.py            # CLI entry-point (`python -m nano_code`)
├── tests/                     # Pytest suite exercising tools & flows
├── pyproject.toml             # Project metadata / dependencies
└── README.md                  # ← You are here

🤝 Contributing

Pull requests are welcome! The codebase is intentionally small – feel free to add new tools, improve docs or extend test coverage. For larger changes, please open an issue first to discuss what you would like to change.

# run the tests
pytest -q

📜 License

This project is licensed under the MIT License. See LICENSE for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nano_code-0.1.4.tar.gz (86.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nano_code-0.1.4-py3-none-any.whl (26.2 kB view details)

Uploaded Python 3

File details

Details for the file nano_code-0.1.4.tar.gz.

File metadata

  • Download URL: nano_code-0.1.4.tar.gz
  • Upload date:
  • Size: 86.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.4

File hashes

Hashes for nano_code-0.1.4.tar.gz
Algorithm Hash digest
SHA256 b9d92133d831078ca7122db28a3fe2ba638161cb5e3f5f97a78a38d8f6031a23
MD5 0c09f2f96507dcb94d7da6648e1cb405
BLAKE2b-256 d9c5d09a99337b0084e093ce1ccbccc9de27a3fcaaaebf81885524381324c7ae

See more details on using hashes here.

File details

Details for the file nano_code-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: nano_code-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 26.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.4

File hashes

Hashes for nano_code-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 5c6e77d3e2af3d69f8ad7dd22b08b3f643238fbdcfcd7edd5330da768dfbae94
MD5 90e0a9cde6a21186c7a132ca3a1debed
BLAKE2b-256 3e73105ffd93ffdeeed1cc396cb841c285b26428e3968aa3e07e26718a0dd808

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page