أمر واحد يرجّع كلود من الموت
لما تمتلئ ذاكرة كلود في نص المهمة، ما تحتاج تبدأ من صفر.
كل من استخدم كلود على مهمة طويلة عرف هذا الموقف: أنت في منتصف الشغل، كلود يعرف كل تفاصيل المشروع، وفجأة يبدأ يتصرف غريب أو تقل دقته بشكل واضح. المشكلة مو فيه، المشكلة في إن نافذة السياق (context window) امتلأت. والحل ما يحتاج تبدأ محادثة جديدة وتشرح كل شيء من الأول. في أمر واحد يحل هذا بثانية.
🧩 إيش هو بالضبط
نافذة السياق هي الذاكرة المؤقتة اللي يستخدمها كلود أثناء المحادثة. كل رسالة كتبتها، كل كود شاركته، كل رد جاءك، يأخذ مساحة من هذه النافذة. لما تمتلئ، كلود ما يقدر يرى كل التاريخ وتبدأ المحادثة تتدهور.
تخيّل إنك تشتغل على سبورة صغيرة. كل ما كتبت فيها تراكم الكلام حتى ما في مكان، وأنت مضطر إما تمحي كل شيء أو تأخذ سبورة جديدة وتبدأ من صفر. أمر /compact مثل شخص يجلس ويلخص لك كل اللي كتبته في سطور واضحة، ثم يعطيك سبورة نظيفة مع الملخص جاهز عليها.
⚙️ كيف يشتغل
أمر /compact متاح في Claude Code، يعني النسخة اللي تشتخدمها من الطرفية (Terminal). لما تكتبه، كلود يسوي ثلاثة أشياء بالترتيب:
1️⃣ يقرأ كل تاريخ المحادثة الحالية من أولها لآخرها
2️⃣ يحوّلها لملخص مضغوط يحافظ على أهم المعلومات: إيش المشروع، وين وصلتوا، إيش القرارات اللي اتخذت، وإيش اللي لسه باقي
3️⃣ يفتح نافذة سياق جديدة ويحط فيها هذا الملخص كنقطة انطلاق
النتيجة: ميزانية التوكن (tokens) ترجع تقريباً لنقطة البداية، وكلود يكمّل من حيث توقف بدون ما تشرح له كل شيء من الأول. 💡 في فرق كبير بين هذا وبين تفتح محادثة جديدة وتحاول تكتب ملخصاً بنفسك، لأن كلود يشوف كل شيء وينتقي اللي يهم فعلاً.
🌍 وين تشوفه في حياتك
هذا الأمر مهم في الحالات اللي تعمل فيها مع كلود لفترة طويلة وما تقدر تخسر السياق:
💻 جلسات البرمجة الطويلة: لما تبني ميزة كاملة أو تصلح مشكلة معقدة وتحتاج تبقى في نفس السياق ساعات
📄 مراجعة المستندات الكبيرة: لما تشتغل على تحرير أو تحليل ملف طويل على جلسات متعددة
🔍 جلسات البحث والتحليل العميق: لما تسأل كلود يتعمق في موضوع ويبني كل إجابة على اللي قبلها
🏗️ التخطيط للمشاريع: لما تشتغل مع كلود على هيكل مشروع كامل وكل قرار يؤثر على اللي بعده
🛠️ الأدوات اللي تستخدمها فعلاً
🔧 Claude Code
هذه هي البيئة الوحيدة اللي يشتغل فيها أمر /compact. Claude Code هو الواجهة البرمجية لكلود اللي تشتخدمها من الطرفية مباشرة، وهي مصممة للعمل على مشاريع حقيقية بدل المحادثات العادية. تعطيك أوامر slash وصلاحية الوصول للملفات واستمرارية الجلسة اللي ما توفرها الواجهة على الويب.
1️⃣ ثبّته بكتابة npm install -g @anthropic-ai/claude-code في الطرفية (يحتاج Node.js مثبت مسبقاً)
2️⃣ افتح مجلد مشروعك في الطرفية واكتب claude للبدء
3️⃣ لما تحس إن الجلسة طالت أو كلود بدأ يتباطأ، اكتب /compact واضغط Enter
🔧 Claude Code مع تعليمات مخصصة
نسخة أقوى من نفس الأمر: بدل ما تكتب /compact فقط، تقدر تضيف تعليمة تحدد فيها إيش يحافظ عليه الملخص. يعني بدل ملخص عام، تقوله "ركّز على هذا الجزء بالذات". مثلاً: /compact focus on the authentication logic we built
1️⃣ شغّل Claude Code على مشروعك كالمعتاد
2️⃣ لما تريد تضغط الجلسة، اكتب /compact ثم مسافة ثم تعليماتك بالإنجليزي
3️⃣ كلود يولّد ملخصاً موجهاً بالاتجاه اللي حددته ويكمّل من هناك بدقة أكبر
💡 جرّب بنفسك: خطوة بخطوة
السيناريو: أنت تعمل مع كلود على كود لبناء مكوّن في واجهة مستخدم، وبعد 45 دقيقة من الشغل تحس إن ردوده بدأت تكون عامة وما تراعي القيود اللي حددتها من البداية.
1️⃣ تأكد إن جلسة Claude Code مفتوحة في الطرفية على مجلد مشروعك. ما تحتاج تغلق شيء أو تفتح محادثة جديدة.
2️⃣ اكتب /compact واضغط Enter. هذا كل شيء. مو محتاج تعمل أي شيء ثاني.
3️⃣ انتظر ثوانٍ قليلة. كلود يولّد ملخصاً كاملاً للجلسة: القرارات، الكود اللي بُني، المشاكل اللي حُلّت، واللي لسه ناقص. اقرأ هذا الملخص لأنه يخبرك كيف كلود يفهم مشروعك.
4️⃣ اكمل شغلك بشكل طبيعي. الردود ترجع حادة وواعية بالتفاصيل اللي تهمك. الفرق يبيّن من أول رد بعد الضغط.
وش تسوي بعد ذا
✅ حمّل Claude Code إذا ما جربته بعد وابدأ جلسة على مشروع حقيقي عندك بدل الواجهة على الويب
✅ المرة الجاية اللي تستخدم فيها /compact، اقرأ الملخص اللي يولّده بعناية لأنه يكشف كيف كلود يفهم مشروعك وأين يختلف عن فهمك أنت
✅ جرّب /compact مع تعليمة مخصصة مرة واحدة وشوف الفرق في جودة الملخص مقارنة بالأمر العادي
اللي يعرف متى يضغط الجلسة يشتغل أسرع وأذكى من اللي يبدأ من صفر كل مرة.
———— English ————
Compact Command Saves Dying Sessions
When Claude runs out of context mid-task, one command summarizes everything and keeps you moving.
If you have ever worked with Claude on a long project, you know the moment. The conversation has been running for an hour. Claude understands the codebase, remembers every decision, tracks every constraint. Then something shifts — responses get vague, it forgets details it knew twenty minutes ago, and progress stalls. This is not a model failure. It is a context window filling up. And you do not have to start over.
**What it actually is**
Every conversation with Claude runs inside something called a context window — a fixed amount of memory that holds everything: your messages, Claude's replies, any code or documents you have shared. That window has a size limit, measured in tokens, which are roughly chunks of text. When it fills up, Claude cannot see the oldest parts of the conversation anymore, and quality degrades.
Think of it like a whiteboard with limited space. The longer you work, the more the board fills up. Eventually you cannot add anything new without losing something important. The /compact command does not erase the board — it calls in someone to read everything written on it and produce a clean, dense summary, then hands you a fresh board with that summary already written on it.
⚙️ How it works
The /compact command lives inside Claude Code, the terminal-based interface for working with Claude on real projects. When you type it, three things happen in sequence:
1️⃣ Claude reads the entire current conversation from the very beginning
2️⃣ It generates a structured summary that preserves what matters: project context, decisions made, current state of the work, and what still needs doing
3️⃣ It opens a new context window and loads that summary as the starting point
Your token budget resets to near-zero usage. Claude picks up where it left off. You did not lose the thread — you compressed it. 💡 That is a fundamentally different outcome from opening a new chat and trying to re-explain everything yourself, because Claude reads the full history before summarizing, not just what you remember to mention.
🌍 Where you see it
The situations where /compact pays off most are exactly the ones where losing context would hurt the most:
💻 Long coding sessions: building a full feature or debugging a complex system across hours of back-and-forth
📄 Document review work: editing or analyzing long files where Claude needs to hold a lot of state across multiple passes
🔍 Deep research dives: asking Claude to build understanding progressively, where each answer depends on the last
🏗️ Architecture planning: working through a project structure where every decision constrains the next one
🛠️ Tools you actually use
🔧 Claude Code
Claude Code is the command-line interface where /compact exists. It is built for real development work rather than casual conversation, and it gives you slash commands, direct file access, and persistent session awareness that the web interface does not offer. This is the environment you need to be in for /compact to work.
1️⃣ Install it by running npm install -g @anthropic-ai/claude-code in your terminal (Node.js must be installed first)
2️⃣ Navigate to your project folder and run claude to start a session
3️⃣ Work normally until the session feels heavy or responses lose precision, then type /compact and press Enter
🔧 Claude Code with guided compact
This is /compact with intention behind it. Instead of letting Claude decide what to preserve, you specify what matters most by adding an instruction after the command. For example: /compact focus on the API design decisions we finalized. The summary it generates will center on that part of your work rather than distributing attention evenly.
1️⃣ Run Claude Code on your project as usual
2️⃣ When you are ready to compact, type /compact then a space then your focus instruction in plain English
3️⃣ Claude generates a targeted summary and continues from that frame, with sharper recall of the part you care about most
💡 Try it yourself: step by step
Scenario: you have been working with Claude Code on a React component for 45 minutes. Responses are starting to feel generic and Claude seems to be forgetting the specific constraints you established early in the session.
1️⃣ Stay inside your open Claude Code session in the terminal. Do not close anything and do not open a new chat. The whole point is to preserve continuity.
2️⃣ Type /compact and press Enter. That is the entire action. Nothing else is required on your end.
3️⃣ Wait a few seconds. Claude will output a summary of the session covering what was built, what decisions were made, and what is still pending. Read this summary — it tells you exactly what Claude considers important about your work, which is useful information in itself.
4️⃣ Send your next message exactly as you normally would. The responses will be sharper, faster, and properly aware of your constraints again. The improvement is noticeable from the first reply after compacting.
**What to do next**
✅ Install Claude Code if you have not already and run your next long working session through it instead of the web interface
✅ The next time you compact a session, read the generated summary carefully — it reveals how Claude understood your project and where its mental model might differ from yours
✅ Try /compact with a custom instruction at least once so you see how different a focused summary is compared to a general one
The engineers who ship faster are not the ones with more patience — they are the ones who know which lever to pull before the session dies.