Metadata-Version: 2.5
Name: opencode-unlimited
Version: 0.1.0
Summary: Local HTTP/HTTPS proxy for OpenCode with Tor, WARP, and direct egress lanes and automatic failover.
Project-URL: Homepage, https://github.com/mithun50/opencode-unlimited
Project-URL: Documentation, https://github.com/mithun50/opencode-unlimited/tree/main/docs
Project-URL: Repository, https://github.com/mithun50/opencode-unlimited
Project-URL: Issues, https://github.com/mithun50/opencode-unlimited/issues
Project-URL: Changelog, https://github.com/mithun50/opencode-unlimited/blob/main/CHANGELOG.md
Project-URL: Security, https://github.com/mithun50/opencode-unlimited/blob/main/SECURITY.md
Author-email: Mithun Gowda B <mithungowda.b7411@gmail.com>
License: MIT License
        
        Copyright (c) 2026 Mithun Gowda B (mithungowda.b7411@gmail.com)
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: cli,opencode,proxy,rate-limit,termux,tor,warp
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Internet :: Proxy Servers
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
Requires-Python: >=3.10
Requires-Dist: aiohttp>=3.9
Requires-Dist: httpx[socks]>=0.27
Requires-Dist: rich>=13
Requires-Dist: stem>=1.8
Requires-Dist: tomli>=2.0; python_version < '3.11'
Requires-Dist: typer>=0.12
Provides-Extra: dashboard
Requires-Dist: fastapi>=0.110; extra == 'dashboard'
Requires-Dist: uvicorn>=0.29; extra == 'dashboard'
Provides-Extra: dev
Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
Requires-Dist: pytest>=8.0; extra == 'dev'
Requires-Dist: ruff>=0.4; extra == 'dev'
Requires-Dist: trustme>=1.1; extra == 'dev'
Description-Content-Type: text/markdown

# opencode-unlimited

