@ychampion/withheld-max-output-token-errors
ADelay surfacing max-output-token failures until the recovery loop completes, then emit sanitized tool_result errors.
Install
agr install @ychampion/withheld-max-output-token-errors --target claudeWrites 1 file into .claude/skills/, pinned to git-5600072a.
- .claude/skills/withheld-max-output-token-errors/SKILL.md
Document
name: withheld-max-output-token-errors description: "Delay surfacing max-output-token failures until the recovery loop completes, then emit sanitized tool_result errors." metadata: author: ychampion
SKILL: Withheld Max Output Token Errors
Domain: tool-orchestration
Trigger: Use this when a user turn hits the max-output-token limit but the system keeps retrying so the recovery loop should finish before reporting an error.
Source Pattern: Distilled from reviewed tool-loop and result-shaping patterns.
Core Method
Detect the API’s max_output_tokens error inside the streaming loop, suppress it while recovery continues, and only expose it once all retries settle. During that delay, emit placeholder tool_result messages that say each tool is missing so the user sees a focused failure summary instead of a raw API error. This keeps recovery logic intact while still surfacing helpful, per-tool diagnostics after the recovery path finishes.
Key Rules
- Guard every assistant message against
apiError === 'max_output_tokens'and only mark it for reporting once the recovery loop decides no more progress can happen. - Track tool_use IDs for the assistant messages that triggered the error and emit sanitized messages with the standard
tool_resultshape so downstream components can handle them like any other tool failure. - Log the withheld message only after
isWithheldMaxOutputTokensreturns true; do not surface the API error early or the SDK context may terminate the session. - Keep the placeholder text short, include the original error message, and mark
is_error: trueso tooling knows it’s still an error. - Preserve the tool ID so any transcripts or sidecars referencing the tool use still match the replayed replacement.
Example Application
When the per-turn token budget is exceeded while streaming a multi-tool answer, let the recovery loop run; once it fails, emit one user-facing tool_result block per tool use with the stored error message instead of leaking the API’s max_output_tokens field.
Anti-Patterns (What NOT to do)
- Do not throw or propagate the API error immediately; SDK callers might abort and the recovery path would never execute.
- Do not drop the tool_use IDs when rewriting the error, or transcripts/resumes will lose their references.
Trustgrade A
- passBody integrity
Whether the stored document is plausibly the kind of file the artifact declares, rather than something fetched by mistake.
- passType matchnot applicable to this artifact type
Whether the artifact is really the kind of thing its metadata claims it is.
- passFreshness
How long since the source repository was last pushed to.
- passPrompt injection
Scans the artifact's own text for instructions aimed at your agent rather than at you.
- passLicense
Whether the source repository declares an SPDX license permissive enough to redistribute.
How the grade is calculated
Each check contributes 0 points when it passes, 1 when it warns, and 2 when it fails. The total maps to a letter:
- Aevery check passed
- Bone warning
- Ctwo warnings
- Dprompt injection or body integrity failed, or three warnings
- Fone of those failed, and something else is wrong
These are automated hygiene checks, not a security audit, and not a dependency or vulnerability scan. A grade of A means nothing was flagged — not that the artifact is safe.
Versions
git-5600072a5aa82026-07-31