
Nowait Reasoning Optimizer
- 434 installs
- 30.1k repo stars
- Updated August 4, 2026
- davila7/claude-code-templates
Tune agent prompts and tool-call flow so Claude reasons in one pass without unnecessary waits, retries, or over-planning during multi-step coding tasks.
About
Guides optimization of Claude Code agent reasoning so tasks complete faster with fewer redundant planning passes, smarter tool invocation order, and tighter prompt structure for autonomous coding workflows.
- Reduces idle wait cycles in agent loops
- Improves single-pass reasoning quality
- Optimizes tool-call sequencing
- Lowers token waste from re-planning
- Speeds multi-step autonomous coding
Nowait Reasoning Optimizer by the numbers
- 434 all-time installs (skills.sh)
- Ranked #1,910 of 16,546 AI & Agent Building skills by installs in the Skillselion catalog
- Data as of Aug 5, 2026 (Skillselion catalog sync)
npx skills add https://github.com/davila7/claude-code-templates --skill nowait-reasoning-optimizerAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 434 |
|---|---|
| repo stars | ★ 30.1k |
| Last updated | August 4, 2026 |
| Repository | davila7/claude-code-templates ↗ |
What it does
Tune agent prompts and tool-call flow so Claude reasons in one pass without unnecessary waits, retries, or over-planning during multi-step coding tasks.
Files
NOWAIT Reasoning Optimizer
Implements the NOWAIT technique from the paper "Wait, We Don't Need to 'Wait'! Removing Thinking Tokens Improves Reasoning Efficiency" (Wang et al., 2025).
Overview
NOWAIT is a training-free inference-time intervention that suppresses self-reflection tokens (e.g., "Wait", "Hmm", "Alternatively") during generation, reducing chain-of-thought (CoT) trajectory length by 27-51% without compromising model utility.
When to Use
- Deploying R1-style reasoning models with limited compute
- Reducing inference latency for production systems
- Optimizing token costs for reasoning tasks
- Working with verbose CoT outputs that need streamlining
Supported Models
| Model Series | Type | Token Reduction |
|---|---|---|
| QwQ-32B | RL-based | 16-31% |
| Phi4-Reasoning-Plus | RL-based | 23-28% |
| Qwen3-32B | RL-based | 13-16% |
| Kimi-VL-A3B | Multimodal | 40-60% |
| QvQ-72B-Preview | Multimodal | 20-30% |
Important: NOWAIT works best with RL-based models. Distilled models (Qwen3-4B/8B/14B) show degraded performance when reflection tokens are suppressed.
Quick Start
1. Basic Implementation
from scripts.nowait_processor import NOWAITLogitProcessor
# Initialize processor for your model's tokenizer
processor = NOWAITLogitProcessor(tokenizer)
# Use during generation
outputs = model.generate(
inputs,
logits_processor=[processor],
max_new_tokens=32768
)2. Keywords Suppressed
See references/keywords.md for the complete list. Core keywords:
wait, alternatively, hmm, but, however, check,
double-check, maybe, verify, again, oh, ahHow It Works
1. Initialize Keywords: Identify reflection keywords from empirical analysis 2. Expand to Token Variants: Map keywords to all token variants in vocabulary (e.g., "wait" → " wait", "Wait", " Wait", ".wait", "WAIT") 3. Suppress During Inference: Set logits of reflection tokens to large negative values during decoding
Logits (Before) Logits (After)
Wait 0.8 → Wait -inf
First 0.6 → First 0.6
Hmm 0.5 → Hmm -inf
Let 0.4 → Let 0.4Key Findings
Why It Works
- NOWAIT doesn't eliminate self-reflection entirely—it guides models to skip unnecessary "waiting" reasoning
- Models still perform essential verification at key decision points
- Results in more linear, straightforward reasoning paths
RL vs Distilled Models
| Model Type | NOWAIT Effect | Recommendation |
|---|---|---|
| RL-based (QwQ, Phi4, Qwen3-32B) | Stable accuracy, significant token reduction | ✅ Recommended |
| Distilled (Qwen3-4B/8B/14B) | Accuracy degradation on hard tasks | ⚠️ Use with caution |
Distilled models rely heavily on CoT structure from training data—removing reflection tokens disrupts their reasoning patterns.
Integration Examples
HuggingFace Transformers
from transformers import AutoModelForCausalLM, AutoTokenizer
from scripts.nowait_processor import NOWAITLogitProcessor
model = AutoModelForCausalLM.from_pretrained("Qwen/QwQ-32B")
tokenizer = AutoTokenizer.from_pretrained("Qwen/QwQ-32B")
processor = NOWAITLogitProcessor(tokenizer)
response = model.generate(
tokenizer(prompt, return_tensors="pt").input_ids,
logits_processor=[processor],
max_new_tokens=32768,
do_sample=True,
temperature=0.7
)vLLM
from vllm import LLM, SamplingParams
from scripts.nowait_processor import get_nowait_bad_words_ids
llm = LLM(model="Qwen/QwQ-32B")
bad_words_ids = get_nowait_bad_words_ids(llm.get_tokenizer())
sampling_params = SamplingParams(
max_tokens=32768,
bad_words_ids=bad_words_ids
)Expected Results
| Task Type | Original Tokens | NOWAIT Tokens | Reduction |
|---|---|---|---|
| Math (AIME) | 15,000 | 10,500 | 30% |
| Visual QA (MMMU) | 2,900 | 1,450 | 50% |
| Video QA (MMVU) | 1,700 | 1,250 | 27% |
Limitations
- Less effective on very simple problems where CoT overhead is already minimal
- Distilled models may suffer accuracy loss on challenging tasks
- Some domains may require model-specific keyword tuning
References
- Paper: arXiv:2506.08343v2
- Complete keyword list:
references/keywords.md - Implementation:
scripts/nowait_processor.py
NOWAIT Keywords Reference
Complete reference for reflection keywords used in the NOWAIT technique.
Primary Keywords (from paper)
These keywords were empirically identified from 32 independent runs of QwQ-32B on AIME 2025, using \n\n as delimiters to identify the 15 most frequent monolingual transition words.
Core Suppression List
KEYWORDS = [
"wait", # Most common reflection trigger
"alternatively", # Indicates exploring different approach
"hmm", # Hesitation marker
"but", # Contradiction/reconsideration
"however", # Contradiction/reconsideration
"alternative", # Exploring options
"another", # Switching approach
"check", # Verification trigger
"double-check", # Re-verification
"oh", # Realization marker
"maybe", # Uncertainty/reconsideration
"verify", # Verification trigger
"other", # Exploring alternatives
"again", # Repetition/re-check
"now", # Transition marker
"ah", # Realization marker
"any", # Exploring possibilities
]Excluded Patterns
These patterns should NOT be suppressed as they are false positives:
EXCLUDED = [
"ohio", # Contains "oh" but is a proper noun
"butane", # Contains "but" but is a chemical
"button", # Contains "but" but is a UI element
"butterfly", # Contains "but" but is a noun
"checkout", # Contains "check" but is a noun/verb
"checksum", # Contains "check" but is technical term
"another's", # Possessive form, often necessary
]Token Expansion
For each keyword, the processor expands to all vocabulary variants:
| Keyword | Expanded Variants |
|---|---|
| wait | wait, Wait, WAIT, " wait", " Wait", ".wait", ",wait", etc. |
| hmm | hmm, Hmm, HMM, " hmm", "...hmm", etc. |
| alternatively | alternatively, Alternatively, " Alternatively", etc. |
Model-Specific Tuning
Different models may benefit from adjusted keyword lists:
QwQ-32B / DeepSeek-R1
- Use full default list
- High reduction potential (30%+)
Phi4-Reasoning-Plus
- Use full default list
- Consider adding: "let me think", "I wonder"
Kimi-VL (Multimodal)
- Use full default list
- Very high reduction (40-60%)
- May need domain-specific additions for visual tasks
Qwen3 Series
- RL-based (32B): Use full list
- Distilled (4B/8B/14B): Consider removing "but", "however" to preserve some reasoning flow
Keyword Categories
Self-Reflection Markers
wait,hmm,oh,ah- Signal: Model is pausing to reconsider
Verification Triggers
check,double-check,verify- Signal: Model is validating previous work
Alternative Exploration
alternatively,alternative,another,other- Signal: Model is exploring different approaches
Contradiction/Reconsideration
but,however,maybe- Signal: Model is reconsidering previous conclusion
Transition Markers
now,again,any- Signal: Model is shifting focus or repeating
Benchmark Results by Keyword Removal
| Keywords Removed | AIME 2025 ACC | Token Reduction |
|---|---|---|
| None (baseline) | 66.67% | 0% |
| wait only | 67.33% | 15% |
| wait + hmm | 67.67% | 22% |
| All 17 keywords | 68.00% | 31% |
Implementation Notes
Logit Suppression Value
- Default:
-1e10(effectively negative infinity) - Alternative:
-100(softer suppression, allows rare occurrence)
Vocabulary Iteration
def build_suppressed_tokens(tokenizer, keywords):
suppressed = set()
vocab = tokenizer.get_vocab()
for token_text, token_id in vocab.items():
for keyword in keywords:
if keyword.lower() in token_text.lower():
suppressed.add(token_id)
break
return suppressedPerformance Considerations
- Token set is built once at initialization
- Lookup is O(1) per token during generation
- Memory overhead: ~few KB for token ID set
#!/usr/bin/env python3
"""
NOWAIT Logit Processor
Implements the NOWAIT technique for efficient reasoning by suppressing
self-reflection tokens during inference.
Reference: "Wait, We Don't Need to 'Wait'! Removing Thinking Tokens
Improves Reasoning Efficiency" (Wang et al., 2025)
Usage:
from nowait_processor import NOWAITLogitProcessor
processor = NOWAITLogitProcessor(tokenizer)
outputs = model.generate(inputs, logits_processor=[processor])
"""
import torch
from typing import List, Set, Optional, Union
from dataclasses import dataclass, field
# Default reflection keywords from the paper (empirically derived from QwQ-32B)
DEFAULT_KEYWORDS = [
"wait", "alternatively", "hmm", "but", "however",
"alternative", "another", "check", "double-check",
"oh", "maybe", "verify", "other", "again", "now", "ah", "any"
]
# Keywords to exclude from suppression (false positives)
EXCLUDED_PATTERNS = [
"ohio", # Contains "oh"
"butane", # Contains "but"
"button", # Contains "but"
"butterfly", # Contains "but"
]
@dataclass
class NOWAITConfig:
"""Configuration for NOWAIT processor."""
keywords: List[str] = field(default_factory=lambda: DEFAULT_KEYWORDS.copy())
excluded_patterns: List[str] = field(default_factory=lambda: EXCLUDED_PATTERNS.copy())
negative_value: float = -1e10
case_sensitive: bool = False
class NOWAITLogitProcessor:
"""
A logit processor that suppresses self-reflection tokens during generation.
This processor identifies tokens associated with self-reflection keywords
(e.g., "Wait", "Hmm", "Alternatively") and sets their logits to a large
negative value, effectively preventing their generation.
Args:
tokenizer: The tokenizer for the target model
config: Optional NOWAITConfig for customization
keywords: Optional list of keywords to suppress (overrides config)
Example:
>>> from transformers import AutoTokenizer, AutoModelForCausalLM
>>> tokenizer = AutoTokenizer.from_pretrained("Qwen/QwQ-32B")
>>> model = AutoModelForCausalLM.from_pretrained("Qwen/QwQ-32B")
>>> processor = NOWAITLogitProcessor(tokenizer)
>>> outputs = model.generate(
... input_ids,
... logits_processor=[processor],
... max_new_tokens=32768
... )
"""
def __init__(
self,
tokenizer,
config: Optional[NOWAITConfig] = None,
keywords: Optional[List[str]] = None
):
self.tokenizer = tokenizer
self.config = config or NOWAITConfig()
if keywords is not None:
self.config.keywords = keywords
# Build the set of token IDs to suppress
self.suppressed_token_ids: Set[int] = self._build_suppressed_tokens()
def _is_excluded(self, token_text: str) -> bool:
"""Check if token text matches any excluded pattern."""
token_lower = token_text.lower()
for pattern in self.config.excluded_patterns:
if pattern in token_lower:
return True
return False
def _build_suppressed_tokens(self) -> Set[int]:
"""
Build the set of token IDs to suppress based on keywords.
This expands each keyword to all its variants in the vocabulary:
- Different cases: "wait", "Wait", "WAIT"
- With leading spaces: " wait", " Wait"
- With punctuation: ".wait", ",wait"
"""
suppressed = set()
vocab = self.tokenizer.get_vocab()
for token_text, token_id in vocab.items():
# Skip excluded patterns
if self._is_excluded(token_text):
continue
# Check if token contains any keyword
token_check = token_text if self.config.case_sensitive else token_text.lower()
for keyword in self.config.keywords:
keyword_check = keyword if self.config.case_sensitive else keyword.lower()
if keyword_check in token_check:
suppressed.add(token_id)
break
return suppressed
def __call__(
self,
input_ids: torch.LongTensor,
scores: torch.FloatTensor
) -> torch.FloatTensor:
"""
Process logits by suppressing reflection tokens.
Args:
input_ids: Input token IDs (batch_size, seq_len)
scores: Logit scores (batch_size, vocab_size)
Returns:
Modified scores with suppressed tokens set to negative infinity
"""
for token_id in self.suppressed_token_ids:
if token_id < scores.shape[-1]:
scores[:, token_id] = self.config.negative_value
return scores
def get_suppressed_count(self) -> int:
"""Return the number of tokens being suppressed."""
return len(self.suppressed_token_ids)
def get_suppressed_tokens(self, limit: int = 50) -> List[str]:
"""Return sample of suppressed token texts for debugging."""
tokens = []
for token_id in list(self.suppressed_token_ids)[:limit]:
try:
token_text = self.tokenizer.decode([token_id])
tokens.append(f"{token_id}: '{token_text}'")
except:
tokens.append(f"{token_id}: <decode error>")
return tokens
def get_nowait_bad_words_ids(
tokenizer,
keywords: Optional[List[str]] = None,
config: Optional[NOWAITConfig] = None
) -> List[List[int]]:
"""
Get bad_words_ids for use with vLLM or other frameworks.
This returns the suppressed tokens in the format expected by
frameworks that use bad_words_ids parameter.
Args:
tokenizer: The tokenizer for the target model
keywords: Optional list of keywords to suppress
config: Optional NOWAITConfig for customization
Returns:
List of token ID lists for bad_words_ids parameter
Example:
>>> from vllm import LLM, SamplingParams
>>> llm = LLM(model="Qwen/QwQ-32B")
>>> bad_words = get_nowait_bad_words_ids(llm.get_tokenizer())
>>> params = SamplingParams(bad_words_ids=bad_words)
"""
processor = NOWAITLogitProcessor(tokenizer, config=config, keywords=keywords)
return [[token_id] for token_id in processor.suppressed_token_ids]
def create_nowait_stopping_criteria(
tokenizer,
max_reflections: int = 0
) -> "NOWAITStoppingCriteria":
"""
Create a stopping criteria that limits reflection occurrences.
Alternative to logit suppression - allows some reflections but stops
if too many are detected.
Args:
tokenizer: The tokenizer for the target model
max_reflections: Maximum allowed reflection keywords (0 = none)
Returns:
StoppingCriteria instance
"""
return NOWAITStoppingCriteria(tokenizer, max_reflections)
class NOWAITStoppingCriteria:
"""
Stopping criteria that monitors reflection keyword count.
This is a softer alternative to complete suppression - it allows
the model to use some reflection tokens but stops generation if
the count exceeds a threshold.
"""
def __init__(self, tokenizer, max_reflections: int = 0):
self.tokenizer = tokenizer
self.max_reflections = max_reflections
self.config = NOWAITConfig()
self.reflection_count = 0
def __call__(
self,
input_ids: torch.LongTensor,
scores: torch.FloatTensor,
**kwargs
) -> bool:
"""Check if generation should stop based on reflection count."""
# Decode latest token
if input_ids.shape[1] > 0:
latest_token = input_ids[0, -1].item()
try:
token_text = self.tokenizer.decode([latest_token]).lower()
for keyword in self.config.keywords:
if keyword.lower() in token_text:
self.reflection_count += 1
break
except:
pass
return self.reflection_count > self.max_reflections
def reset(self):
"""Reset the reflection counter."""
self.reflection_count = 0
# Convenience function for quick setup
def apply_nowait(
model,
tokenizer,
prompt: str,
max_new_tokens: int = 32768,
temperature: float = 0.7,
**generate_kwargs
) -> str:
"""
Convenience function to generate with NOWAIT applied.
Args:
model: The language model
tokenizer: The tokenizer
prompt: Input prompt
max_new_tokens: Maximum tokens to generate
temperature: Sampling temperature
**generate_kwargs: Additional arguments for model.generate()
Returns:
Generated text with NOWAIT optimization applied
Example:
>>> response = apply_nowait(model, tokenizer, "Solve: 2+2=?")
"""
processor = NOWAITLogitProcessor(tokenizer)
inputs = tokenizer(prompt, return_tensors="pt")
if hasattr(model, "device"):
inputs = {k: v.to(model.device) for k, v in inputs.items()}
outputs = model.generate(
**inputs,
logits_processor=[processor],
max_new_tokens=max_new_tokens,
temperature=temperature,
do_sample=temperature > 0,
**generate_kwargs
)
# Decode only the new tokens
generated_ids = outputs[0][inputs["input_ids"].shape[1]:]
return tokenizer.decode(generated_ids, skip_special_tokens=True)
if __name__ == "__main__":
# Demo/test mode
print("NOWAIT Reasoning Optimizer")
print("=" * 50)
print(f"Default keywords: {DEFAULT_KEYWORDS}")
print(f"Excluded patterns: {EXCLUDED_PATTERNS}")
print()
print("Usage example:")
print(" from nowait_processor import NOWAITLogitProcessor")
print(" processor = NOWAITLogitProcessor(tokenizer)")
print(" model.generate(..., logits_processor=[processor])")