Skip to content

feat(cli): add ogx connect claude command#5877

Merged
cdoern merged 7 commits into
ogx-ai:mainfrom
nathan-weinberg:connect-claude
May 26, 2026
Merged

feat(cli): add ogx connect claude command#5877
cdoern merged 7 commits into
ogx-ai:mainfrom
nathan-weinberg:connect-claude

Conversation

@nathan-weinberg
Copy link
Copy Markdown
Contributor

What does this PR do?

Add a new CLI subcommand that launches Claude Code connected to a running OGX server, handling model discovery, tier mapping, and environment variable configuration automatically. The command probes the server for available LLM models, maps them to Claude's haiku/sonnet/opus tiers, and launches claude with the appropriate ANTHROPIC_BASE_URL and model tier env vars set. Includes --print-env flag for shell integration and per-tier model overrides. Updates Claude Code integration docs to use the new command as the primary quick-start workflow.

Closes #5870

Test Plan

Unit tests added, manual test steps below (non-destructive for those with existing Claude setups)

# Start an OGX server
export OPENAI_API_KEY="your-key"
ogx run starter

# Dry-run with --print-env (no claude process launched)
ogx connect claude --print-env

# Real launch of Claude with OGX
ogx connect claude

Add a new CLI subcommand that launches Claude Code connected to a running
OGX server, handling model discovery, tier mapping, and environment
variable configuration automatically. The command probes the server for
available LLM models, maps them to Claude's haiku/sonnet/opus tiers, and
launches claude with the appropriate ANTHROPIC_BASE_URL and model tier
env vars set. Includes --print-env flag for shell integration and
per-tier model overrides. Updates Claude Code integration docs to use the
new command as the primary quick-start workflow.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Signed-off-by: Nathan Weinberg <[email protected]>
@nathan-weinberg nathan-weinberg marked this pull request as ready for review May 18, 2026 14:52
Copy link
Copy Markdown
Collaborator

@mattf mattf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$ uv run ogx connect claude            
INFO     2026-05-18T15:04:53.726819Z  ogx.cli.connect.claude:135 Connecting to Claude Code                              
         base_url=http://localhost:8321 category=cli haiku=claude-haiku-4-5 models=6 opus=claude-haiku-4-5              
         sonnet=claude-haiku-4-5                                                                                        
 ▐▛███▜▌   Claude Code v2.1.143
▝▜█████▛▘  Haiku 4.5 (1M context) · API Usage Billing
  ▘▘ ▝▝    ~/Documents/Repositories/meta-llama/llama-stack

  Opus 4.7 xhigh is now available! · /model to switch

❯ hello                                                                                                 
  ⎿  Not logged in · Please run /login

✻ Worked for 0s

❯ /model                                                                                                

────────────────────────────────────────────────────────────────────────────────────────────────────────
  Select model
  Switch between Claude models. Applies to this session and future Claude Code sessions. For
  other/previous model names, specify with --model.

  ❯ 1. Default (recommended) ✔  Use the default model (currently Haiku 4.5 (1M context)) · $5/$25 per
                                Mtok
    2. claude-haiku-4-5         Custom Opus model
    3. claude-haiku-4-5         Custom Sonnet model
    4. claude-haiku-4-5         Custom Haiku model

  ○ Effort not supported for Default (recommended)

something is missing

@nathan-weinberg
Copy link
Copy Markdown
Contributor Author

Did it work after you logged in? Maybe we just need to make that a prereq

@mattf
Copy link
Copy Markdown
Collaborator

mattf commented May 18, 2026

Did it work after you logged in? Maybe we just need to make that a prereq

i don't have a login to use. i expect if you're logging in then you aren't using stack.

@nathan-weinberg
Copy link
Copy Markdown
Contributor Author

Did it work after you logged in? Maybe we just need to make that a prereq

i don't have a login to use. i expect if you're logging in then you aren't using stack.

Nope, you can be logged in and not be using Anthropic models

@mattf
Copy link
Copy Markdown
Collaborator

mattf commented May 19, 2026

Did it work after you logged in? Maybe we just need to make that a prereq

i don't have a login to use. i expect if you're logging in then you aren't using stack.

Nope, you can be logged in and not be using Anthropic models

an anthropic account should not be required if we're going to claim you can use claude cli w/ stack

…laude Code gateway auth

ANTHROPIC_API_KEY requires an interactive approval prompt on first use in
Claude Code, which causes "Not logged in" errors for users who haven't
previously authenticated. ANTHROPIC_AUTH_TOKEN is the documented approach
for LLM gateways and proxies — it sends a Bearer token with no approval
flow required.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Signed-off-by: Nathan Weinberg <[email protected]>
@mattf
Copy link
Copy Markdown
Collaborator

mattf commented May 19, 2026

$ uv run ogx connect claude                                             
      Built ogx @ file:///home/matt/Documents/Repositories/meta-llama/llama-stack
Uninstalled 3 packages in 395ms
Installed 3 packages in 380ms
INFO     2026-05-19T22:57:41.784865Z  ogx.cli.connect.claude:135 Connecting to Claude Code                              
         base_url=http://localhost:8321 category=cli haiku=claude-haiku-4-5 models=6 opus=claude-haiku-4-5              
         sonnet=claude-haiku-4-5                                                                                        
 ▐▛███▜▌   Claude Code v2.1.143
▝▜█████▛▘  Haiku 4.5 · API Usage Billing
  ▘▘ ▝▝    ~/Documents/Repositories/meta-llama/llama-stack

