Claude Code 2.1.291 asks a model it doesn't know (any but Claude's own names) for 32000 tokens at most (dte: default dv=32000, upper dN=128000), whatever the model can write, and raises that error when the reply stops on max_tokens; only CLAUDE_CODE_MAX_OUTPUT_TOKENS raises it (n4t, capped at the upper limit). A reasoning model's thinking counts toward the reply, so DeepSeek V4 on a long turn ran into it with plenty of quota left. magpie's translation doesn't make it worse: max_tokens goes upstream as Claude Code sent it (clamped only for a group's member, to its own limit), and finish_reason "length" maps to max_tokens as it should.
Now, as magpie writes CLAUDE_CODE_MAX_CONTEXT_TOKENS, it writes CLAUDE_CODE_MAX_OUTPUT_TOKENS with Claude Code's model: the least known reply limit of the models it runs on (main, tiers, subagents; WorkBuddy's DeepSeek V4 is 128000), since one value serves them all. It is left out when the main model is a Claude one, which Claude Code knows; when one of the others has no known limit; and when the least is no more than 32000. A value the user set, before magpie or over magpie's, is theirs and never touched; magpie's is taken out when Claude Code goes back to Claude's models or off magpie. TestClaudeOutputTokens fails on the old code (mid: "") and passes; go test ./internal/agent/, -race -count=5 on the Claude context/output/compact tests, go vet (darwin, windows) and darwin/linux(nogui)/windows builds pass. Not tried with a real Claude Code on DeepSeek.