[![PyPI version](https://img.shields.io/pypi/v/opencode-unlimited.svg)](https://pypi.org/project/opencode-unlimited/)
[![Python](https://img.shields.io/pypi/pyversions/opencode-unlimited.svg)](https://pypi.org/project/opencode-unlimited/)
[![CI](https://github.com/mithun50/opencode-unlimited/actions/workflows/ci.yml/badge.svg)](https://github.com/mithun50/opencode-unlimited/actions/workflows/ci.yml)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/mithun50/opencode-unlimited/blob/main/LICENSE)
[![Code style: ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)

**opencode-unlimited** (`ocu`) is a local HTTP/HTTPS proxy for [OpenCode](https://opencode.ai). It sends OpenCode's traffic out through one of several egress "lanes" (direct, Cloudflare WARP, Tor) and moves to the next lane when one fails or, for plain-HTTP traffic, returns `429 Too Many Requests`.

> **Know the limits.** Quotas tied to your OpenCode account or API key are counted per account, not per IP address, so changing the egress lane does not reset them. HTTPS traffic is end-to-end encrypted, so `ocu` can't see 429 responses inside it (see [HTTPS and 429s](#https-and-429s)). Follow the terms of the services you use.

---

## Features

- Local forward proxy on `127.0.0.1:8877` that handles HTTPS `CONNECT` tunnels and plain HTTP, and streams server-sent events without buffering
- Egress lanes: direct, Cloudflare WARP, and Tor, with failover when a lane can't connect
- On plain-HTTP `429`: records the event (with `Retry-After`), rotates to the next lane, and retries once
- Lanes that are disabled or whose service fails to start are removed from rotation
- `ocu tor install`: checks for Tor and installs it (the official Tor Expert Bundle verified by SHA-256 on Windows, your package manager elsewhere), and can add it to your PATH
- `ocu run`: finds or installs OpenCode, starts the proxy in the background, and launches OpenCode through it
- Optional web dashboard (FastAPI)
- Pure-Python config (stdlib dataclasses + TOML), so it installs cleanly on Termux

---

## Installation

```bash
# Recommended (isolated, puts `ocu` on PATH)
pipx install opencode-unlimited

# Or with uv
uv tool install opencode-unlimited

# Or with pip inside a virtual environment
pip install opencode-unlimited

# With the web dashboard
pipx install "opencode-unlimited[dashboard]"
```

Requires Python 3.10+. Tor is optional and `ocu` can install it for you. WARP is optional and needs `warp-cli`.

<details>
<summary>Platform notes (Windows, Debian/Ubuntu, Termux)</summary>

**Windows (PowerShell)**

```powershell
python -m pip install --user pipx
python -m pipx ensurepath   # then open a new terminal
pipx install opencode-unlimited
```

**Debian / Ubuntu** (`externally-managed-environment` / PEP 668)

```bash
sudo apt update && sudo apt install -y pipx
pipx ensurepath
pipx install opencode-unlimited
```

**Termux (Android)**

```bash
pkg install python tor
pip install opencode-unlimited
```

</details>

---

## Quick start

```bash
ocu run              # start the proxy in the background and launch OpenCode through it
ocu run --desktop    # same, but launch OpenCode Desktop
ocu start -d         # only start the background proxy
ocu status           # proxy, lanes, and account status
ocu tor status       # is Tor installed / on PATH / listening?
ocu stop             # stop the background proxy (and the Tor it started)
```

To route any other tool through `ocu`, point it at the proxy:

```bash
export HTTPS_PROXY=http://127.0.0.1:8877 HTTP_PROXY=http://127.0.0.1:8877
```

```powershell
$env:HTTPS_PROXY = "http://127.0.0.1:8877"; $env:HTTP_PROXY = "http://127.0.0.1:8877"
```

> OpenCode 2.x normally sends work to a long-running background service that does not inherit these variables. `ocu run` therefore launches OpenCode with `--standalone`. If you launch OpenCode yourself, pass `--standalone` too, for example `opencode run --standalone "..."`.

---

## CLI commands

| Command | Description |
|---|---|
| `ocu run [-- ARGS]` | Find/install OpenCode, start the proxy in the background, launch OpenCode through it |
| `ocu setup` | Detect OpenCode CLI/Desktop and install or configure it |
| `ocu start [-d]` | Start the proxy stack (foreground with live status, or `-d` for background) |
| `ocu stop` | Stop the background proxy |
| `ocu status` | Show proxy status, lane health, and the account pool |
| `ocu logs [-f] [-n N]` | Show or follow the log file |
| `ocu dashboard [-p PORT]` | Run the web dashboard (needs the `dashboard` extra) |
| `ocu config show` / `set KEY VALUE` / `reset` | View, change, or reset the configuration |
| `ocu lanes list` | Show egress lanes and their health |
| `ocu lanes tor on/off`, `ocu lanes warp on/off` | Enable or disable a lane |
| `ocu tor status` | Show whether Tor is installed, on PATH, and listening |
| `ocu tor install [-y] [--no-path] [--force]` | Install Tor and (optionally) add it to PATH |
| `ocu tor path` | Add an installed Tor's folder to your user PATH (Windows) |
| `ocu tor renew` | Ask the running Tor for a new circuit |
| `ocu accounts list/add/remove/rotate` | Manage the local account pool |
| `ocu version` | Print the version |

Common options for `start` and `run`: `--proxy-port`, `--no-tor`, `--no-warp`, `--dashboard`.

---

## How it works

```
  OpenCode (HTTPS_PROXY=http://127.0.0.1:8877)
         |
         v
  +------+--------+   CONNECT host:443  -> tunnel via current lane, fail over on connect error
  |   ZenProxy    |   plain HTTP        -> forward, on 429 rotate + retry once
  +------+--------+
         |  lane selector (ProxyChain)
   +-----+------+---------+
   v            v         v
 direct      WARP       Tor
 (clean)   SOCKS5    SOCKS5
           :40000    :9050
         \     |     /
          v    v    v
       opencode.ai / models.opencode.ai / provider APIs
```

Full details are in [docs/architecture.md](https://github.com/mithun50/opencode-unlimited/blob/main/docs/architecture.md).

### Lanes

| Lane | Config name | Route |
|---|---|---|
| Clean endpoint | `clean` / `clean_endpoint` | Direct connection |
| Direct | `direct` | Direct connection (always available) |
| WARP | `warp` | SOCKS5 `127.0.0.1:40000` (WARP must be in proxy mode) |
| Tor | `tor` | SOCKS5 `127.0.0.1:9050` |

The default order is `["clean", "warp", "tor"]`, followed by any lanes not listed. Change it with:

```bash
ocu config set lanes_priority "tor,clean"
```

### HTTPS and 429s

OpenCode uses HTTPS, which reaches `ocu` as `CONNECT` tunnels. `ocu` opens each tunnel through the current lane and tries the next lane if the connection fails. The TLS session runs between OpenCode and the server (`ocu` does not decrypt it), so a `429` inside the tunnel reaches OpenCode unchanged and does not trigger rotation. 429 handling applies to plain-HTTP requests.

### Tor

`ocu start` and `ocu run` check for Tor when the Tor lane is on, and offer to install it if it's missing. See [docs/tor.md](https://github.com/mithun50/opencode-unlimited/blob/main/docs/tor.md) for what the installer does on each OS and how it edits PATH on Windows.

---

## Configuration

| Platform | Path |
|---|---|
| Linux | `~/.config/opencode-unlimited/config.toml` |
| macOS | `~/Library/Application Support/opencode-unlimited/config.toml` |
| Windows | `%APPDATA%\opencode-unlimited\config.toml` |

```toml
proxy_port = 8877
dashboard_port = 7979
enable_warp = true
enable_tor = true
enable_clean_endpoints = true
auto_resume = true
log_level = "INFO"
lanes_priority = ["clean", "warp", "tor"]
opencode_api_host = "api.opencode.ai"
opencode_cli_path = ""
opencode_desktop_path = ""
```

Every key is described in [docs/configuration.md](https://github.com/mithun50/opencode-unlimited/blob/main/docs/configuration.md).

---

## Documentation

- [Architecture](https://github.com/mithun50/opencode-unlimited/blob/main/docs/architecture.md)
- [Configuration](https://github.com/mithun50/opencode-unlimited/blob/main/docs/configuration.md)
- [Tor setup](https://github.com/mithun50/opencode-unlimited/blob/main/docs/tor.md)
- [Testing](https://github.com/mithun50/opencode-unlimited/blob/main/docs/testing.md)
- [Troubleshooting](https://github.com/mithun50/opencode-unlimited/blob/main/docs/troubleshooting.md)
- [Changelog](https://github.com/mithun50/opencode-unlimited/blob/main/CHANGELOG.md)

---

## Contributing

Contributions are welcome. Start with [CONTRIBUTING.md](https://github.com/mithun50/opencode-unlimited/blob/main/CONTRIBUTING.md), and please follow the [Code of Conduct](https://github.com/mithun50/opencode-unlimited/blob/main/CODE_OF_CONDUCT.md).

Report security issues privately as described in [SECURITY.md](https://github.com/mithun50/opencode-unlimited/blob/main/SECURITY.md), not in public issues.

---

## License

MIT. See [LICENSE](https://github.com/mithun50/opencode-unlimited/blob/main/LICENSE).
