🧮 Token Calculator Suite
License: MIT Node.js TypeScript Platforms
Conforms to Agent Plugins 1.0.0 — the portable packaging format from the Agentic AI Foundation (OpenAI, Amazon, Microsoft, Cursor and Vercel, with Google as core maintainer). The repository root is the plugin root: it carries the portable
plugin.jsonmanifest alongside.claude-plugin/and the four skills inskills/token-analysis/,skills/file-analysis/,skills/project-cost/andskills/model-comparison/, so any conformant client discovers them.Works in ChatGPT. The skills are plain text — instructions and criteria, no local execution — so they install by switching Work on in the ChatGPT selector and adding them from Plugins, by name or by this repository's URL. They behave the same as in Claude. Their frontmatter validates against the closed Agent Skills field set, which is what ChatGPT, claude.ai and the Skills API require to accept an upload: an extra key there is not ignored, it fails hard. Also available on the free plan, with usage limits.
Unified token calculation system for Claude Chat, Cowork, and Claude Code.
Reusable, open-source library for estimating Claude token consumption across three Anthropic platforms. Built with modularity, accuracy, and privacy in mind.
✨ Features:
- 📊 Accurate token estimation (±18% with exact data)
- 🔄 Single source of truth (shared core library)
- 🌍 Multi-platform: Chat, Cowork, Claude Code
- 🛡️ Privacy-first (Option C consent model)
- 📦 Production-ready TypeScript
- 📚 Fully documented with examples
📦 What's included
token-calculator-suite/
├── skills/ ← Plugin skills (Cowork + Claude Code)
├── plugin.json ← Agent Plugins 1.0.0 manifest
├── .claude-plugin/ ← Claude Code manifest + marketplace entry
├── packages/
│ ├── core/ ← Shared calculation logic
│ ├── calculador-tokens-v2/ ← Claude.ai skill
│ └── cli/ ← token-calc CLI (@token-calc/cli)
├── README.md ← This file
└── package.json ← Monorepo config
🚀 Quick Start
For Chat (claude.ai)
Installation: Copy the whole packages/calculador-tokens-v2/ directory into
your skills folder. Copy the directory, not just the SKILL.md: the Agent Skills
spec requires the folder name to match the frontmatter name, which is what
identifies the skill.
Usage:
/tokens
Features:
- ✅ Calculates tokens in current conversation
- ✅ Opción C: Asks permission before using personal data
- ✅ Accuracy: ±18% with exact data, ±22-30% without
- ✅ Real-time context usage tracking
For Cowork
Installation:
- Zip the repository root (it is the plugin root:
plugin.json,.claude-plugin/andskills/all live there) astoken-calculator.zip - In Cowork: Customize > Plugins > Upload > Select zip
Usage:
/token-calculator:token-analysis # Analyze text for token count and cost
/token-calculator:file-analysis # Estimate a file's token consumption
/token-calculator:project-cost # Estimate total API cost for a project
/token-calculator:model-comparison # Compare models by cost and context window
Features:
- ✅ Analyzes PDFs, DOCX, images, code files
- ✅ Generates batch reports for multiple files
- ✅ Suggests optimization opportunities
- ✅ Exports as CSV or table
For Claude Code
Two independent ways to use this in Claude Code. They are not alternatives to each other — most people want the first.
| What | What you get | Setup |
|---|---|---|
| Plugin skills | The four skills in skills/, invoked as /token-calculator:token-analysis and friends. Pure text, no build. | Install the plugin (see below) |
token-calc CLI | A terminal command Claude can run through the Bash tool, printing a token breakdown plus JSON. | Clone and build (see below) |
This package is a CLI, not an MCP server. Earlier revisions of this section described registering a
dist/mcp-server.jsundermcpServers. That file does not exist and never did: the package (@token-calc/cli) has no MCP SDK dependency and implements no JSON-RPC. Its build output isdist/cli.js, atoken-calcexecutable. If you followed those instructions and got stuck looking formcp-server.js, that is why. See issue #1.
Option A — Install the plugin (skills only, no build)
/plugin marketplace add https://github.com/novanoticia/token-calculator-suite
/plugin install token-calculator@token-calculator-suite
/reload-plugins
Then invoke any of the four skills:
/token-calculator:token-analysis # tokens and cost for a chunk of text
/token-calculator:file-analysis # what a file will cost in context
/token-calculator:project-cost # total API cost for a project
/token-calculator:model-comparison # models by cost and context window
Nothing to compile: the skills are Markdown.
Option B — Build the token-calc CLI
Prerequisites
- Node.js 18.0.0 or higher (
node --version) - Yarn 4 (Berry). This matters: the workspaces use the
workspace:*protocol and the lockfile is Berry v8. Yarn Classic (1.x) fails outright withCouldn't find package "@token-calc/core@workspace:*" ... on the "npm" registry. Enable Berry withcorepack enable && yarn set version stable. - Git
Steps
-
Clone
git clone https://github.com/novanoticia/token-calculator-suite.git cd token-calculator-suite -
Install dependencies
yarn install.yarnrc.ymlalready setsnodeLinker: node-modules, so this produces a realnode_modulestree rather than Yarn PnP. -
Build
yarn buildThis builds
@token-calc/coreand then@token-calc/cli, in that order — the CLI depends on core. To build just one:yarn build:coreoryarn build:cli. -
Verify
ls packages/cli/dist/You should see
cli.js. That is the executable thetoken-calcbin points to. -
Run it
node packages/cli/dist/cli.js tokens \ --messages 50 --user-words 5000 --assistant-words 8000 --lang es node packages/cli/dist/cli.js convert --words 1000 --lang es node packages/cli/dist/cli.js file --path ./document.pdf node packages/cli/dist/cli.js helpTo get a bare
token-calcon yourPATH, link the package once.npm linkis the one that creates a global bin — Yarn Berry'syarn linkdoes something different (it links a package into another project, not onto yourPATH):cd packages/cli && npm link && cd - token-calc helpOr skip linking and add an alias:
alias token-calc="node $(pwd)/packages/cli/dist/cli.js" -
Use it from Claude Code
There is nothing to configure. Claude runs it through the Bash tool like any other command — just tell it what you want, mentioning the path or the linked binary:
"Run token-calc on ./informe.pdf and tell me if it fits in the context window"
To let Claude call it without asking permission each time, add it to your allowed tools, for example
Bash(token-calc:*).
Troubleshooting
Couldn't find package "@token-calc/core@workspace:*"— you are on Yarn Classic. Runcorepack enable && yarn set version stable, thenyarn installagain.yarn buildcompiles core but not the CLI — you are on a revision from before the rootbuildscript chained both. Useyarn build:clidirectly.- Looking for
mcp-server.js— it does not exist. The build output ispackages/cli/dist/cli.js. See the note at the top of this section. - Type errors about
processorfs—@types/nodemust be installed at the root; it is already in the rootdevDependencies, so re-runyarn install. Unknown command: undefined— you ran the CLI with no arguments. That message is followed by the usage text; pick one oftokens,file,convert,help.
What the CLI gives you
- ✅ Token estimation for a conversation, with a min–max range and a confidence level
- ✅ File analysis (PDF, DOCX, images, code) by path or by type and size
- ✅ Word and character conversion, language-aware (ES/EN)
- ✅ Context-window usage as an absolute figure and a percentage
- ✅ Human-readable output plus a JSON block for piping
📊 How It Works
Core Library (packages/core/)
All platforms share a single source of truth:
calculateTokens({
messageCount: 50,
userWords: 5000,
assistantWords: 8000,
language: 'es',
useExactData: true
})
Returns:
{
"totalTokens": 28540,
"minEstimate": 23000,
"maxEstimate": 34000,
"errorMarginPercent": "±18%",
"contextUsage": {
"tokensUsed": 28540,
"tokensAvailable": 200000,
"percentageUsed": 14.27
},
"confidence": "high"
}
Accuracy Levels
| Condition | Error Margin | Confidence |
|---|---|---|
| Exact data (Preferences + Memory) | ±18% | 🟢 High |
| Standard estimate | ±22% | 🟡 Medium |
| High uncertainty | ±30% | 🔴 Low |
Supported File Types
| Type | Tokenization |
|---|---|
| Images | 500-1,500 tokens |
| PDFs | 300 tokens/page + overhead |
| DOCX | 5,000-10,000 tokens |
| Code | 5 tokens/line |
| Web Search | 400 tokens/result |
🔧 Architecture
Three Tiers
┌─────────────────────────────────────────────────┐
│ PRESENTATION LAYER │
├──────────────┬──────────────┬──────────────────┤
│ Chat Skill │ Cowork Plugin│ Claude Code CLI │
├──────────────┴──────────────┴──────────────────┤
│ SHARED CORE LIBRARY (@token-calc/core) │
├─────────────────────────────────────────────────┤
│ - Calculation algorithms │
│ - Constants & ratios │
│ - Language-specific tokenization │
│ - Error margin logic │
└─────────────────────────────────────────────────┘
Modification Guide
To change a calculation formula:
- Edit
packages/core/src/index.ts - Run
yarn build - All platforms automatically use new logic
To add a new file type:
- Add to
packages/core/src/constants.ts - Implement in
calculateFileTokens() - Available to all platforms immediately
📝 Configuration
Language Support
// Spanish (default)
calculateTokens({ language: 'es' }) // 1 word ≈ 1.3 tokens
// English
calculateTokens({ language: 'en' }) // 1 word ≈ 1.0 tokens
Privacy (Option C)
First time only, asks for consent:
🔐 Can I use your Preferences + Memory for exact calculations?
[SÍ] [NO]
- Yes: ±18% accuracy (uses 3,468 exact tokens)
- No: ±22-30% accuracy (estimates only)
🎯 Use Cases
Personal
- "How many tokens am I using this week?"
- "Will this PDF fit in my context window?"
- "Should I archive old conversations?"
Team/Enterprise
- Token budget tracking across projects
- File size optimization recommendations
- Cost estimation for Claude API usage
- Compliance reporting (document processing)
Developer
- Estimate API costs before calling Claude
- Optimize prompt engineering (token budgeting)
- Batch processing analysis
- Automated workflow optimization
🔐 Privacy & Security
✅ No external data collection
- All calculations run locally
- Personal data (Preferences/Memory) never sent anywhere
- Option C requires explicit consent before use
✅ Transparent accuracy
- Always shows error margins
- Distinguishes "known" vs "estimated" data
- Reports confidence levels
🤝 Contributing
All code is open source on GitHub.
Setup dev environment
git clone https://github.com/token-calculator-suite/token-calculator-suite.git
cd token-calculator-suite
yarn install
yarn build
To customize for your team
- Fork repo
- Edit constants in
packages/core/src/constants.ts - Customize skills/commands for your workflow
- Deploy to your Cowork/Code instances
📚 Documentation
| File | Purpose |
|---|---|
packages/core/README.md | Core library API |
packages/calculador-tokens-v2/SKILL.md | Chat skill usage |
plugin.json | Portable plugin manifest (Agent Plugins 1.0.0) |
.claude-plugin/plugin.json | Claude Code plugin manifest |
skills/*/SKILL.md | Plugin skills |
packages/cli/src/cli.ts | token-calc CLI commands |
🐛 Known Limitations
- System prompt estimation is ±1.5k tokens (not observable)
- Web search results compression varies (±20%)
- Language detection not automatic (must specify
--lang) - Concurrent file analysis in Cowork not optimized for >100 files
📞 Support
- Bug reports: GitHub Issues
- Feature requests: GitHub Discussions
- Custom integrations: Contact maintainers
📄 License
MIT License. Free to use, modify, and distribute.
🙏 Acknowledgments
Built with modularity first, tested across three Anthropic platforms.
Last updated: March 2026 Maintainers: Token Calculator Suite Contributors
Part of token-calculator-suite. Made for accuracy, privacy, and reusability.