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

Feature Description
โšก Instant CLI Run nano-code and start chatting immediately
๐Ÿ›  Rich Toolset Built-in tools for filesystem operations and more
๐Ÿง  Smart Memory Persistent session context with cost tracking
๐Ÿ”Œ Pluggable LLMs OpenAI-compatible with easy provider switching
๐Ÿ“ฆ Zero Config Works out of the box with sensible defaults

Built-in Tools

  • File Operations: list_dir, find_files, read_file, write_file, edit_file, mv_file_or_dir
  • Search & Analysis: search_text with regex support
  • Task Management: add_tasks for quick TODO capture
  • Easy Extensibility: Simple plugin system for custom tools

๐Ÿš€ Installation

Quick Start (Recommended)

# Install and run with uv (fastest)
uvx nano-code@latest

Development Setup

# Clone the repo
git clone https://github.com/gusye1234/nano-code.git
cd nano-code

# Install with uv (recommended)
uv sync

# Or install in development mode
uv pip install -e '.[dev]'

# Or use pip
pip install -e '.[dev]'

Requirements

  • Python โ‰ฅ 3.11
  • OpenAI-compatible API key

Environment Setup

# Required: Set your OpenAI API key
export OPENAI_API_KEY="sk-..."

# Optional: Custom endpoint (for OpenAI-compatible APIs)
export LLM_BASE_URL="https://api.openai.com/v1"

# Optional: Default model override
export LLM_MAIN_MODEL="gpt-4.1"

โš™๏ธ Configuration

Configure nano-code using either environment variables or a config file. Environment variables take precedence over config files.

Method 1: Environment Variables (Recommended)

export OPENAI_API_KEY="sk-..."           # Required
export LLM_BASE_URL="https://api.openai.com/v1"  # Optional
export LLM_MAIN_MODEL="gpt-4.1"         # Optional

Method 2: Config File

Create ~/.nano_code/config.json:

{
  "llm_api_key": "sk-...",
  "llm_base_url": "https://api.openai.com/v1",
  "llm_main_model": "gpt-4.1"
}

Config file locations:

  • Linux/macOS: ~/.nano_code/config.json
  • Windows: %USERPROFILE%\.nano_code\config.json

See nano_code/env.py for all supported configuration options.

๐Ÿƒโ€โ™€๏ธ Quickstart

One-liner (Recommended)

uvx nano-code

From source

# After installing from source
python -m nano_code
# OR
nano-code

First Run

  1. Run nano-code in your project directory
  2. The agent will start with your current directory as the working context
  3. Start chatting! Try:
    • "List all Python files in this project"
    • "Find TODO comments in the codebase"
    • "Read the main README file"

๐Ÿ—‚ Project Structure

nano-code/
โ”œโ”€โ”€ nano_code/                 # Core library package
โ”‚   โ”œโ”€โ”€ agent/                 # Agent implementations
โ”‚   โ”œโ”€โ”€ agent_tool/            # Tool system
โ”‚   โ”‚   โ”œโ”€โ”€ os_tool/           # Filesystem operations
โ”‚   โ”‚   โ””โ”€โ”€ util_tool/         # Utility functions
โ”‚   โ”œโ”€โ”€ core/                  # Session & memory management
โ”‚   โ”œโ”€โ”€ llm/                   # LLM integrations
โ”‚   โ”œโ”€โ”€ utils/                 # Shared utilities
โ”‚   โ”œโ”€โ”€ constants.py           # Configuration constants
โ”‚   โ”œโ”€โ”€ env.py                 # Environment configuration
โ”‚   โ””โ”€โ”€ __main__.py            # CLI entry point
โ”œโ”€โ”€ tests/                     # Comprehensive test suite
โ”œโ”€โ”€ pyproject.toml             # Project configuration
โ””โ”€โ”€ README.md                  # Documentation

Key Components

  • Session System: Maintains context across interactions
  • Tool Registry: Pluggable architecture for custom tools
  • LLM Abstraction: Provider-agnostic LLM interface
  • Cost Tracking: Real-time usage and cost monitoring

๐Ÿค Contributing

We welcome contributions! The codebase is intentionally small and designed for easy extension.

Getting Started

# Clone and setup
git clone https://github.com/gusye1234/nano-code.git
cd nano-code
uv sync

# Run tests
pytest -q

# Run tests with coverage
pytest --cov=nano_code tests/

Contribution Guidelines

  • Add new tools: Easy plugin system for custom functionality
  • Improve documentation: Help make the project more accessible
  • Extend test coverage: Ensure reliability for all features
  • Report bugs: Create issues for any problems you encounter

For significant changes, please open an issue first to discuss your approach.

๐Ÿ“œ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿท๏ธ Disclaimer

Any git commit that starts with nc: is written by nano-code itself.


Built with โค๏ธ by the nano-code community

โญ Star this project on GitHub

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.5.tar.gz (19.4 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.5-py3-none-any.whl (31.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for nano_code-0.1.5.tar.gz
Algorithm Hash digest
SHA256 807e96e609bd5236b4bd3873b5d30a7401f33e1e34e5364330d2299132b762c6
MD5 46c3a40af27d5c32dfc326e738e3a155
BLAKE2b-256 05383ca014d8a3c0308afb80d6baf37522e1c76ce014e43b77e2865545a6f6d1

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for nano_code-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 9aae12f8293538dd9e00bdf3190b02390c6382845beab37b0681bcd32fb21386
MD5 cab59ad4ff5c8938463425e3dadc497b
BLAKE2b-256 ae1c4d9d8a3955a8243b02a2956c9c77a88ef02c715e10a3decb5252b08c3dad

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