21 July 2026

أمر واحد يوريك وين راح رصيدك — One Command Shows Your Token WasteArabic

Arabic
أمر واحد يوريك وين راح رصيدك
نافذة السياق تتعبّى بأشياء ما طلبتها، وفي أمر واحد يكشفها كلها.
 
كل مرة تبدأ محادثة مع نموذج ذكاء اصطناعي (AI)، في شيء يصير قبل لا يرد عليك: النموذج يحمّل كل شيء في ذاكرته المؤقتة اللي تُسمّى نافذة السياق (context window). ناس كثير ما يعرفون وش فيها بالضبط. الرد يجي، والرصيد يروح، وهم ما شافوا وين.
 
🧩 إيش هي نافذة السياق بالضبط
 
نافذة السياق هي الذاكرة المؤقتة للنموذج. كل شيء يشوفه في جلستك الحالية يدخل فيها: تعليمات النظام (system prompt) وملفاتك اللي أضفتها وتاريخ المحادثة كله. ولها سعة محدودة تُقاس بالرموز (tokens). الرمز الواحد يساوي تقريباً ثلاثة أرباع كلمة بالإنجليزي أو أربعة حروف.
 
الفكرة تشبه لوحة بيضاء بمساحة ثابتة. كل جملة على اللوحة تكلّف شيء عشان تبقى موجودة. إذا نصف اللوحة مليانة تعليمات ما يحتاجها النموذج الحين، أنت تدفع على ضجيج.
 
⚙️ كيف تعرف وش يملأ النافذة الحين
 
أكثر مصادر الرموز الضايعة ثلاثة:
 
📄 ملفات كاملة محمّلة وما استُخدم منها غير جزء صغير
📜 تعليمات نظام طويلة ومكررة فيها كلام ما يضيف شيء
💬 تاريخ محادثة طويل فيه سياق قديم ما يرتبط بالسؤال الحالي
 
الأمر اللي يكشف هذا كله:
 
إذا كنت تستخدم Claude Code، الأمر النيتف موجود مباشرة:
 
1️⃣ افتح جلسة Claude Code في أي مجلد مشروع
2️⃣ اكتب /cost في أي وقت أثناء المحادثة
3️⃣ تظهر لك تفاصيل الرموز المستخدمة في الجلسة الحالية
4️⃣ قارن الأرقام بالمحتوى اللي تعتقد إنك أضفته فعلاً، وإذا الفرق كبير فشيء يتحمّل بدون ما تطلبه
 
أما إذا كنت تشتغل مع النماذج عبر Python أو API، فمكتبة tiktoken تحسب لك الرموز في أي نص قبل لا ترسله:
 
1️⃣ ثبّت المكتبة: pip install tiktoken
2️⃣ شغّل هذا السطر من الترمينال مباشرة:
python3 -c "import tiktoken; enc = tiktoken.get_encoding('cl100k_base'); print(len(enc.encode(open('prompt.txt').read())), 'token')"
3️⃣ استبدل prompt.txt بأي ملف تبغى تقيسه
4️⃣ الرقم اللي يطلع هو عدد الرموز اللي ستدفع عليها بالضبط
 
🌍 وين تشوفه في حياتك الفعلية
 
📱 لما تبدأ محادثة بتعليمات نظام طويلة كتبتها من زمان وما راجعتها
🖥️ لما تحمّل ملف كود كامل وسؤالك عن دالة واحدة بس
📂 لما يكون عندك CLAUDE.md فيه توثيق قديم ما حدّثته
🤖 لما تستخدم تطبيق AI جاهز وتتساءل ليش كل محادثة تكلّفك أكثر مما توقعت
 
🛠️ الأدوات اللي تستخدمها فعلاً
 
🔧 tiktoken
مكتبة Python من OpenAI تحسب عدد الرموز في أي نص قبل إرساله للنموذج. تشتغل بدون ما تسوي أي API call، يعني تعرف الثقل الحقيقي قبل لا يكلّفك شيء.
كيف تبدأ:
1️⃣ ثبّتها مرة واحدة: pip install tiktoken
2️⃣ استوردها في Python: import tiktoken
3️⃣ استخدم الترميز cl100k_base لنماذج GPT-4 وClaude
 
🔧 Claude Code
أداة سطر الأوامر الرسمية من Anthropic تشتغل مباشرة في ترمينالك. فيها أمر /cost يعطيك نظرة فورية على استهلاك الرموز أثناء أي جلسة بدون ما تطلع من الشغل.
كيف تبدأ:
1️⃣ ثبّتها: npm install -g @anthropic-ai/claude-code
2️⃣ شغّلها في مجلد مشروعك: claude
3️⃣ اكتب /cost في أي وقت تبغى ترى وين راح رصيدك
 
🔧 LLM CLI
أداة سطر الأوامر من Simon Willison تتيح لك التعامل مع نماذج متعددة من ترمينال واحد. تعرض عدد الرموز مع كل رد تلقائياً، يعني تشوف تكلفة كل طلب في الحال.
كيف تبدأ:
1️⃣ ثبّتها: pip install llm
2️⃣ أضف مفتاح API الخاص بك: llm keys set openai
3️⃣ شغّل أي طلب وشوف عدد الرموز في المخرجات مباشرة
 
💡 جرّب بنفسك: خطوة بخطوة
 
السيناريو: عندك system prompt كتبته من زمان وما تعرف ثقله الحقيقي.
 
