agtok is a tool for centrally managing and switching tokens and base URLs for three common CLIs with a single command: claude-code, gemini-cli, and codex-cli. It supports both interactive TUI and command-line interface (CLI). It manages presets grouped by Agent, supports preview and application, and ensures atomic writes with backups.
# Install
brew tap vaspike/homebrew-agtok && brew install agtok
# Update
brew upgrade agtok- Visit the Releases page
- Download the corresponding release
- Unpacking release
- (macOS, Linux)Execute in a terminal(create a soft link):
# create a soft link sudo ln -sfn "$PWD/agtok" /usr/local/bin/agtok # Or direct cp to `/usr/local/bin/` sudo cp -f "$PWD/agtok" /usr/local/bin
- (Windows) Copy the
agtok.exefile to theC:\Program Files\agtokdirectory
agtok initagtok-
Preset Structure
- Presets are stored by Agent in separate files under
~/.config/token-switcher/presets/ - Example (
claude.json):
{ "version": 1, "presets": [ { "alias": "dev", "url": "https://...", "token": "sk-...", "model": "sonnet", "added_at": "20251031-0945" } ]}- In the TUI, press
pto display the preset directory path in the top Status bar.
- Presets are stored by Agent in separate files under
-
Initialize Presets
- TUI: In an Agent table, press
ito generate a preset from the current disk configuration (default aliassnap-default, automatically adds a timestamp if name conflicts); automatic deduplication. - CLI:
agtok init [--agent <id>] [--alias <name>]
- TUI: In an Agent table, press
-
Add Presets
- TUI: Press
ato open the form (URL is required, Alias can be empty, Token is optional), press Enter to save. - CLI:
agtok presets add --agent <id> [--alias <name>] --url <u> [--token <t>]
- TUI: Press
-
Update Presets (TUI)
- TUI: Select a row and press
uto update fields. URL left blank = unchanged; Token-= clear (preset only); blank = unchanged; for Claude, Model empty = clear, non-empty = set. - If updating the active row, Claude's Model on disk is strictly mirrored: empty removes
ANTHROPIC_MODEL, non-empty writes/overwrites. Other agents update presets only.
- TUI: Select a row and press
-
Apply Presets to Agent Configuration
- TUI: Select a preset and press
Enter; writes are atomic with backups, permissions 0600; Claude only writesANTHROPIC_AUTH_TOKEN. - Claude Model: applying a Claude preset mirrors
ANTHROPIC_MODELon disk; if the preset has no model value, the key is removed; if it has a value, the key is written/overwritten. - CLI:
agtok apply --agent <id> --alias <name> [--dry-run]oragtok apply --agent <id> --url <u> [--token <t>]
- TUI: Select a preset and press
-
Rename/Delete Presets
- TUI:
eto rename (validates uniqueness and format),dto delete (requires secondary confirmation); the active row cannot be deleted.
- TUI:
-
Version Detection
- TUI: The first column of each Agent's active row displays the version number;
Not installedis shown if not installed,Unknownif parsing fails. - Detection commands:
claude -v/gemini -v/codex -V; asynchronous backfill, cached for 60s. Gemini detection allows a slightly longer timeout.
- TUI: The first column of each Agent's active row displays the version number;
-
Status Bar & Details
- Top bar shows
agtok <version>and a colored Status (green for OK, red for errors). Presspto show the presets dir path in Status. - Details panel shows the selected row; for Claude,
Modelis displayed and(not set)appears in muted color when empty.
- Top bar shows
-
Running Modes
- TUI: Run
agtokwithout parameters to enter TUI; or explicitlyagtok tui. - CLI: Effective when subcommand and parameters are passed (list/apply/presets/init).
- TUI: Run
-
Claude-code (agent id:
claude)- Path:
~/.claude/settings.json - Keys: Reads
env.ANTHROPIC_AUTH_TOKEN/_API_TOKEN/_API_KEY; only writes_AUTH_TOKEN.
- Path:
-
Gemini-cli (agent id:
gemini)- Path:
~/.gemini/.env - Keys:
GOOGLE_GEMINI_BASE_URL,GEMINI_API_KEY.
- Path:
-
Codex-cli (agent id:
codex)- Path:
~/.codex/config.toml(model_providers.codex.base_url),~/.codex/auth.json(OPENAI_API_KEY).
- Path:
- macOS, Linux: Fully supported (TUI/CLI, preset persistence, version detection, atomic writes).
- Windows: Planned support.