❯ /status                                                                                                                                                                                                          

───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
  Settings  Status   Config   Usage   Stats

  Version:             2.1.143
  Session name:        /rename to add a name
  Session ID:          e57f0433-c091-40fa-b7e3-4cdd07277e6e
  cwd:                 /home/matt/Documents/Repositories/meta-llama/llama-stack
  Auth token:          ANTHROPIC_AUTH_TOKEN
  Anthropic base URL:  http://localhost:8321
   
  Model:               opus (claude-haiku-4-5)
  Setting sources:     User settings

❯ /model                                                                                                                                                                                                           

───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
  Select model
  Switch between Claude models. Applies to this session and future Claude Code sessions. For other/previous model names, specify with --model.
                              
    1. Default (recommended)  Use the default model (currently Haiku 4.5 (1M context)) · $5/$25 per Mtok
  ❯ 2. claude-haiku-4-5 ✔     Custom Opus model
    3. claude-haiku-4-5       Custom Sonnet model
    4. claude-haiku-4-5       Custom Haiku model

  ○ Effort not supported for claude-haiku-4-5

❯ hello                                                                                                                                                                                                            

● Hello. What can I help you with?

✻ Sautéed for 3s

that's progress. it's weird that claude-haiku-4-5 is all the models.

consider -

$ ANTHROPIC_BASE_URL=http://localhost:8321 ANTHROPIC_API_KEY=none claude                                                                                  
 ▐▛███▜▌   Claude Code v2.1.145
▝▜█████▛▘  Opus 4.7 · API Usage Billing
  ▘▘ ▝▝    ~/Documents/Repositories/meta-llama/llama-stack

❯ /model                                                                                                                                                                                                           

───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
  Select model
  Switch between Claude models. Applies to this session only. For other/previous model names, specify with --model.
                              
    1. Default (recommended)  Use the default model (currently Opus 4.7 (1M context)) · $5/$25 per Mtok
    2. Sonnet                 Sonnet 4.6 · Best for everyday tasks · $3/$15 per Mtok
    3. Sonnet (1M context)    Sonnet 4.6 for long sessions · $3/$15 per Mtok
    4. Haiku                  Haiku 4.5 · Fastest for quick answers · $1/$5 per Mtok
  ❯ 5. Opus ✔                 Opus 4.7 · Most capable for complex work
                              
  ◉ xHigh effort (default) ←/→ to adjust

@nathan-weinberg
Copy link
Copy Markdown
Contributor Author

it's weird that claude-haiku-4-5 is all the models.

that's probably if no models are specified at launch with the CLI it will set the first available model as the default for all

so a user you can either

  1. use the --model flag to set a model to use for all 3 tiers
  2. go more explicit and set a specific model for one or more tiers
  3. don't specify anything and do your model selection via /models in the Claude TUI

@cdoern
Copy link
Copy Markdown
Collaborator

cdoern commented May 20, 2026

I believe the haiku-4-5 might be due to our internal aliasing in ogx. I don't know if this is something this PR should aim to solve. this looks like its functioning to me.

mattf
mattf previously requested changes May 21, 2026
Copy link
Copy Markdown
Collaborator

@mattf mattf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$ curl -s http://localhost:8321/v1/models | jq -r '.data[].id'
claude-haiku-4-5
claude-sonnet-4-6
claude-opus-4-7

$ uv run ogx connect claude --print-env                    
export ANTHROPIC_BASE_URL=http://localhost:8321
export ANTHROPIC_AUTH_TOKEN=ogx
export ANTHROPIC_DEFAULT_HAIKU_MODEL=claude-haiku-4-5
export ANTHROPIC_DEFAULT_SONNET_MODEL=claude-haiku-4-5
export ANTHROPIC_DEFAULT_OPUS_MODEL=claude-haiku-4-5
unset CLAUDE_CODE_USE_VERTEX
unset ANTHROPIC_VERTEX_PROJECT_ID
unset CLAUDE_CODE_USE_BEDROCK
unset ANTHROPIC_BEDROCK_SESSION_TOKEN

instead of using the first model for all the defaults, what do you think about doing a simple check to populate the default models based on what's available?

Comment thread src/ogx/cli/connect/claude.py
nathan-weinberg and others added 2 commits May 21, 2026 15:47
… claude`

Replace --host/--port with --url to support https and custom ports
without extra flags. Auto-detect haiku/sonnet/opus tier mappings from
available model names instead of defaulting all tiers to the first model.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Signed-off-by: Nathan Weinberg <[email protected]>
Copy link
Copy Markdown
Collaborator

@mattf mattf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking good. one question about the base url.

Comment thread src/ogx/cli/connect/claude.py Outdated
@mattf mattf dismissed their stale review May 26, 2026 01:44

pending others

@franciscojavierarceo franciscojavierarceo added this pull request to the merge queue May 26, 2026
Copy link
Copy Markdown
Collaborator

@cdoern cdoern left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one change but its pretty important

Comment thread src/ogx/cli/connect/claude.py Outdated
@cdoern cdoern removed this pull request from the merge queue due to a manual request May 26, 2026
@cdoern cdoern enabled auto-merge May 26, 2026 13:47
@cdoern cdoern added this pull request to the merge queue May 26, 2026
Merged via the queue into ogx-ai:main with commit 65fb133 May 26, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add ogx connect support for Claude

4 participants