Skip to content

Conversation

@IgorWarzocha
Copy link
Owner

Summary

Add first-class support for ZAI/GLM models (GLM-4.7) as a new provider with Anthropic-compatible API.

Features

  • Add zai-coding-plan provider with GLM-4.7 model
  • Automatic Anthropic SDK selection (fixes models.dev cache using wrong SDK)
  • Thinking variants selectable via Ctrl+T:
    • none: disabled
    • low: 4k tokens
    • medium: 12k tokens (default: 8k)
    • high: 24k tokens
    • max: 64k tokens
  • Add GLM-specific system prompt
  • Add ZAI to auth menu for easy API key configuration

Technical Changes

  • models.ts: Override npm to @ai-sdk/anthropic and inject thinking config for zai-coding-plan
  • provider.ts: Merge model variants from ModelsDev into provider variants
  • auth.ts: Add zai-coding-plan to auth menu with helpful prompts
  • system.ts: Add GLM prompt selection
  • glm.txt: Comprehensive system prompt for GLM models

Files Changed

  • packages/opencode/src/cli/cmd/auth.ts
  • packages/opencode/src/provider/models.ts
  • packages/opencode/src/provider/provider.ts
  • packages/opencode/src/session/index.ts
  • packages/opencode/src/session/prompt/glm.txt
  • packages/opencode/src/session/system.ts

- Add GLM system prompt (session/prompt/glm.txt)
- Update session/system.ts to route GLM models to the new prompt
- Update session/index.ts to extract token usage from metadata (fixes ZAI/Anthropic token counting)
- Add zai-coding-plan to provider priority list
- Add GLM hint to auth selection
- Add specific prompt instructions for ZAI API key
- Add zai-coding-plan to CUSTOM_LOADERS in provider.ts with correct baseURL
- Inject default zai-coding-plan provider definition in models.ts for CLI visibility
- Implement rigorous system prompt for GLM models
- Add 'Ambition vs Precision' heuristic from Codex
- Add detailed workflow from Beast/Anthropic
- Add strict XML constraints for steerability (no emojis, no logs)
- Align with agent-architect skill best practices
- Override npm to @ai-sdk/anthropic for zai-coding-plan (fixes SDK selection from cache)
- Add default thinking options (budgetTokens: 8000) for glm-4.7
- Add thinking variants: none, low (4k), medium (12k), high (24k), max (64k)
- Merge model variants from ModelsDev into provider variants
- Minor cleanup: remove redundant type casts in session
@gemini-code-assist
Copy link

Summary of Changes

Hello @IgorWarzocha, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly expands the platform's capabilities by integrating ZAI/GLM models as a new, fully supported provider. It ensures seamless interaction with these models by configuring the appropriate SDK, offering flexible "thinking" token budget options, and providing a specialized system prompt for optimal performance. Additionally, the changes streamline the user experience for setting up ZAI API keys within the application.

Highlights

  • New ZAI/GLM Provider: Introduced first-class support for ZAI/GLM models, specifically GLM-4.7, with an Anthropic-compatible API.
  • Automatic SDK Selection: Implemented automatic selection of the @ai-sdk/anthropic SDK for ZAI/GLM, resolving potential caching issues.
  • Configurable Thinking Variants: Added multiple "thinking" token budget options (none, low, medium, high, max) for GLM models, selectable via Ctrl+T.
  • Dedicated System Prompt: Integrated a specific system prompt (glm.txt) tailored for GLM models to guide their behavior.
  • Auth Menu Integration: Added ZAI to the authentication menu for straightforward API key configuration with helpful prompts.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request adds support for ZAI/GLM models as a new provider. The changes are comprehensive, covering authentication, provider configuration, token usage calculation, and system prompts. The implementation looks solid, particularly the fixes for token counting in session/index.ts and the variant merging logic in provider/provider.ts. I have one suggestion in packages/opencode/src/provider/models.ts to refactor the logic for configuring the new provider, which will improve maintainability and fix a potential logic gap.

