Skip to content

feat(opencode): add dynamic configuration and context discovery for LM Studio#15732

Open
TrentPierce wants to merge 4 commits intoanomalyco:devfrom
TrentPierce:dev
Open

feat(opencode): add dynamic configuration and context discovery for LM Studio#15732
TrentPierce wants to merge 4 commits intoanomalyco:devfrom
TrentPierce:dev

Conversation

@TrentPierce
Copy link

Issue for this PR

Closes #
#6231
#2456
#11141
#4232
Possibly many others related to LMStudio.

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

This PR improves the LM Studio provider integration by allowing users to specify a custom server address and automatically discover their loaded model and context limits.

  • Configurable Base URL: Added a prompt during auth login to override the default LM Studio server address (e.g., for users running on different ports or remote machines).

  • Dynamic Context Discovery: The LMStudio loader now queries /v1/models to fetch the max_context_length and automatically configures model limits.

  • Improved Stability: Added an 8k token floor for context and a warning if a model is configured with less than 32k tokens (which can cause issues with OpenCode's system prompt).

How did you verify your code works?

  • Discovery: Ran opencode models --provider lmstudio --verbose and confirmed that max_context_length from LM Studio correctly populated the model's limit.context.

  • Connectivity: Verified that auth login correctly saves and uses a custom baseURL in auth.json.

  • Inference: Ran a test prompt using opencode run --model lmstudio/ to ensure the combined system prompt and user query fit within the dynamically discovered context window.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@nilswx
Copy link

nilswx commented Mar 3, 2026

Great, thank you! This feature is long overdue. Manually configuring local models and their capabilities, variants, etc is nuts. Automatic discovery is far better for most use cases.

@TrentPierce
Copy link
Author

Great, thank you! This feature is long overdue. Manually configuring local models and their capabilities, variants, etc is nuts. Automatic discovery is far better for most use cases.

Thank you! I have developed a few tools for LMStudio, so I was surprised to see it not working well with OpenCode. This pull request was tested with the latest version of LMStudio. There are many more metrics we can discover automatically if needed in the future as well.

@danielcherubini
Copy link

Oh wow this is amazing

@TrentPierce
Copy link
Author

Oh wow this is amazing

Thank you! I'm looking forward to trying some of the new Qwen models in OpenCode.

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.

3 participants