/major-ai-skills:max-tokens-ceiling-guardfrom major-ai-skills
Set task-appropriate output token limits in model requests and handle truncated responses explicitly.
Ships in major-ai-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
When invoking LLM APIs (/v1/chat/completions or /v1/messages), client SDKs commonly omit or default the max_tokens parameter to 4,096 or 8,192 tokens.
Defaulting to maximum ceilings creates severe operational hazards:
The Max Tokens Ceiling Guard Protocol enforces task-calibrated output clamping - restricting the output ceiling strictly to the expected payload size.
┌─────────────────────────────────────────────────────────────┐
│ Output Budget Risk Comparison │
│ │
│ Unclamped Default (`max_tokens: 4096`): │
│ • Task: "Is this pull request safe? (YES/NO)" │
│ • Model hallucinates recursive chain-of-thought monologue │
│ ↳ Streams 4,096 tokens before stopping │
│ ↳ 45 seconds wasted, $0.06 billed on a 1-token question! │
│ │
│ Task-Calibrated Ceiling Guard (`max_tokens: 1`): │
│ • Task: "Is this pull request safe? (YES/NO)" │
│ ↳ Model emits 1 token: "YES" and terminates instantly │
│ ↳ 0.05 seconds elapsed, $0.000015 billed (99.9% Savings!) │
└─────────────────────────────────────────────────────────────┘
Always clamp max_tokens to the minimum bound required for the specific task archetype:
| Task Archetype | Optimal max_tokens | Example Tasks |
|---|---|---|
| Boolean Gating / Triage | 1 | TRUE/FALSE, PASS/FAIL, SAFE/VULN |
| Categorical Classification | 5 | Route selection (FRONTEND, BACKEND, DB) |
| 1-Line Summaries & Commits | 50 | Git commit message, PR title, telemetry update |
| Atomic Code Replacement | 250 | replace_file_content single-function patch |
| Function Implementation | 800 | Writing a single TypeScript/Python utility |
| Full Architecture Artifact | 2,048 | Comprehensive RFC or system implementation plan |
from openai import OpenAI
from typing import Optional, Dict, Any
client = OpenAI()
TASK_BUDGET_MAP = {
"boolean_gate": 1,
"classification": 5,
"git_commit": 50,
"atomic_patch": 250,
"function_impl": 800,
"full_doc": 2048
}
def execute_budgeted_query(
messages: list,
task_type: str = "function_impl",
custom_budget: Optional[int] = None
) -> str:
"""Dispatches query with strictly clamped max_tokens to prevent runaway billing."""
budget = custom_budget or TASK_BUDGET_MAP.get(task_type, 800)
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=messages,
max_tokens=budget,
temperature=0.0
)
choice = response.choices[0]
if choice.finish_reason == "length":
print(f"⚠️ Warning: Generation hit hard ceiling ({budget} tokens). Output may be clamped.")
return choice.message.content
Running 200 automated evaluation and classification checks with synthetic runaway prompts:
| Metric | Default max_tokens: 4096 | Task-Calibrated Guard | Improvement |
|---|---|---|---|
| Runaway Incident Cost | $18.40 (12 loops $\times$ 4k tokens) | $0.02 | 99.8% Cost Protection |
| Average Check Latency | 3.4 seconds | 0.08 seconds | 42.5x Faster Execution |
| Unsolicited Chatter | 68 instances | 0 instances | 100% Zero-Chatter |
MANDATORY: API client wrappers must never dispatch requests without an explicit
max_tokensparameter. For boolean gates and triage checks, setmax_tokens: 1; for commit messages, setmax_tokens: 50.
What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub alivirgo/major-ai-skills --plugin major-ai-skills412 skills in this plugin
/3d-slicerAutomate 3D Slicer research workflows with MRML, VTK/ITK, DICOM data, and Segment Editor. Use for software workflows, not clinical interpretation./abbreviated-git-statusInspect Git branch, staging, and working-tree changes with short or porcelain status output when a compact repository check is needed./ableton-liveAutomate Ableton Live sessions with Python MIDI Remote Scripts, Max for Live, AbletonOSC, and Link synchronization./act-as-a-personal-tutorExplain a subject step by step, assess prior knowledge, and use short exercises to check understanding before advancing.Other plugins' skills for the same job