| name | counting-tokens |
| description | Use when a user asks for the token count of a prompt, text snippet, or local file, or wants to estimate whether content will fit inside an OpenAI model context window. |
Counting Tokens
Overview
gpt-tokenizer๋ฅผ ์ฌ์ฉํด ํ๋กฌํํธ๋ ๋ก์ปฌ ํ์ผ์ ํ ํฐ ์๋ฅผ ๋น ๋ฅด๊ฒ ๊ณ์ฐํ๋ skill์ด๋ค.
Core principle: ์ ์์น์ ์ผํ์ฑ ๋ํผ๋ฅผ ๋ค์ ๋ง๋ค์ง ๋ง๊ณ , ์ด skill ์์ ๊ฒ์ฆ๋ ์คํฌ๋ฆฝํธ๋ฅผ ๊ทธ๋๋ก ์ฌ์ฌ์ฉํ๋ค.
When to Use
- ์ฌ์ฉ์๊ฐ
์ด ํ๋กฌํํธ ๋ช ํ ํฐ์ด์ผ?, ์ด ํ์ผ ํ ํฐ ์ ์๋ ค์ค, ์ปจํ
์คํธ ์๋์ฐ์ ๋ค์ด๊ฐ๋?์ฒ๋ผ ๋ฌผ์ ๋
- OpenAI ๊ณ์ด ๋ชจ๋ธ ๊ธฐ์ค์ผ๋ก ํ
์คํธ ๊ธธ์ด๋ฅผ ๋๋ต ๊ฒ์ฆํด์ผ ํ ๋
- ํ๋กฌํํธ ํฌ๊ธฐ๋ฅผ ๋น๊ตํ๊ฑฐ๋ ์ค์ด๊ธฐ ์ ์ ๊ธฐ์ค ์ซ์๊ฐ ํ์ํ ๋
Do not use this skill for:
- Chat Completions ๋ฉ์์ง ์ค๋ฒํค๋, tool/function calling ์ค๋ฒํค๋๊น์ง ์ ํํ ๊ณ์ฐํด์ผ ํ๋ ๊ฒฝ์ฐ
- ์ด๋ฏธ์ง, PDF ๋ฐ์ด๋๋ฆฌ, ์ค๋์ค์ฒ๋ผ ์์ ํ
์คํธ๊ฐ ์๋ ์
๋ ฅ
- OpenAI ๊ณ์ด์ด ์๋ ๋ค๋ฅธ ํ ํฌ๋์ด์ ๊ท์น์ ์จ์ผ ํ๋ ๊ฒฝ์ฐ
Quick Reference
- skill root:
/Users/pinion/.agents/skills/counting-tokens
- ์ค์น:
bun install
- ์งง์ ํ๋กฌํํธ:
bun run count -- --text "Your prompt here"
- ํ์ผ ์
๋ ฅ:
bun run count -- --file /absolute/path/to/file.txt
- ๋ชจ๋ธ:
gpt-5 ๊ณ ์
- ๊ฒ์ฆ:
bun test
๊ฒฐ๊ณผ JSON ํ๋:
tokens
chars
bytes
lines
model
sourceType
source
Implementation
ํญ์ skill root์์ ์คํํ๋ค.
cd /Users/pinion/.agents/skills/counting-tokens
1. Prompt text
์งง์ ๋จ์ผ ํ๋กฌํํธ๋ --text๋ก ๋ฐ๋ก ์ผ๋ค.
bun run count -- --text "Summarize the quarterly update in 5 bullets."
2. Local file
๋ฉํฐ๋ผ์ธ ํ
์คํธ, ๊ธด ์์คํ
ํ๋กฌํํธ, quoting์ด ๋ถ์ํ ์
๋ ฅ์ ํ์ผ๋ก ์ ์ฅํด์ --file๋ก ์ผ๋ค.
bun run count -- --file /tmp/system-prompt.txt
3. Fixed model
์ด skill์ ํญ์ gpt-5 tokenizer๋ฅผ ์ฌ์ฉํ๋ค. ์ฌ์ฉ์๊ฐ ๋ค๋ฅธ ๋ชจ๋ธ์ ์ธ๊ธํ๋๋ผ๋ ์ด skill ์์ฒด๋ ๋ฐ๊พธ์ง ๋ง๊ณ , ํ์ํ๋ฉด ๋ณ๋ ์๊ตฌ๋ก ์ฒ๋ฆฌํ๋ค.
Output
๊ฒฐ๊ณผ๋ JSON์ผ๋ก ์ถ๋ ฅ๋๋ค. ๋ณดํต์ tokens๋ฅผ ๋จผ์ ๋ตํ๊ณ , ํ์ํ ๋๋ง chars, bytes, lines๋ฅผ ๊ฐ์ด ๋ง๋ถ์ธ๋ค.
์์:
{
"tokens": 11,
"chars": 24,
"bytes": 24,
"lines": 1,
"model": "gpt-5",
"sourceType": "text",
"source": null
}
Common Mistakes
| Mistake | Fix |
|---|
| ๋ค๋ฅธ ํด๋์ ์ ํ ํฐ ์นด์ดํฐ ์คํฌ๋ฆฝํธ๋ฅผ ๋ ๋ง๋ฆ | ์ด skill์ bun run count๋ฅผ ๊ทธ๋๋ก ์ฌ์ฌ์ฉํ๋ค |
| ๊ธด ํ๋กฌํํธ๋ฅผ ์
ธ ์ธ์ฉ์ผ๋ก ์ง์ ๋ฐ์ด ๋ฃ์ | ์์ ํ์ผ๋ก ์ ์ฅํ ๋ค --file์ ์ฌ์ฉํ๋ค |
| ์๋ ๊ฒฝ๋ก ๋๋ฌธ์ ์๋ฑํ ํ์ผ์ ์ฝ์ | ๊ฐ๋ฅํ๋ฉด ์ ๋ ๊ฒฝ๋ก๋ฅผ ์ฌ์ฉํ๋ค |
| plain text ํ ํฐ ์๋ฅผ Chat Completions ์ ์ฒด ์์ฒญ ํ ํฐ๊ณผ ๋์ผ์ํจ | ์ด skill์ plain text/file ๊ธฐ์ค ์ถ์ ์น๋ผ๋ ์ ์ ๋ถ๋ฆฌํด์ ์ค๋ช
ํ๋ค |
| ๋ชจ๋ธ ์ต์
์ ์ฐพ๊ฑฐ๋ ๋ค๋ฅธ ๋ชจ๋ธ์ ์ฆ์์์ ๋ถ์ด๋ ค ํจ | ์ด skill์ gpt-5 ๊ณ ์ ์ด๋ผ๋ ์ ์ ๋จผ์ ์ค๋ช
ํ๋ค |
Red Flags
์ ๊น์ด๋๊น ์ฌ๊ธฐ์ ๋ฐ๋ก node one-liner๋ก ์ธ์
playground์์ ๋์ถฉ ๋ณด๊ณ ๋๋ด์
๊ธด ํ๋กฌํํธ๋ ๊ทธ๋ฅ --text๋ก ๋ฐ์ด ๋ฃ์
์ด ์๊ฐ์ด ๋ค๋ฉด skill-local ์คํฌ๋ฆฝํธ๋ก ๋์๊ฐ๋ค. ์ฌ์ฌ์ฉ์ฑ๊ณผ ์ฌํ์ฑ์ด ๋ชฉ์ ์ด๋ค.