# Developer Tool Providers

This page covers providers that integrate through local assistant tooling or CLI runtimes instead of a standard remote LLM API. They are useful when LibreFang agents need to reuse an existing coding or terminal-assistant stack.

## Included Providers

- Claude Code
- GitHub Copilot
- ChatGPT (Session Token)
- Kimi Coding
- Aider
- Claude Code CLI
- Codex CLI
- Gemini CLI
- Qwen Code

## CLI logins as first-class default providers

When you have not set a provider API key but **do** have a working CLI login (`claude`, `codex`, `gemini`, `qwen` available on `PATH` and authenticated), LibreFang will pick the CLI provider as the default model for new agents. The detection runs at startup and is rechecked when the daemon refreshes provider availability.

Detection priority (in order, first match wins):

1. `claude-code` — `claude` binary on `PATH`, `claude auth status` reports an active session.
2. `codex-cli` — `codex` binary on `PATH`, with `OPENAI_API_KEY` (which the Codex CLI itself needs) set.
3. `gemini-cli` — `gemini` binary on `PATH`, authenticated via `gemini auth login`.
4. `qwen-code` — `qwen` binary on `PATH`, authenticated.

This behaviour replaced the previous "fallback when API providers fail" heuristic — CLI providers are now treated like any other remote provider. To explicitly override the auto-pick, set `[default_model] provider = "anthropic"` (or whichever) in `config.toml`.

---

## Claude Code

| | |
|---|---|
| **Display Name** | Claude Code |
| **Driver** | Native Anthropic (Messages API) |
| **Env Var** | `ANTHROPIC_API_KEY` |
| **Base URL** | `https://api.anthropic.com` |
| **Key Required** | Yes |
| **Free Tier** | No |
| **Auth** | `x-api-key` header |
| **Models** | Claude models with extended tool use |

**Notes:** Claude Code is an Anthropic model variant optimized for agentic coding tasks. It uses the same API key and base URL as Anthropic but targets models tuned for long-horizon tool-use workflows.

---

## GitHub Copilot

| | |
|---|---|
| **Display Name** | GitHub Copilot |
| **Driver** | OpenAI-compatible (via Copilot token exchange) |
| **Env Var** | `GITHUB_TOKEN` |
| **Base URL** | `https://api.githubcopilot.com` |
| **Key Required** | Yes (GitHub PAT or OAuth token) |
| **Free Tier** | Included with GitHub Copilot subscription |
| **Auth** | OAuth PKCE flow; exchanges GitHub PAT for short-lived Copilot API token |
| **Models** | GitHub Copilot-hosted models (GPT-4o, Claude, etc.) |