Comment on lines 133 to 172
if (parsed["zai-coding-plan"]) {
parsed["zai-coding-plan"].npm = "@ai-sdk/anthropic"
// Inject thinking options and variants for glm-4.7 if it exists in cache
if (parsed["zai-coding-plan"].models["glm-4.7"]) {
parsed["zai-coding-plan"].models["glm-4.7"].options = {
...parsed["zai-coding-plan"].models["glm-4.7"].options,
...glmDefaultOptions,
}
parsed["zai-coding-plan"].models["glm-4.7"].variants = glmVariants
}
} else {
parsed["zai-coding-plan"] = {
id: "zai-coding-plan",
name: "ZAI (GLM)",
env: [],
npm: "@ai-sdk/anthropic",
models: {
"glm-4.7": {
id: "glm-4.7",
name: "GLM 4.7",
release_date: "2025-11-24",
attachment: true,
reasoning: true,
temperature: true,
tool_call: true,
interleaved: true,
cost: {
input: 0,
output: 0,
},
limit: {
context: 200000,
output: 128000,
},
options: glmDefaultOptions,
variants: glmVariants,
},
},
}
}

Choose a reason for hiding this comment

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

medium

The current logic for ensuring the zai-coding-plan provider is correctly configured has some room for improvement:

  1. Code Duplication: The entire definition for the glm-4.7 model is duplicated in the else block. This makes the code harder to maintain, as any updates to the model definition would need to be made in two places.
  2. Potential Logic Flaw: If models.dev returns a zai-coding-plan provider but without the glm-4.7 model, your current if block will not add it. The model configuration is only injected if parsed["zai-coding-plan"].models["glm-4.7"] already exists. The else block, which does create the model, is never reached.

A more robust approach is to ensure the provider and model exist, creating them if necessary, and then applying the overrides. This avoids duplication and fixes the logic gap.

    const providerId = "zai-coding-plan";
    const modelId = "glm-4.7";

    const provider = (parsed[providerId] ??= {
      id: providerId,
      name: "ZAI (GLM)",
      env: [],
      models: {},
    });
    provider.npm = "@ai-sdk/anthropic";

    const model = (provider.models[modelId] ??= {
      id: modelId,
      name: "GLM 4.7",
      release_date: "2025-11-24",
      attachment: true,
      reasoning: true,
      temperature: true,
      tool_call: true,
      interleaved: true,
      cost: { input: 0, output: 0 },
      limit: { context: 200000, output: 128000 },
      options: {},
      variants: {},
    });

    model.options = { ...model.options, ...glmDefaultOptions };
    model.variants = glmVariants;

Address code review feedback:
- Use ??= to reduce duplication
- Fix edge case where provider exists but model is missing
- Cleaner, more maintainable code structure
@IgorWarzocha
Copy link
Owner Author

@codex triple check if pr looks sound after the changes

@chatgpt-codex-connector
Copy link

Codex Review: Didn't find any major issues. Can't wait for the next one!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@IgorWarzocha IgorWarzocha changed the base branch from dev to howcode January 3, 2026 10:23
@IgorWarzocha
Copy link
Owner Author

/opencode verify all of this is sound. check for DRY, no excessive console logs and comments. I know for a fact it does something to models.dev.json or whatever it is called, so the changes seem to persist even when switching to upstream release build. Can you confirm/deny. And will models.dev cache get refreshed when they update the remote database?

@opencode-agent
Copy link

opencode-agent bot commented Jan 3, 2026

Analysis Complete

✅ DRY Principle

Code is DRY - uses ??= operator to only create provider/model if missing. No unnecessary duplication.

✅ Console Logs

Minimal and appropriate - only in refresh() at models.ts:166-168 for debugging cache refresh.

✅ Comments

Minimal - only 2 lines (models.ts:92-93) explaining ZAI Anthropic compatibility.

🔍 models.dev.json Behavior

DENIED: Changes do NOT persist to cache file

How it works:

  1. get() calls refresh() (models.ts:79)
  2. refresh() ONLY writes to cache when successful fetch from remote API (models.ts:179: if (result && result.ok))
  3. ZAI/GLM modifications happen in-memory on parsed object (models.ts:134-158) after reading cache
  4. Modifications are NOT written back to cache file

Result:

  • ✅ Switching to upstream release: cache refetched, modifications reapplied in memory
  • ✅ No persistent cache contamination

✅ Cache Refresh

Yes, cache refreshes automatically

Line 183: setInterval(() => ModelsDev.refresh(), 60 * 1000 * 60).unref()

Refreshes every hour. When remote models.dev updates, next refresh cycle pulls new data.


Verdict: Code is sound. Runtime-only modifications, no file pollution, automatic refresh works correctly.

New%20session%20-%202026-01-03T19%3A53%3A59.772Z
opencode session  |  github run

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.

2 participants