Claude Code Flag Forwarding
Relevant source files
The following files were used as context for generating this wiki page:
Claude Code Flag Forwarding is a core mechanism in the ollacc wrapper that allows users to pass command-line arguments directly to the underlying claude CLI tool while managing environment variables and model selection. The system differentiates between internal management flags (used for ollacc configuration) and external flags intended for the Anthropic SDK.
The launcher acts as a thin intermediary that sets the necessary OpenAI-compatible environment variables for the Ollama Cloud API before executing the final claude command. This ensures that features like --continue or --help can be utilized seamlessly within the ollacc workflow.
Sources: README.md:16-30, README.md:155-163
Architecture and Command Logic
The execution flow of ollacc involves intercepting specific management flags before proceeding to model resolution and final execution. The wrapper utilizes a specific sequence to ensure the environment is correctly provisioned for the claude executable.
Management Flag Interception
Before loading the full configuration or prompting for keys, ollacc checks for specific internal flags. This allows users to reset their state (clearing keys or models) even if the configuration is corrupted or the network is unavailable.
The diagram above illustrates the early interception of management flags to allow state resets.
Sources: lib/flags.sh:8-33, lib/auth.sh:7-13
Environment Provisioning
For claude to correctly route requests to the Ollama Cloud API, ollacc exports three specific environment variables. A critical requirement for this forwarding logic is that ANTHROPIC_API_KEY must be explicitly set to an empty string to prevent the SDK from ignoring the ANTHROPIC_AUTH_TOKEN.
| Environment Variable | Value/Source | Description |
|---|---|---|
ANTHROPIC_BASE_URL | https://ollama.com | The bare host for the Ollama Cloud API. |
ANTHROPIC_AUTH_TOKEN | User's API Key | The Bearer token stored in ~/.ollacc/config. |
ANTHROPIC_API_KEY | "" (Empty) | Must be empty to force the SDK to use the auth token. |
Sources: lib/auth.sh:50-55, README.md:155-163
Flag Forwarding Implementation
The system supports two methods of passing flags to the claude command. While the -- separator is recommended for safety to avoid collisions with ollacc's own arguments, any trailing arguments are appended to the final execution string.
Forwarding Mechanism
The wrapper ultimately uses the exec command to replace the current shell process with the claude process, appending the resolved model name and all remaining user-provided arguments.
# Example of how flags are forwarded internally
exec claude --model "$MODEL" "$@"
Sources: README.md:92-105, README.md:163
Configuration Management Functions
The following functions in lib/config.sh and lib/flags.sh manage the internal state that determines which flags are processed by the wrapper versus forwarded.
flags_handle(): Processes--model-clearand--key-clear. It returns1if no management flag is found, signaling the orchestrator to continue.config_unset(): Removes specific keys from the configuration file to reset state.bash_escape(): Ensures that values placed in the configuration (which might be used in command-line arguments) are safe from shell injection.
Sources: lib/flags.sh:8-33, lib/config.sh:45-77
Command Usage Examples
The following table summarizes how different command-line patterns are handled by the flag forwarding system:
| Command | Action | Forwarded to claude |
|---|---|---|
ollacc --model-clear | Internal state reset | None (Exits early) |
ollacc --model my-model | Temporary model override | --model my-model |
ollacc -- --help | Usage help request | --help |
ollacc -- --continue | Session continuation | --continue |
Sources: README.md:92-105, lib/flags.sh:12-32
Summary
Claude Code Flag Forwarding ensures that ollacc remains a transparent wrapper. By intercepting a minimal set of management flags (--model-clear, --key-clear) and strictly managing the environment variable requirements of the Anthropic SDK, it allows users to utilize the full feature set of Claude Code while transparently routing requests to the Ollama Cloud API.
Sources: README.md:27-33, lib/auth.sh:50-55