# Settings

This page lists all built-in settings for the **Bub app layer**. The core `bub.core.Agent` class does not read YAML files or `BUB_*` environment variables (it takes constructor arguments only). Third-party plugins can register their own configuration sections; see each plugin's documentation. For initial setup steps, see [Configuration](/docs/app/configure/).

## Precedence {#precedence}

Settings classes resolve fields in this order (highest priority first):

| Priority | Source | Description |
| --- | --- | --- |
| 1 | Environment variables | `BUB_*`; read when the settings class is instantiated |
| 2 | `.env` in current directory | `find_dotenv(usecwd=True)`; does not override existing system environment variables |
| 3 | YAML config file | `<BUB_HOME>/config.yml` (default `~/.bub/config.yml`), loaded via `configure.load` |
| 4 | Field defaults | Default values declared in code |

- `--workspace`, `--project`, and `--enable-channel` are **CLI flags**, not settings fields.
- Settings instances are cached process-wide. Modifying `os.environ` after `ensure_config()` has been called will not update cached instances; restart the process to apply changes.

## Config file and runtime paths {#config-file}

| Path / Variable | Default | Description |
| --- | --- | --- |
| `<BUB_HOME>/config.yml` | `~/.bub/config.yml` | Default YAML config file (override via `BubFramework(config_file=Path(...))`) |
| `BUB_HOME` | `~/.bub` | Configuration and runtime data directory (stores `config.yml`, session Tapes, managed plugin project, and temporary code-mode files) |
| `BUB_PROJECT` | `<BUB_HOME>/bub-project` | Managed plugin project directory for `bub install` / `uninstall` / `update` (created automatically at the default path; custom paths must already exist) |

## Environment variable index {#env-index}

Every YAML setting has a corresponding environment variable (all `BUB_*` variables can be placed in `.env`):

