Skip to content

[BUG] GLM-5 model pollutes context window with broken thinking output #16903

Closed as not planned

Description

@tayroneoliveira2023

Description

When using the GLM-5 model (Z.AI), OpenCode's context window gets polluted with broken/malformed thinking output. The terminal displays ? characters scattered throughout the interface, the rendered content becomes garbled, and the TUI layout breaks completely. The context window shows raw thinking tokens that should be hidden or properly parsed.

The GLM 4.7 model works correctly without any of these rendering issues under the same conditions.

Steps to Reproduce

  1. Open OpenCode on Windows (cmd or PowerShell)
  2. Select the GLM-5 (Z.AI Coding Plan) model
  3. Run any task that triggers the model's thinking/reasoning mode (e.g., a build or code generation task)
  4. Observe the terminal output becoming corrupted

Expected Behavior

The context window should display clean, properly formatted output — thinking tokens should be hidden or correctly rendered, just like the GLM 4.7 model does.

Actual Behavior

  • Multiple ? characters appear throughout the terminal (top, bottom, status bar)
  • The thinking/reasoning output leaks into the visible context window in a broken/malformed state
  • The TUI layout breaks — code snippets, markdown, and status indicators become garbled
  • The status bar at the bottom shows ???■■■■■ instead of proper indicators
  • The overall context window becomes unusable and filled with noise

Specific observations from the screenshot

  • The title bar and content area show ? characters on the left margin where they shouldn't be
  • Code content (Java — EvidenciaRunner.java) is partially rendered but interspersed with broken formatting
  • The bottom status bar shows: ? Build · glm-5 followed by more ? lines, then ? Build GLM-5 Z.AI Coding Plan
  • The very bottom shows ???■■■■■ esc interrupt — the progress/status indicators are corrupted

Comparison

Model Behavior
GLM 4.7 Clean output, no artifacts, thinking is properly handled
GLM-5 Broken thinking tokens leak into context window, ? characters everywhere, TUI breaks

Environment

  • OS: Windows 10/11
  • Terminal: cmd / PowerShell
  • OpenCode version: Latest
  • Model: GLM-5 (Z.AI Coding Plan)

Screenshot

OpenCode GLM-5 broken thinking output


  • I have verified that this issue has not already been requested
  • I have read the contributing guidelines

Activity

  1. added
    opentuiThis relates to changes in v1.0, now that opencode uses opentui
    on Mar 10, 2026
  2. github-actions commented on Mar 10, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

    If your issue is distinct from these, feel free to keep it open and provide any additional context that differentiates it.

  3. tayroneoliveira2023 commented on Mar 10, 2026

    @tayroneoliveira2023
    Author

    Related issues and root cause

    After investigating, this issue appears to be directly related to the known problem with <think>/<thinking> tag handling in OpenCode:

    Root cause

    The extractReasoningMiddleware was intentionally removed in PR #11270 (v1.1.46+), which means <think> tags are now rendered as plain text instead of being collapsed into reasoning blocks. This causes the context window pollution seen in the screenshot — the GLM-5 thinking output leaks into the visible UI as garbled ? characters and broken formatting.

    GLM 4.7 is unaffected because it handles reasoning differently and doesn't produce the same volume of raw <think> tag output.

    Potential fix

    PR #15382 by @erwinh22 implements the rendering-layer approach: tags are preserved in storage for multi-turn LLM context (respecting the decision in PR #11270), but parsed and rendered as reasoning blocks at display time in TUI, Web UI, and CLI. This PR appears to not have been merged yet.

  4. tareko commented on Mar 27, 2026

    @tareko

    This seems to still exist in GLM-5.1, and essentially makes opencode unusable.

  5. toninho09 commented on Apr 1, 2026

    @toninho09

    Try setting the temperature to 1.0 in opencode.json:

    	"provider": {
    		"zai-coding-plan": {
    			"models": {
    				"glm-5": {
    					"options": {
    						"temperature": 1.0
    					}
    				},
    				"glm-5.1": {
    					"options": {
    						"temperature": 1.0
    					}
    				}
    			}
    		}
    	}

    The transform.ts file doesn't have this config yet. With temperature 1.0, GLM-5 and GLM-5.1 feel more stable to me.

  6. sa-altaiftech commented on Apr 3, 2026

    @sa-altaiftech

    Try setting the temperature to 1.0 in opencode.json:

    "provider": {
    "zai-coding-plan": {
    "models": {
    "glm-5": {
    "options": {
    "temperature": 1.0
    }
    },
    "glm-5.1": {
    "options": {
    "temperature": 1.0
    }
    }
    }
    }
    }
    The transform.ts file doesn't have this config yet. With temperature 1.0, GLM-5 and GLM-5.1 feel more stable to me.

    its possible to set maximum context window? right now if above 80k is not useful, opencode still mark the context window is 200k so compaction not working and make thinking in a loop

  7. jumski commented on Apr 6, 2026

    @jumski

    Same for me - GLM 5.1 is also broken and unusable.

  8. Silur commented on Apr 8, 2026

    @Silur

    Actual outputs of GLM5.1 from opencode:

    Image Image Image
  9. ShibuyaCyana commented on Apr 8, 2026

    @ShibuyaCyana

    According to this Reddit post it seems also happening in Claude code.

    So there seems to be two separate problems:

    1. OpenCode parsing for GLM models are broken;
    2. GLM models themselves are degrading, probably due to they've been overly quantized.
  10. added a commit that references this issue on Apr 10, 2026
    fc36b7c
  11. saurav-shakya commented on Apr 10, 2026

    @saurav-shakya

    Fixed by merging PR #15389, which renders “think” tags as reasoning blocks.
    GLM-5’s thinking output will now be properly displayed in a reasoning block and won’t pollute the context.

  12. removed
    opentuiThis relates to changes in v1.0, now that opencode uses opentui
    on May 3, 2026
  13. github-actions commented on Jul 4, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions