StopTimizer

Precise token counter for GPT, Claude, and Gemini models (source of truth from software kernel)

16 stars

Best use case

StopTimizer is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Precise token counter for GPT, Claude, and Gemini models (source of truth from software kernel)

Teams using StopTimizer should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/stoptimizer/SKILL.md --create-dirs "https://raw.githubusercontent.com/diegosouzapw/awesome-omni-skill/main/skills/ai-agents/stoptimizer/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/stoptimizer/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How StopTimizer Compares

Feature / AgentStopTimizerStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Precise token counter for GPT, Claude, and Gemini models (source of truth from software kernel)

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# StopTimizer

Precise token counting using official tokenizers as source of truth from software kernel.

## Purpose

Provides accurate token counts for LLM models (GPT, Claude, Gemini) without approximation. Does not perform validation or judgment—returns raw numbers only (Unix philosophy).

## Usage

### Count All Models

```bash
deno run --allow-net <url>/stoptimizer.ts "hello world"
# Output: 2 2 2 2 2 2 2 (space-separated: gpt-5 gpt-5.2 gpt-5-mini gpt-4o gpt-4 gpt-3.5 claude)
```

### JSON Output

```bash
deno run --allow-net <url>/stoptimizer.ts --json "test"
# Output: {"gpt-5":1,"gpt-5.2":1,"gpt-5-mini":1,"gpt-4o":1,"gpt-4":1,"gpt-3.5":1,"claude-3.5-sonnet":1}
```

### Single Model

```bash
deno run --allow-net <url>/stoptimizer.ts --model gpt-4o "text"
# Output: 1
```

### stdin Support (Large Files)

For files too large for command-line arguments, use stdin:

```bash
# Using dash (Unix tradition)
cat KERNEL.md | deno run --allow-net <url>/stoptimizer.ts -

# Using --stdin flag (modern clarity)
deno run --allow-net <url>/stoptimizer.ts --stdin < large-file.txt

# Combined with other options
cat prompt.txt | deno run --allow-net <url>/stoptimizer.ts - --json
cat README.md | deno run --allow-net <url>/stoptimizer.ts --stdin --model gpt-4o
```

## Supported Models

### GPT Models (OpenAI)
- **gpt-5** - GPT-5 (o200k_base encoding, 100% precise)
- **gpt-5.2** - GPT-5.2 (o200k_base encoding, 100% precise)
- **gpt-5-mini** - GPT-5 mini (o200k_base encoding, 100% precise)
- **gpt-4o** - GPT-4o (o200k_base encoding, 100% precise)
- **gpt-4** - GPT-4 (cl100k_base encoding, 100% precise)
- **gpt-3.5** - GPT-3.5 Turbo (cl100k_base encoding, 100% precise)

### Other Models
- **claude-3.5-sonnet** - Claude 3.5 Sonnet (100% precise via Anthropic tokenizer)
- **gemini-2.0-flash** - Gemini 2.0 Flash (research in progress, use Vertex AI API)

**Encoding Note**: GPT-5 family and GPT-4o use `o200k_base` (~2.3 MB vocabulary), while GPT-4 and GPT-3.5 use `cl100k_base` (~1.1 MB vocabulary). Token counts will differ between encodings for the same text.

## STOP Protocol Validation

Tool provides counts only. Compose validation logic in shell scripts:

```bash
#!/bin/bash
# Example: STOP validation with stdin (for large prompts)

OLD=$(cat prompt-v1.txt | deno run --allow-net <url>/stoptimizer.ts - --model gpt-4o)
NEW=$(cat prompt-v2.txt | deno run --allow-net <url>/stoptimizer.ts - --model gpt-4o)

if [ "$OLD" -eq "$NEW" ]; then
  CHARS_OLD=$(wc -c < prompt-v1.txt)
  CHARS_NEW=$(wc -c < prompt-v2.txt)
  GAIN=$((CHARS_NEW - CHARS_OLD))
  echo "✅ STOP COMPLIANT: Both $OLD tokens, gained $GAIN chars"
  exit 0
else
  echo "❌ STOP VIOLATION: $OLD vs $NEW tokens"
  exit 1
fi
```

### CI/CD Integration

```yaml
# .github/workflows/stop-validation.yml
name: STOP Protocol Validation
on: [pull_request]

jobs:
  validate:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: denoland/setup-deno@v1
      
      - name: Validate prompt changes
        run: |
          TOOL_URL="https://raw.githubusercontent.com/ShipFail/promptware/main/os/skills/stoptimizer/stoptimizer.ts"
          
          # Check each optimization
          deno run --allow-net $TOOL_URL --model gpt-4o "args" > /tmp/old
          deno run --allow-net $TOOL_URL --model gpt-4o "arguments" > /tmp/new
          [ "$(cat /tmp/old)" -eq "$(cat /tmp/new)" ] || exit 1
```

## Performance

- **First run**: ~2-3 MB download (vocabularies cached in `~/.cache/deno/`)
- **Subsequent runs**: Instant (cached modules)
- **Memory**: ~10-15 MB runtime
- **Speed**: ~100-200 tokens/sec per model

## Exit Codes

- `0` - Success (token count returned)
- `2` - Error (network failure, invalid model, missing argument)

## Limitations

- Requires network access on first run for vocabulary download
- Gemini tokenizer requires additional research (SentencePiece WASM integration)
- Text-only (no multimodal token counting)
- No streaming support (processes entire text at once)

## References

- [RFC 0022: STOP Protocol](../../rfcs/0022-semantic-token-optimization-protocol.md)
- [RFC 0012: Skill Specification](../../rfcs/0012-sys-skill-spec.md)
- [js-tiktoken](https://github.com/dqbd/tiktoken)
- [OpenAI Tokenizer](https://platform.openai.com/tokenizer)

## Examples

### Basic Token Counting

```bash
$ deno run --allow-net stoptimizer.ts "The quick brown fox"
5 5 5 5
```

### Comparing Abbreviations vs Full Words

```bash
$ deno run --allow-net stoptimizer.ts --json "params"
{"gpt-4o":1,"gpt-4":1,"gpt-3.5":1,"claude-3.5-sonnet":1}

$ deno run --allow-net stoptimizer.ts --json "parameters"
{"gpt-4o":1,"gpt-4":1,"gpt-3.5":1,"claude-3.5-sonnet":1}

# Both tokenize to 1 token - STOP compliant!
```

### Programmatic Use

```typescript
import { Tiktoken, getGPTVocab } from "./deps.ts";

const vocab = getGPTVocab("cl100k_base");
const tokenizer = new Tiktoken(
  vocab.bpe_ranks,
  vocab.special_tokens,
  vocab.pat_str
);

const tokens = tokenizer.encode("hello world");
console.log(`Token count: ${tokens.length}`);
tokenizer.free();
```

Related Skills

bgo

10
from diegosouzapw/awesome-omni-skill

Automates the complete Blender build-go workflow, from building and packaging your extension/add-on to removing old versions, installing, enabling, and launching Blender for quick testing and iteration.

Coding & Development

mcp-create-declarative-agent

16
from diegosouzapw/awesome-omni-skill

Skill converted from mcp-create-declarative-agent.prompt.md

MCP Architecture Expert

16
from diegosouzapw/awesome-omni-skill

Design and implement Model Context Protocol servers for standardized AI-to-data integration with resources, tools, prompts, and security best practices

mathem-shopping

16
from diegosouzapw/awesome-omni-skill

Automatiserar att logga in på Mathem.se, söka och lägga till varor från en lista eller recept, hantera ersättningar enligt policy och reservera leveranstid, men lämnar varukorgen redo för manuell checkout.

math-modeling

16
from diegosouzapw/awesome-omni-skill

本技能应在用户要求"数学建模"、"建模比赛"、"数模论文"、"数学建模竞赛"、"建模分析"、"建模求解"或提及数学建模相关任务时使用。适用于全国大学生数学建模竞赛(CUMCM)、美国大学生数学建模竞赛(MCM/ICM)等各类数学建模比赛。

matchms

16
from diegosouzapw/awesome-omni-skill

Mass spectrometry analysis. Process mzML/MGF/MSP, spectral similarity (cosine, modified cosine), metadata harmonization, compound ID, for metabolomics and MS data processing.

managing-traefik

16
from diegosouzapw/awesome-omni-skill

Manages Traefik reverse proxy for local development. Use when routing domains to local services, configuring CORS, checking service health, or debugging connectivity issues.

managing-skills

16
from diegosouzapw/awesome-omni-skill

Install, find, update, and manage agent skills. Use when the user wants to add a new skill, search for skills that do something, check if skills are up to date, or update existing skills. Triggers on: install skill, add skill, get skill, find skill, search skill, update skill, check skills, list skills.

manage-agents

16
from diegosouzapw/awesome-omni-skill

Create, modify, and manage Claude Code subagents with specialized expertise. Use when you need to "work with agents", "create an agent", "modify an agent", "set up a specialist", "I need an agent for [task]", or "agent to handle [domain]". Covers agent file format, YAML frontmatter, system prompts, tool restrictions, MCP integration, model selection, and testing.

maintainx-automation

16
from diegosouzapw/awesome-omni-skill

Automate Maintainx tasks via Rube MCP (Composio). Always search tools first for current schemas.

mailsoftly-automation

16
from diegosouzapw/awesome-omni-skill

Automate Mailsoftly tasks via Rube MCP (Composio). Always search tools first for current schemas.

mails-so-automation

16
from diegosouzapw/awesome-omni-skill

Automate Mails So tasks via Rube MCP (Composio). Always search tools first for current schemas.