A token limit is a configured target or ceiling for model consumption. In SQL generation, maxTokens(500) caps response length and helps prevent runaway generation and unexpected output costs, but it does not restrict the incoming prompt. section 6.2
Treat token limits as layered production guardrails:
- Validate request size at the API boundary with character limits before constructing the model prompt. section 6.2
- Count tokens locally with a tokenizer such as JTokkit and reject prompts exceeding a predefined budget. section 6.2
- Constrain agent exploration, verbosity, iteration depth, and retries; filter command output and exclude irrelevant files from context. section 9.5.2
A bounded SQL-generation request
A request can combine a validated user prompt, table definitions, and recent queries, then call the model with maxTokens(500) and low temperature. The response ceiling still requires separate input-size protection.
Listing 9.6 Custom slash commands for cost-controlled agent workflows
markdown <!-- .claude/commands/focused-refactor.md --> # Focused Refactor Refactor the specified function or module with these constraints: - Read ONLY the files directly relevant to the change - Do NOT explore the broader codebase unless explicitly needed - Generate ONLY the changed code (diff format preferred) - Do NOT explain changes unless asked - Run existing tests after changes; do NOT write new tests - If tests fail, fix the issue in max 2 iterations, then stop and report what's unresolved - Budget: aim to complete in under 50,000 tokens total $ARGUMENTS
Shows a reusable agent command that limits file exploration, output verbosity, retries, and total work to under 50,000 tokens. section 9.5.2











