Skip to content
This repository was archived by the owner on Apr 26, 2026. It is now read-only.

Fix Claude stream finish handling and add effort passthrough#6

Open
simonseo wants to merge 2 commits into
unixfox:masterfrom
simonseo:simonseo/claude-code-effort-fixes
Open

Fix Claude stream finish handling and add effort passthrough#6
simonseo wants to merge 2 commits into
unixfox:masterfrom
simonseo:simonseo/claude-code-effort-fixes

Conversation

@simonseo

Copy link
Copy Markdown

Summary

  • fix Claude stream finish metadata so OpenCode records the turn as finished instead of issuing extra follow-up turns
  • pass OpenCode effort variants through to Claude Code CLI via --effort
  • scope Claude session reuse by effort so changing variants does not reuse the wrong Claude session

Verification

  • npm run build
  • npm run typecheck
  • opencode run --pure -m claude-code/opus --variant low hi --print-logs --log-level INFO showed --effort low in Claude CLI args and completed in one turn

pm0u pushed a commit to pm0u/opencode-claude-code-plugin that referenced this pull request Apr 7, 2026
Cherry-pick useful parts from unixfox#6:
- Pass OpenCode effort/reasoning variants through to Claude CLI via --effort
- Scope session keys by effort level so different variants get separate sessions
- Include cache tokens (read + creation) in inputTokens and populate
  cachedInputTokens for accurate token reporting via buildUsage helper

Omits the PR's finishReason/usage restructuring which emits non-standard
shapes incompatible with OpenCode's AI SDK consumer.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
pm0u pushed a commit to pm0u/opencode-claude-code-plugin that referenced this pull request Apr 7, 2026
OpenCode uses @ai-sdk/provider v3, which changed finishReason from a
plain string ("stop") to an object ({ unified: "stop", raw: undefined })
and usage from a flat structure to nested inputTokens/outputTokens
objects. With v2 shapes, OpenCode never saw a valid finishReason on
assistant messages, so its agentic loop never broke — causing infinite
empty turns after every response.

- Upgrade @ai-sdk/provider to v3.0.8, @ai-sdk/provider-utils to v4.0.23
- Emit v3-compatible finishReason and usage in all stream/generate paths
- Filter empty text blocks from outgoing messages (defensive measure for
  anthropics/claude-code#41729)
- Return early with finished stream when no user content is present

Partially based on unixfox#6 which
correctly identified the v3 shape requirements.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
pm0u pushed a commit to pm0u/opencode-claude-code-plugin that referenced this pull request Apr 7, 2026
Emit cacheCreationInputTokens under providerMetadata.anthropic so
OpenCode can display cache write tokens in its cost/token UI. Also
restructures providerMetadata on finish events to use buildProviderMetadata
helper for consistent formatting.

Completes the remaining piece from unixfox#6.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant