[PR #10451] feat: create and expose model-id environment variables for bash from CLI #13444

Closed
opened 2026-02-16 18:18:18 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/10451

State: closed
Merged: No


This PR adds environment variables that are available when running shell commands through opencode (both the BashTool and the ! command).

Fixes #10453
Fixes #10247
Fixes #6350
Fixes #9065
Fixes #9292
Fixes #7492

  • OPENCODE_MODEL_NAME: Human-readable model name (e.g., 'GPT-5.2')
  • OPENCODE_MODEL_ID: Provider's internal model ID (e.g., 'gpt-5.2' or 'openai/gpt-5.2')
  • OPENCODE_CANONICAL_MODEL_ID: Normalized model ID without provider prefix (e.g., 'gpt-5.2')
  • OPENCODE_PROVIDER_ID: Provider routing to the model (e.g., 'openai', 'opencode', 'openrouter')
  • OPENCODE_MODEL_FULL_ID: Combined provider/model identifier (e.g., 'openai/gpt-5.2')

Example values

GPT 5.2 via OpenAI auth

  • OPENCODE_MODEL_NAME: 'GPT-5.2'
  • OPENCODE_MODEL_ID: 'gpt-5.2'
  • OPENCODE_CANONICAL_MODEL_ID: 'gpt-5.2'
  • OPENCODE_PROVIDER_ID: 'openai'
  • OPENCODE_MODEL_FULL_ID: 'openai/gpt-5.2'

GPT 5.2 via Opencode Zen

  • OPENCODE_MODEL_NAME: 'GPT-5.2'
  • OPENCODE_MODEL_ID: 'gpt-5.2'
  • OPENCODE_CANONICAL_MODEL_ID: 'gpt-5.2'
  • OPENCODE_PROVIDER_ID: 'opencode'
  • OPENCODE_MODEL_FULL_ID: 'opencode/gpt-5.2'

GPT 5.2 via Openrouter

  • OPENCODE_MODEL_NAME: 'GPT-5.2'
  • OPENCODE_MODEL_ID: 'openai/gpt-5.2'
  • OPENCODE_CANONICAL_MODEL_ID: 'gpt-5.2'
  • OPENCODE_PROVIDER_ID: 'openrouter'
  • OPENCODE_MODEL_FULL_ID: 'openrouter/openai/gpt-5.2'

Use case

I have shell scripts and other code run inside opencode (agents, skills, and tools) that need to be aware of which model the user has selected, for model-aware workflows. I also want to be able to compare content generated by different models, and include model id / name in frontmatter.

Shell scripts run via opencode (for example, from agents, skills, and tools) can now access information about which model and provider are being used, enabling model-aware workflows.

Files modified

  • src/tool/bash.ts
  • src/pty/index.ts
  • src/session/prompt.ts

There is a human here

I am an advanced-beginner programmer at best and way over my head messing with opencode itself. I used opencode w/ GPT5.2 to code this. I did eyeball the code, it looks reasonably simple, but I have no idea really and there may well be a better way--but this did give me the solution I was looking for. Very open to input!

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/10451 **State:** closed **Merged:** No --- This PR adds environment variables that are available when running shell commands through opencode (both the BashTool and the ! command). Fixes #10453 Fixes #10247 Fixes #6350 Fixes #9065 Fixes #9292 Fixes #7492 - `OPENCODE_MODEL_NAME`: Human-readable model name (e.g., 'GPT-5.2') - `OPENCODE_MODEL_ID`: Provider's internal model ID (e.g., 'gpt-5.2' or 'openai/gpt-5.2') - `OPENCODE_CANONICAL_MODEL_ID`: Normalized model ID without provider prefix (e.g., 'gpt-5.2') - `OPENCODE_PROVIDER_ID`: Provider routing to the model (e.g., 'openai', 'opencode', 'openrouter') - `OPENCODE_MODEL_FULL_ID`: Combined provider/model identifier (e.g., 'openai/gpt-5.2') ## Example values ### GPT 5.2 via OpenAI auth - `OPENCODE_MODEL_NAME`: 'GPT-5.2' - `OPENCODE_MODEL_ID`: 'gpt-5.2' - `OPENCODE_CANONICAL_MODEL_ID`: 'gpt-5.2' - `OPENCODE_PROVIDER_ID`: 'openai' - `OPENCODE_MODEL_FULL_ID`: 'openai/gpt-5.2' ### GPT 5.2 via Opencode Zen - `OPENCODE_MODEL_NAME`: 'GPT-5.2' - `OPENCODE_MODEL_ID`: 'gpt-5.2' - `OPENCODE_CANONICAL_MODEL_ID`: 'gpt-5.2' - `OPENCODE_PROVIDER_ID`: 'opencode' - `OPENCODE_MODEL_FULL_ID`: 'opencode/gpt-5.2' ### GPT 5.2 via Openrouter - `OPENCODE_MODEL_NAME`: 'GPT-5.2' - `OPENCODE_MODEL_ID`: 'openai/gpt-5.2' - `OPENCODE_CANONICAL_MODEL_ID`: 'gpt-5.2' - `OPENCODE_PROVIDER_ID`: 'openrouter' - `OPENCODE_MODEL_FULL_ID`: 'openrouter/openai/gpt-5.2' ## Use case I have shell scripts and other code run inside opencode (agents, skills, and tools) that need to be aware of which model the user has selected, for model-aware workflows. I also want to be able to compare content generated by different models, and include model id / name in frontmatter. Shell scripts run via opencode (for example, from agents, skills, and tools) can now access information about which model and provider are being used, enabling model-aware workflows. ## Files modified - src/tool/bash.ts - src/pty/index.ts - src/session/prompt.ts ## There is a human here I am an advanced-beginner programmer at best and way over my head messing with opencode itself. I used opencode w/ GPT5.2 to code this. I did eyeball the code, it looks reasonably simple, but I have no idea really and there may well be a better way--but this did give me the solution I was looking for. Very open to input!
yindo added the pull-request label 2026-02-16 18:18:18 -05:00
yindo closed this issue 2026-02-16 18:18:18 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#13444