| Variable | Default | YAML path | Section |
| --- | --- | --- | --- |
| `BUB_HOME` | `~/.bub` | — | [Runtime paths](#config-file) |
| `BUB_PROJECT` | `<BUB_HOME>/bub-project` | — | [Runtime paths](#config-file) |
| `BUB_MODEL` | `openrouter:openrouter/free` | `model` | [AgentSettings](#agent-settings) |
| `BUB_COMMAND_PREFIX` | `,` | `command_prefix` | [Command prefix](#command-prefix) |
| `BUB_FALLBACK_MODELS` | `null` | `fallback_models` | [Models and fallback](#model-routing) |
| `BUB_API_KEY` | unset | `api_key` | [Credential resolution](#credentials) |
| `BUB_API_BASE` | unset | `api_base` | [Credential resolution](#credentials) |
| `BUB_<PROVIDER>_API_KEY` | unset | — | [Credential resolution](#credentials) |
| `BUB_<PROVIDER>_API_BASE` | unset | — | [Credential resolution](#credentials) |
| `BUB_PROVIDERS` | `{}` | `providers` | [Custom providers](#custom-providers) |
| `BUB_MAX_STEPS` | `sys.maxsize` | `max_steps` | [AgentSettings](#agent-settings) |
| `BUB_MAX_TOKENS` | `16384` | `max_tokens` | [AgentSettings](#agent-settings) |
| `BUB_SUBAGENT_MAX_CONCURRENCY` | `4` | `subagent_max_concurrency` | [AgentSettings](#agent-settings) |
| `BUB_SUBAGENT_TIMEOUT_SECONDS` | `null` | `subagent_timeout_seconds` | [AgentSettings](#agent-settings) |
| `BUB_MODEL_TIMEOUT_SECONDS` | `null` | `model_timeout_seconds` | [AgentSettings](#agent-settings) |
| `BUB_CLIENT_ARGS` | `{}` | `client_args` | [`client_args`](#client-args) |
| `BUB_COMPLETION_ARGS` | `{}` | `completion_args` | [`completion_args`](#completion-args) |
| `BUB_VERBOSE` | `0` | `verbose` | [AgentSettings](#agent-settings) |
| `BUB_ENABLED_CHANNELS` | `all` | `enabled_channels` | [ChannelSettings](#channel-settings) |
| `BUB_DEBOUNCE_SECONDS` | `1.0` | `debounce_seconds` | [ChannelSettings](#channel-settings) |
| `BUB_MAX_WAIT_SECONDS` | `10.0` | `max_wait_seconds` | [ChannelSettings](#channel-settings) |
| `BUB_ACTIVE_TIME_WINDOW` | `60.0` | `active_time_window` | [ChannelSettings](#channel-settings) |
| `BUB_STREAM_OUTPUT` | `false` | `stream_output` | [ChannelSettings](#channel-settings) |
| `BUB_SPILL_THRESHOLD` | `4096` | `spill.threshold` | [SpillSettings](#spill-settings) |
| `BUB_TELEGRAM_TOKEN` | `""` | `telegram.token` | [TelegramSettings](#telegram-settings) |
| `BUB_TELEGRAM_ALLOW_USERS` | unset | `telegram.allow_users` | [TelegramSettings](#telegram-settings) |
| `BUB_TELEGRAM_ALLOW_CHATS` | unset | `telegram.allow_chats` | [TelegramSettings](#telegram-settings) |
| `BUB_TELEGRAM_PROXY` | unset | `telegram.proxy` | [TelegramSettings](#telegram-settings) |
| `CODEX_HOME` | `~/.codex` | — | [Third-party login](#login-env) |

## AgentSettings {#agent-settings}

Defined in `src/bub/builtin/settings.py` (top-level YAML fields):

```python
@config()
class AgentSettings(Settings):
    model_config = SettingsConfigDict(
        env_prefix="BUB_",
        env_parse_none_str="null",
        extra="ignore",
    )
    model: str = "openrouter:openrouter/free"
    command_prefix: str = ","
    fallback_models: list[str] | None = None
    api_key: str | dict[str, str] | None = None
    api_base: str | dict[str, str] | None = None
    providers: dict[str, CustomProvider] = {}
    max_steps: int = sys.maxsize
    max_tokens: int = 16384
    subagent_max_concurrency: int = 4
    subagent_timeout_seconds: int | None = None
    model_timeout_seconds: int | None = None
    client_args: dict[str, Any] = {}
    completion_args: dict[str, Any] = {}
    verbose: int = 0
```

| Environment variable | Default | YAML key | Description |
| --- | --- | --- | --- |
| `BUB_MODEL` | `openrouter:openrouter/free` | `model` | Model identifier (`provider:model`) |
| `BUB_COMMAND_PREFIX` | `,` | `command_prefix` | Direct command prefix (non-empty, no whitespace) |
| `BUB_FALLBACK_MODELS` | `null` | `fallback_models` | Fallback model list (JSON array in env vars); applies only to the default primary model |
| `BUB_API_KEY` | unset | `api_key` | Global API key string, or provider-to-key mapping dict |
| `BUB_API_BASE` | unset | `api_base` | Global API base URL string, or provider-to-URL mapping dict |
| `BUB_<PROVIDER>_API_KEY` | unset | — | Provider-specific API key (e.g. `BUB_OPENAI_API_KEY`) |
| `BUB_<PROVIDER>_API_BASE` | unset | — | Provider-specific API base URL (e.g. `BUB_OPENROUTER_API_BASE`) |
| `BUB_PROVIDERS` | `{}` | `providers` | Custom provider definitions (JSON object in env vars) |
| `BUB_MAX_STEPS` | `sys.maxsize` | `max_steps` | Maximum model Steps per Run (positive integer) |
| `BUB_MAX_TOKENS` | `16384` | `max_tokens` | Default max output tokens per model call (omitted for `codex:` models) |
| `BUB_SUBAGENT_MAX_CONCURRENCY` | `4` | `subagent_max_concurrency` | Maximum concurrent [subagents](/docs/app/subagents/) per process |
| `BUB_SUBAGENT_TIMEOUT_SECONDS` | `null` | `subagent_timeout_seconds` | Default timeout in seconds for a subagent run (`null` means no limit) |
| `BUB_MODEL_TIMEOUT_SECONDS` | `null` | `model_timeout_seconds` | Timeout in seconds for one model call (including streaming) |
| `BUB_CLIENT_ARGS` | `{}` | `client_args` | Extra kwargs passed to the model client constructor (JSON object) |
| `BUB_COMPLETION_ARGS` | `{}` | `completion_args` | Extra kwargs passed to each model generation call (JSON object) |
| `BUB_VERBOSE` | `0` | `verbose` | Log level: `0` (INFO), `1` (DEBUG), `2` (TRACE) |

### Command prefix {#command-prefix}

| `command_prefix` | Example |
| --- | --- |
| `,` (default) | `,help` and `,tape.info` are direct commands |
| `!` | `!help` is a direct command; `,help` is ordinary text |
| `/` | In Telegram, invoke via `/bub /help` |

### Credential resolution {#credentials}

For each model call, Bub resolves the first non-empty `api_key` and `api_base` in this order:

1. `providers.<name>.api_key` and `providers.<name>.api_base` (custom providers);
2. The provider entry in the `api_key` / `api_base` mapping (`BUB_<PROVIDER>_API_KEY` and `BUB_<PROVIDER>_API_BASE` scanned at startup populate this mapping with lower priority than explicit `BUB_API_KEY` / `BUB_API_BASE` and YAML values), or the string value if `api_key` / `api_base` is a plain string;
3. Standard provider environment variables without the `BUB_` prefix (such as `OPENAI_API_KEY` or `OPENROUTER_API_KEY`).

:::caution
Setting `BUB_API_KEY` / `BUB_API_BASE` (or YAML `api_key` / `api_base`) to a **single string** applies that string to every provider, overriding per-provider mappings and step-3 fallbacks. When using multiple providers (e.g., primary on OpenAI and fallback on OpenRouter), use a mapping or `BUB_<PROVIDER>_API_KEY`.
:::

### Models and fallback {#model-routing}

Common `BUB_MODEL` prefixes (see [Republic providers](https://getrepublic.org/providers/) for the full list):

| Prefix | Provider |
| --- | --- |
| `openai:` | OpenAI or any OpenAI-compatible endpoint |
| `codex:` / `grok:` / `github-copilot:` | Account credentials configured via `bub login` |
| `openrouter:` | OpenRouter |
| `anthropic:` / `google:` / `azure-openai:` | Native provider APIs |
| `ollama:` / `magpie:` | Local model servers |

`fallback_models` applies only when the active model matches the default `model` setting (it is skipped when `model=` is passed in code or after switching models with `,model`). Fallbacks are tried in order only when **connecting or opening the request stream fails**; errors after streaming has started do not retry on another model.

### `client_args` and `completion_args` {#client-args}

Common `client_args` keys:

| Key | Description |
| --- | --- |
| `headers` | Shared by all providers. Overrides the default `User-Agent: bub/<version>`; [provider-specific headers](#custom-providers) take precedence. |
| `api_format` | Set to `"chat"` for OpenAI-compatible `/v1/chat/completions` endpoints |
| `timeout` / `max_retries` | HTTP client request timeout and retry count (overall call timeout is controlled by `model_timeout_seconds`) |

<a id="completion-args"></a>

Common `completion_args` keys (call-level `options` override matching keys):

| Key | Description |
| --- | --- |
| `max_tokens` | Defaults to `BUB_MAX_TOKENS` when unset (omitted for `codex:` calls) |
| `reasoning_effort` | Overridden by session `,reasoning_effort` or call-level `options` |
| `extra_body` | Passed through to the provider request body |

### Custom providers (`providers`) {#custom-providers}

Define custom provider prefixes under `providers` when connecting to multiple endpoints that share the same protocol (such as internal gateways or relays):

```yaml
model: proxy:gpt-5.5
fallback_models:
  - openai:gpt-5.5
  - relay:claude-sonnet-5
providers:
  proxy:
    type: openai
    api_base: https://llm-proxy.example.com/v1
    api_key: sk-proxy-...
  relay:
    type: anthropic
    api_base: https://relay.example.com
    api_key: sk-relay-...
```

| Field | Required | Description |
| --- | --- | --- |
| `type` | Yes | Underlying Republic provider protocol name (e.g. `openai`, `anthropic`) |
| `api_base` | No | Endpoint URL; falls back to `api_base` mapping or `BUB_<NAME>_API_BASE` |
| `api_key` | No | Endpoint API key; falls back to `api_key` mapping or `BUB_<NAME>_API_KEY` |
| `headers` | No | Request headers for this provider name only. Overrides matching `client_args.headers` and the default `User-Agent`, ignoring case. |

Set [OpenRouter app attribution](https://openrouter.ai/docs/app-attribution) for the `openrouter:` prefix:

```yaml
providers:
  openrouter:
    type: openrouter
    headers:
      HTTP-Referer: https://example.com
      X-OpenRouter-Title: Example App
```

## ChannelSettings {#channel-settings}

Defined in `src/bub/channels/manager.py` (top-level YAML fields):

| Environment variable | Default | YAML key | Description |
| --- | --- | --- | --- |
| `BUB_ENABLED_CHANNELS` | `all` | `enabled_channels` | Channels to enable (comma-separated names, `all`, or `!name` exclusions; see [CLI channel selection](/docs/reference/cli/#channel-selection)) |
| `BUB_DEBOUNCE_SECONDS` | `1.0` | `debounce_seconds` | Debounce wait timer reset after each active message |
| `BUB_MAX_WAIT_SECONDS` | `10.0` | `max_wait_seconds` | Max wait seconds when buffering unmentioned follow-up messages in a group |
| `BUB_ACTIVE_TIME_WINDOW` | `60.0` | `active_time_window` | Seconds after an active message during which unmentioned group messages join the current batch |
| `BUB_STREAM_OUTPUT` | `false` | `stream_output` | Push streaming events to gateway channels (`bub chat` always forces `true`) |

<a id="channel-selection"></a>

Debouncing applies only to channels with `needs_debounce=True` (such as Telegram).

## TelegramSettings {#telegram-settings}

Defined in `src/bub/channels/telegram.py` (under `telegram:` in YAML):

| Environment variable | Default | YAML key | Description |
| --- | --- | --- | --- |
| `BUB_TELEGRAM_TOKEN` | `""` | `token` | Telegram bot token; enables the Telegram channel when non-empty |
| `BUB_TELEGRAM_ALLOW_USERS` | unset | `allow_users` | Allowed numeric user IDs or usernames (comma-separated; empty allows all) |
| `BUB_TELEGRAM_ALLOW_CHATS` | unset | `allow_chats` | Allowed chat/group IDs (comma-separated; empty allows all) |
| `BUB_TELEGRAM_PROXY` | unset | `proxy` | HTTP or SOCKS5 proxy URL (e.g. `http://127.0.0.1:7890` or `socks5://host:port`) |

See [Gateway: Configure Telegram](/docs/app/gateway/#configure-telegram) for allowlist and group-chat rules.

## SpillSettings {#spill-settings}

Defined in `src/bub/builtin/spill.py` (under `spill:` in YAML):

| Environment variable | Default | YAML key | Description |
| --- | --- | --- | --- |
| `BUB_SPILL_THRESHOLD` | `4096` | `threshold` | Estimated token threshold (4 chars ≈ 1 token) for spilling large tool outputs (`0` disables new spills; must be `>= 0`) |

When a tool output exceeds this threshold and `spill.read` is available, the full text is written to the `spill` sidecar and the model receives a short preview and handle (`spill.read` outputs are not spilled again).

## Third-party login variables {#login-env}

| Variable | Default | Description |
| --- | --- | --- |
| `CODEX_HOME` | `~/.codex` | Directory storing `auth.json` for `bub login codex` (overridable via `--codex-home`) |

## Session-persisted settings {#session-settings}

These three settings are modified via comma commands inside a session and stored in the session Tape (taking effect on the **next Turn** and persisting across restarts):

| Setting | Command (default prefix `,`) | Effect |
| --- | --- | --- |
| `model` | `,model openai:gpt-5.5` | Overrides the session model (`fallback_models` does not apply when switched away from the default model) |
| `reasoning_effort` | `,reasoning_effort high` | Overrides reasoning effort for the session |
| `code_mode` | `,code_mode enable=true` | Enables or disables code mode for the session |

## Plugin custom settings {#plugin-settings}

Plugins can register their own settings classes with `@config`:

```python
from pydantic_settings import SettingsConfigDict
from bub import Settings, config

@config(name="orders")
class OrderSettings(Settings):
    model_config = SettingsConfigDict(
        env_prefix="BUB_ORDERS_",
        extra="ignore",
    )
    timeout: int = 30
```

- `@config(name="x")` reads from the top-level `x:` section in `config.yml`; `@config()` reads from the YAML root.
- Call `ensure_config(OrderSettings)` to get the process-cached instance.
- `bub.configure` provides `load(path)`, `get_config_data()`, `merge(base, *updates)`, `save(path, data)`, `validate()`, and `get_value(path, default)`.

## Full configuration file example {#example}

Every field except `model` is optional:

```yaml title="~/.bub/config.yml"
model: openrouter:openrouter/free
command_prefix: ","
fallback_models:
  - openai:gpt-5.5
api_key:
  openrouter: sk-or-...
api_base:
  openrouter: https://openrouter.ai/api/v1
providers:
  proxy:
    type: openai
    api_base: https://llm-proxy.example.com/v1
    api_key: "your-provider-api-key"
max_steps: 100
max_tokens: 16384
subagent_max_concurrency: 4
subagent_timeout_seconds: 600
model_timeout_seconds: 120
client_args:
  timeout: 60
  max_retries: 2
completion_args:
  reasoning_effort: medium
verbose: 0

enabled_channels: all
debounce_seconds: 1.0
max_wait_seconds: 10.0
active_time_window: 60.0
stream_output: false

spill:
  threshold: 4096

telegram:
  token: "your-telegram-bot-token"
  allow_users: "123456789,your_username"
  allow_chats: "-1001234567890"
  proxy: socks5://127.0.0.1:7890
```