Core Library Structure
Relevant source files
The following files were used as context for generating this wiki page:
The ollacc core library consists of a modular set of Shell scripts located in the lib/ directory. These modules provide the foundational logic for configuration management, authentication with Ollama Cloud, model catalog resolution, and user interface menus. The library is designed to allow the claude CLI to interact directly with the Ollama Cloud API by managing environment variables and model selection.
Sources: README.md:20-30, install.sh:42-46
Architecture and Module Overview
The project follows a modular architecture where specific responsibilities are delegated to separate shell scripts. These scripts are sourced by the main launcher to provide a cohesive runtime environment.
| Module | Purpose | Key Responsibilities |
|---|---|---|
config.sh | Configuration I/O | Reading/writing to ~/.ollacc/config, string escaping. |
auth.sh | Authentication | Loading tokens, prompting for API keys, exporting SDK environment. |
catalog.sh | Model Discovery | Fetching auth'd models and scraping popular models from ollama.com. |
menu.sh | User Interface | Rendering model selection menus and handling user input. |
flags.sh | Command Handling | Processing administrative flags like --model-clear. |
Sources: lib/config.sh:1, lib/auth.sh:1, lib/catalog.sh:1, lib/menu.sh:1, lib/flags.sh:1
Execution Flow
The following diagram illustrates how the core library modules interact during a standard execution flow.
The system ensures that authentication is established before attempting to resolve the model catalog or presenting the user interface.
Sources: lib/flags.sh:10-25, lib/auth.sh:20-40, lib/catalog.sh:22-30
Configuration Management (config.sh)
The configuration system manages the ~/.ollacc/config file. It uses a key-value pair format compatible with Shell sourcing. A critical feature of this module is bash_escape, which ensures that special characters in API keys or model names do not break the configuration file's structure when it is sourced.
Key Functions
config_set <key> <value>: Writes or replaces a configuration line while preserving comments. It ensures the file haschmod 600permissions.config_unset <key>: Removes a specific key from the configuration file.bash_escape <string>: Escapes characters like\,$,`, and"to make them safe for double-quoted assignments.
Sources: lib/config.sh:14-30, lib/config.sh:40-60
Authentication and Environment (auth.sh)
This module manages the connection to Ollama Cloud. It handles the initial setup of the ANTHROPIC_AUTH_TOKEN and prepares the environment for the Anthropic SDK.
SDK Environment Variables
The library exports specific variables required by the Anthropic SDK to redirect traffic to Ollama:
ANTHROPIC_BASE_URL: Set tohttps://ollama.com.ANTHROPIC_AUTH_TOKEN: The user's Ollama Cloud API key.ANTHROPIC_API_KEY: Explicitly set to an empty string to ensure the SDK uses the Bearer token.
Sources: lib/auth.sh:56-61, README.md:144-155
Model Catalog Resolution (catalog.sh)
The catalog resolution logic identifies which models are available to the user by intersecting the "popular" list on Ollama with the user's authorized catalog.
Resolution Logic
- Authenticated Fetch: Queries
https://ollama.com/api/tagsusing the Bearer token. - Popular Scrape: Scrapes
https://ollama.com/search?c=cloudto determine the current trending order. - Intersection: Filters the popular list to only include models found in the user's authenticated response.
- Fallbacks: If scraping fails, it uses the authenticated list order; if the API is unreachable, it uses a hardcoded list of last-resort defaults (e.g.,
kimi-k2.7-code,minimax-m3).
Sources: lib/catalog.sh:22-77
User Interface and Interaction (menu.sh)
The UI layer handles user selection when a default model is not set or when the user chooses to change models.
Sources: lib/menu.sh:10-30, lib/menu.sh:65-75
Installation and State Management
The installation process sets up the environment and defines the library locations.
| Component | Path | Permissions |
|---|---|---|
| Install Directory | ~/.ollacc/ | 700 |
| Configuration | ~/.ollacc/config | 600 |
| Library Files | ~/.ollacc/lib/* | 644 |
| Launcher | ~/.ollacc/ollacc | 755 |
The install.sh script is idempotent and ensures the ollacc alias is added to the user's shell configuration (.zshrc, .bashrc, etc.).
Sources: install.sh:35-55, install.sh:75-85
Summary
The ollacc core library provides a robust, lightweight framework for routing Claude Code requests to Ollama Cloud. By separating concerns into distinct modules for configuration, authentication, and catalog management, the system maintains a clean interface between the user's local environment and the remote API. Its reliance on standard shell utilities and a local configuration file ensures high portability and security for sensitive API credentials.
Sources: README.md:157-164, lib/auth.sh:10-15