1️⃣ انسخ نص الـsystem prompt الخاص بك وضعه في ملف اسمه prompt.txt في أي مجلد
2️⃣ افتح الترمينال وشغّل: pip install tiktoken (مرة واحدة بس تكفي)
3️⃣ شغّل هذا الأمر:
python3 -c "import tiktoken; enc = tiktoken.get_encoding('cl100k_base'); tokens = enc.encode(open('prompt.txt').read()); print(len(tokens), 'token')"
4️⃣ شوف الرقم. إذا كان فوق 500 رمز لتعليمات نظام بسيطة، عندك مساحة تحذف منها. اقرأ كل جملة واسأل نفسك: هل النموذج يحتاج هذا عشان يرد عليّ الحين؟
 
وش تسوي بعد ذا
 
✅ شغّل tiktoken على أي system prompt عندك الحين وشوف الأرقام الفعلية
✅ ابحث عن تفاصيل تسعيرة نافذة السياق للنموذج اللي تستخدمه عشان تعرف إيش يساوي كل رمز
✅ لكل جزء من السياق اللي تحمّله اسأل سؤال واحد: هل النموذج يحتاج هذا عشان يجاوبني الحين؟
 
الرموز اللي ما تشوفها هي اللي تكلّفك أكثر.
 
———— English ————
 
**One Command Shows Your Token Waste**
One line reads exactly what is filling the window right now, before it costs you.
 
Every time you start a conversation with an AI model, something happens before it replies: the model loads everything it can see into its temporary memory, called the context window. Most people never look at what is actually in there. The reply arrives, the balance drops, and they move on without knowing why.
 
**What it actually is**
 
The context window is the model's working memory for your current session. Everything it can see sits inside it at once: your system prompt, any files you added, the full conversation history, and anything else that was pulled in automatically. That space is measured in tokens, and tokens cost money. One token is roughly three quarters of an English word, or about four characters of text.
 
Think of it as a whiteboard with a fixed amount of space. Every sentence on that whiteboard costs something to keep there. If half the whiteboard is covered with instructions the model does not need right now, you are paying to maintain noise.
 
**How it works**
 
The three biggest sources of token waste are:
 
📄 Full files loaded when only a small section was relevant to the question
📜 System prompts padded with repetition, outdated rules, or vague context that never gets used
💬 Long conversation histories that carry stale context forward into unrelated questions
 
The command that surfaces all of this:
 
If you are working in Claude Code, the native command is immediate:
 
1️⃣ Open a Claude Code session in any project directory
2️⃣ Type /cost at any point during the conversation
3️⃣ The output shows exactly how many tokens the current session has consumed
4️⃣ Compare that number against what you actually intended to load — a large gap means something is being pulled in that you did not ask for
 
If you are working with models through Python or an API directly, the tiktoken library gives you a precise count before you even send the request:
 
1️⃣ Install it once: pip install tiktoken
2️⃣ Run this single line from your terminal:
python3 -c "import tiktoken; enc = tiktoken.get_encoding('cl100k_base'); print(len(enc.encode(open('prompt.txt').read())), 'tokens')"
3️⃣ Replace prompt.txt with whatever file you want to measure
4️⃣ The number printed is exactly what you are paying for
 
**Where you see it**
 
📱 When your system prompt runs three paragraphs long for a task that only needs two sentences
🖥️ When you attach an entire codebase file and your question is about one function inside it
📂 When your CLAUDE.md or project instructions contain outdated documentation you forgot to trim
🤖 When you use a packaged AI app and wonder why every session feels expensive before you have said much
 
**🛠️ Tools you actually use**
 
🔧 tiktoken
The official tokenizer library from OpenAI, compatible with GPT and Claude models alike. It counts the exact number of tokens in any string before you send it. No API call required, no cost, just a number you can act on immediately.
How to get started:
1️⃣ Install it: pip install tiktoken
2️⃣ Import it in Python: import tiktoken
3️⃣ Use the cl100k_base encoding for GPT-4 and Claude models — it matches what the models actually count on their end
 
🔧 Claude Code
Anthropic's official terminal tool that runs directly in your working environment. The /cost command gives you a live breakdown of token consumption during any session without leaving your workflow.
How to get started:
1️⃣ Install it: npm install -g @anthropic-ai/claude-code
2️⃣ Launch it inside your project folder: claude
3️⃣ Type /cost at any point to see a full breakdown of the current session's token use
 
🔧 LLM CLI
Simon Willison's terminal tool for working with multiple AI models from one place. It surfaces token counts alongside every response automatically, so you see the cost of each request as it happens.
How to get started:
1️⃣ Install it: pip install llm
2️⃣ Set your API key: llm keys set openai
3️⃣ Run any prompt and the token count appears in the output without extra configuration
 
**💡 Try it yourself: step by step**
 
Scenario: you have a system prompt you wrote a while ago and you have no idea how heavy it actually is.
 
1️⃣ Copy your system prompt text and save it as prompt.txt in any folder on your machine
2️⃣ Open your terminal and run pip install tiktoken — you only need to do this once
3️⃣ Run this command:
python3 -c "import tiktoken; enc = tiktoken.get_encoding('cl100k_base'); tokens = enc.encode(open('prompt.txt').read()); print(len(tokens), 'tokens')"
4️⃣ Read the number. If it is above 500 tokens for a simple set of instructions, you have room to cut. Go line by line and ask one question per sentence: does the model need this to answer me right now?
 
**What to do next**
 
✅ Run tiktoken on your most-used system prompt right now and look at the actual number
✅ Search for the context window pricing of the model you use most so you know what each token actually costs
✅ For every piece of context you load, ask the same question: does the model need this to answer me right now?
 
The tokens you never see are the ones you pay for the most.

Most value

Start building with me now

We sit together, break down your problem, and I build the AI solution with you step by step

60minutes
  • A private session with you
  • Real building during the session
  • Results you take with you when we finish
Book a build session

100% free

A free consultation about your problem

Start

The full path · Monthly subscription

Full access to every guide (29) for 249 AED/month