# EcoCoder Agent Setup Guide

Base URL: `https://api.leanlm.ai/v1` (Anthropic base: `https://api.leanlm.ai`)
Model ID: `ecocoder` (aliases: `leanlm-eco`, `ecocoder-turbo`)
CLI v1.6.7 SHA-256: `cae65789e1acc1803b0aa781057b462677f673b19695563c4b827b59be565788`

## Rules for Coding Agents Reading This File

1. **Protect API keys:** Never ask the user to paste an `eco_live_...` key into chat, never read or print `~/.ecocoder/key`, and never commit keys into config files. Always instruct the user to run `ecocoder login` directly in their terminal.
2. **Verify the binary:** Always verify the downloaded `ecocoder` CLI SHA-256 against `cae65789e1acc1803b0aa781057b462677f673b19695563c4b827b59be565788` (and `https://api.leanlm.ai/ecocoder.sha256`) before moving it onto `PATH`.
3. **One install command:** Run `ecocoder install-subagent --global` once. It writes the EcoCoder skill to `~/.claude/skills/ecocoder/SKILL.md` and `~/.agents/skills/ecocoder/SKILL.md` and prints every file it writes; do not hand-edit agent config files.
4. **No unsolicited spend flags:** Accounts are prepaid and stop cleanly with HTTP `402` at zero balance. Do not append arbitrary `--max-usd` caps unless the user asks for a per-session limit.

## Step 1: Install & Verify `ecocoder` CLI v1.6.7 (Once per Machine)

```bash
mkdir -p ~/.local/bin && tmp=$(mktemp) && \
  curl -fsSL https://api.leanlm.ai/ecocoder -o "$tmp" && \
  (printf "cae65789e1acc1803b0aa781057b462677f673b19695563c4b827b59be565788  %s\n" "$tmp" | shasum -a 256 -c - 2>/dev/null || \
   printf "cae65789e1acc1803b0aa781057b462677f673b19695563c4b827b59be565788  %s\n" "$tmp" | sha256sum -c -) && \
  chmod +x "$tmp" && mv "$tmp" ~/.local/bin/ecocoder && \
  export PATH="$HOME/.local/bin:$PATH"
```

Add `export PATH="$HOME/.local/bin:$PATH"` to `~/.zshrc` or `~/.bashrc` if `~/.local/bin` is not already on `PATH`.

## Step 2: Sign In & Check Connection

Tell the user to run this in their own terminal (never inside agent chat logs):

```bash
ecocoder login && ecocoder check
```

Secrets (`.env*`, private keys, credentials) and VCS/build folders are skipped locally. Users can inspect the exact synced file list anytime with `ecocoder sync-preview`.

## Step 3: Wire Your Coding Agent

Using the `ecocoder` CLI unlocks delta-synced multi-file repository context, automatic edit checks, and `ecocoder stats` cost/energy receipts.

### Claude Code / Codex (Recommended: Delegate Subtasks)

```bash
ecocoder install-subagent --global
```

This installs one EcoCoder skill for both Claude Code (`~/.claude/skills/ecocoder/`) and Codex (`~/.agents/skills/ecocoder/`). Your lead agent calls `ecocoder delegate` directly; run independent tasks in parallel in the background. `delegate` edits the working tree in place: send its output to a log file under `~/.ecocoder/runs/` (not a shared `/tmp` path) and never pipe it through `tail`. Check progress with `ecocoder stats --run-id <id>` and `git diff --stat`. On any nonzero exit, read the `[ecocoder] NEXT:` line (or `error.hint` in --json output) and follow it before retrying. Always pass the exact command that proves the task is done via `--verify-cmd`; EcoCoder checks its own work with it before finishing. Exit 69 means spend limit reached (do not retry); 70 or 71 means your --verify-cmd failed or could not run when the CLI re-ran it (the work is unverified); 75 means retry later (rate limited or gateway unavailable); 76 means the network was down and the run was stopped; 77 means the API key was rejected. For one-off CLI delegation or full-session usage:

```bash
ecocoder delegate "Fix edge cases in parser.py" --verify-cmd "<exact test command, with the repo's venv/PYTHONPATH>"
# Or run a full interactive session:
ecocoder claude
ecocoder run -- codex -m ecocoder
```

### OpenCode

```bash
OPENCODE_CONFIG_CONTENT='{"provider":{"leanlm":{"npm":"@ai-sdk/openai-compatible","name":"EcoCoder","options":{"baseURL":"{env:OPENAI_BASE_URL}","apiKey":"{env:OPENAI_API_KEY}"},"models":{"ecocoder":{"name":"EcoCoder","limit":{"context":128000,"output":32768}}}}},"model":"leanlm/ecocoder"}' ecocoder run -- opencode
```

### pi

`ecocoder pi` automatically provisions an isolated `models.json` wired to the local synced proxy:

```bash
ecocoder pi
```

(Optional without local proxy: `ecocoder setup-pi --write && pi --provider ecocoder --model ecocoder`.)

### Cline / Kilo Code (VS Code)

Run the local synced proxy from the repo root:

```bash
ecocoder proxy
```

Then configure the extension provider settings:
- **API Provider:** `OpenAI Compatible`
- **Base URL:** `http://127.0.0.1:8787/v1`
- **API Key:** `ecocoder-local-proxy`
- **Model ID:** `ecocoder`

## Direct HTTPS / SDK / Cursor BYOK (Zero CLI Fallback)

Direct HTTPS skips CLI installation and repository sync. Multi-turn tool-calling agents passing `Read`/`Write`/`Edit` exchanges with a stable `x-session-id` receive session-local, best-effort single-file checks. Keep HTTP read timeouts `>= 180s`, omit `max_tokens` (or set `>= 16384`), and send `x-leanlm-run-id`:

- **OpenAI / Codex SDK Base URL:** `https://api.leanlm.ai/v1`
- **Anthropic Base URL:** `https://api.leanlm.ai`
- **Model ID:** `ecocoder`

## Step 4: Save 20% on Unattended Runs & Inspect Receipts

- **Standard pricing:** `$0.30/1M` uncached input · `$0.03/1M` cached input (`$0` cache-write fee) · `$1.20/1M` output.
- **Spend 20% less (`--flex`):** `$0.24 / $0.024 / $0.96` per 1M. Pass `--flex` on any `ecocoder` CLI command or header `X-LeanLM-Flex: eco` on Direct HTTPS for unattended/background runs (async queue may hold up to ~60s/turn under load; keep interactive terminals on Standard).
- **Optional per-session cap:** Pass `--max-usd <N>` to cap a single command run below your account balance.
- **Receipts & energy summary:** Run `ecocoder stats`.