**Setup:**
1. Subscribe to [GitHub Copilot](https://github.com/features/copilot)
2. Create a Personal Access Token with `copilot` scope
3. `export GITHUB_TOKEN="ghp_..."`

**Notes:** The Copilot driver handles OAuth PKCE token exchange automatically — it obtains a short-lived Copilot API token from `https://api.github.com/copilot_internal/v2/token` and caches it with auto-refresh. The Copilot API uses OpenAI-compatible chat completions format. Tokens are refreshed 5 minutes before expiry.

---

## ChatGPT (Session Token)

| | |
|---|---|
| **Display Name** | ChatGPT |
| **Provider ID** | `chatgpt` |
| **Driver** | Native ChatGPT (Responses API) |
| **Env Var** | `CHATGPT_SESSION_TOKEN` (primary), `CHATGPT_REFRESH_TOKEN` (optional) |
| **Base URL** | `https://chatgpt.com/backend-api` |
| **Key Required** | Yes (browser session token) |
| **Free Tier** | Subscription-based (ChatGPT Plus / Pro / Team / Enterprise) |
| **Auth** | Session token + bearer; OAuth-style refresh with ~7-day TTL |

**Setup:**
1. Run `librefang auth chatgpt` (browser-based OAuth flow). The CLI captures the session token and caches it.
2. The token auto-refreshes 1 hour before expiry; no manual rotation needed.

**Minimal `config.toml`:**

```toml
[default_model]
provider = "chatgpt"
model = "gpt-4o"
```

**Notes:** Uses the proprietary Responses API rather than `/v1/chat/completions`. This lets agents reuse a paid ChatGPT subscription without a separate OpenAI API key. **Tools and vision supported.** Embeddings are not available via this driver — use OpenAI hosted instead.

---

## Kimi Coding

| | |
|---|---|
| **Display Name** | Kimi Coding |
| **Provider ID** | `kimi-coding` |
| **Driver** | Anthropic-compatible (Messages API) |
| **Env Var** | `KIMI_API_KEY` |
| **Base URL** | `https://api.kimi.com/coding` |
| **Key Required** | Yes |
| **Free Tier** | No |
| **Auth** | `Authorization: Bearer` header |

**Setup:**
1. Sign up at the Kimi console and enable the Coding endpoint
2. Generate an API key under the Coding product
3. `export KIMI_API_KEY="sk-..."`

**Minimal `config.toml`:**

```toml
[default_model]
provider = "kimi-coding"
model = "kimi-coder"
```

**Notes:** Coding-specialized variant of Moonshot's stack, exposed in **Anthropic Messages API format** (not OpenAI-compatible). Uses the same internal driver path as Anthropic, including tool-use schema conversion and vision support. Different env var from `MOONSHOT_API_KEY` — Kimi Coding uses its own key.

---

## Aider

| | |
|---|---|
| **Display Name** | Aider |
| **Type** | **CLI Provider** |
| **Driver** | Subprocess (CLI) |
| **Env Var** | None (uses its own provider env vars) |
| **Binary** | `aider` (must be on PATH) |
| **Key Required** | No (uses Aider's own auth) |
| **Free Tier** | Depends on Aider's configured backend |

**Setup:**
1. Install Aider: `pip install aider-install && aider-install`
2. Configure Aider's LLM provider via its own env vars (e.g. `OPENAI_API_KEY`)
3. No additional LibreFang configuration needed

**Notes:** CLI Provider — LibreFang spawns the `aider` binary as a subprocess in non-interactive mode (`--message`). Aider handles its own LLM provider authentication via standard environment variables (`OPENAI_API_KEY`, `ANTHROPIC_API_KEY`, etc.). Aider's `--yes-always`, `--no-auto-commits`, and `--no-git` flags are applied automatically. Use `AIDER_CLI_PATH` to override the binary path.

---

## Claude Code CLI

| | |
|---|---|
| **Display Name** | Claude Code CLI |
| **Type** | **CLI Provider** |
| **Driver** | Subprocess (CLI) |
| **Env Var** | None (uses its own OAuth session) |
| **Binary** | `claude` (must be on PATH) |
| **Key Required** | No (uses Claude Code's own session auth) |
| **Free Tier** | Depends on Claude Code subscription |

**Setup:**
1. Install Claude Code: `npm install -g @anthropic-ai/claude-code`
2. Authenticate: `claude auth login`
3. No additional LibreFang configuration needed

**Notes:** CLI Provider — LibreFang spawns the `claude` binary as a subprocess in print mode (`-p`). The driver strips other providers' API keys from the subprocess environment to prevent leakage. Active subprocess PIDs are tracked and message timeouts (default 5 minutes) prevent hung processes from blocking agents. Vision input is supported via base64-encoded images.

---

## Codex CLI

| | |
|---|---|
| **Display Name** | Codex CLI |
| **Type** | **CLI Provider** |
| **Driver** | Subprocess (CLI) |
| **Env Var** | `OPENAI_API_KEY` (used by the Codex CLI itself) |
| **Binary** | `codex` (must be on PATH) |
| **Key Required** | Yes (OpenAI API key for Codex CLI) |
| **Free Tier** | No |

**Setup:**
1. Install Codex CLI: `npm install -g @openai/codex`
2. `export OPENAI_API_KEY="sk-..."`
3. No additional LibreFang configuration needed

**Notes:** CLI Provider — LibreFang spawns the `codex` binary as a subprocess in quiet mode (`-q`). The driver strips other providers' API keys from the subprocess environment (preserving only `OPENAI_API_KEY` and `CODEX_*` variables). This allows users with Codex CLI installed to use it as an LLM provider without additional configuration.

---

## Gemini CLI

| | |
|---|---|
| **Display Name** | Gemini CLI |
| **Type** | **CLI Provider** |
| **Driver** | Subprocess (CLI) |
| **Env Var** | None (uses Google OAuth by default) |
| **Binary** | `gemini` (must be on PATH) |
| **Key Required** | No (uses Google OAuth) |
| **Free Tier** | Yes (via Google account) |

**Setup:**
1. Install Gemini CLI: `npm install -g @google/gemini-cli`
2. Authenticate: `gemini auth login`
3. No additional LibreFang configuration needed

**Notes:** CLI Provider — LibreFang spawns the `gemini` binary as a subprocess in print mode (`-p`). The driver preserves `GEMINI_*` and `GOOGLE_*` environment variables while stripping other providers' secrets. No separate API key is needed when using Google OAuth authentication.

---

## Qwen Code

| | |
|---|---|
| **Display Name** | Qwen Code |
| **Type** | **CLI Provider** |
| **Driver** | Subprocess (CLI) |
| **Env Var** | None (uses Qwen OAuth by default) |
| **Binary** | `qwen` (must be on PATH) |
| **Key Required** | No (uses Qwen OAuth) |
| **Free Tier** | Yes (via Alibaba Cloud account) |

**Setup:**
1. Install Qwen Code: `npm install -g @alibaba/qwen-code`
2. Authenticate: `qwen auth login`
3. No additional LibreFang configuration needed

**Notes:** CLI Provider — LibreFang spawns the `qwen` binary as a subprocess in print mode (`-p`). The driver preserves `QWEN_*` environment variables while stripping other providers' secrets. Supports streaming JSON output from the Qwen Code CLI. No separate API key is needed when using Qwen OAuth authentication.
