Summary
Add macdoc convert --to tokens <file> that outputs exact token counts.
Depends on #27 (CLI migration to convert --to pattern).
CLI Interface
macdoc convert --to tokens file.md # both models
macdoc convert --to tokens --model gpt-4o file.md # OpenAI only
macdoc convert --to tokens --model claude-sonnet file.md # Claude only
Output Format
# Default (tabular)
Model Tokens
─────────────────────────
gpt-4o 1,234
claude-sonnet-4-6 1,198
# Single model (just the number for piping)
1234
Token Counting Methods
| Provider |
Method |
Cost |
| OpenAI |
swift-tiktoken (offline BPE) |
Free, offline |
| Claude |
Anthropic /v1/messages/count_tokens API |
Free, online (RPM-limited) |
Architecture
- New package:
token-counter-swift under packages/
- Layer 2 utility (measurement tool, not format converter)
- Depends on:
swift-tiktoken, Foundation (URLSession for Anthropic API)
- Needs
ANTHROPIC_API_KEY env var for Claude counting
References
Current Status
Phase: verified
Last updated: 2026-05-25 by /idd-all-chain (multi-root verify)
Summary
Add
macdoc convert --to tokens <file>that outputs exact token counts.Depends on #27 (CLI migration to
convert --topattern).CLI Interface
Output Format
Token Counting Methods
swift-tiktoken(offline BPE)/v1/messages/count_tokensAPIArchitecture
token-counter-swiftunderpackages/swift-tiktoken,Foundation(URLSession for Anthropic API)ANTHROPIC_API_KEYenv var for Claude countingReferences
macdoc convert --topattern (textutil-compatible) #27Current Status
Phase: verified
Last updated: 2026-05-25 by /idd-all-chain (multi-root verify)