التعمّق في وضع Plan Mode
إتقان وضع Plan Mode في Claude Code — خطّط أولًا ثم نفّذ لبرمجة بالذكاء الاصطناعي أكثر تحكمًا وكفاءة
تحتاج مفتاح API؟ أنشئ حسابًا ←نقاط النهاية وعناوين Base URL ←
في هذه الصفحة
دليل معمّق حول وضع Plan Mode¶
هل مررت بهذه التجربة من قبل: طلبت من Claude Code مساعدتك في تعديل الشيفرة، فانطلق بأقصى سرعة وغيّر اثني عشر ملفًا، ثم اكتشفت أنه خرج عن المسار؟ أو أدركت في منتصف التعديل أنك أغفلت تبعية ما فاضطررت إلى التراجع عن كل شيء؟
أُنشئ وضع Plan Mode لحل هذه المشكلات. فهو يتيح لـ Claude إنشاء خطة تنفيذ مفصّلة أولًا، ولا يبدأ العمل إلا بعد أن تراجعها وتوافق عليها — محوّلًا «إطلاق السهم ثم رسم الهدف» إلى «التخطيط المتقن قبل التنفيذ».
ما هو وضع Plan Mode¶
وضع Plan Mode مقابل الوضع الافتراضي¶
في الوضع الافتراضي، يفكّر Claude Code وينفّذ في الوقت نفسه: تحليل الشيفرة، وتحرير الملفات، وتشغيل الأوامر — هذه الإجراءات متداخلة. هذا فعّال جدًا للمهام البسيطة، لكنه قد يؤدي إلى أسلوب «خطوة واحدة في كل مرة» في المهام المعقّدة.
وضع Plan Mode مختلف تمامًا:
| الميزة | الوضع الافتراضي | وضع Plan Mode |
|---|---|---|
| التنفيذ | التفكير والتنفيذ في الوقت نفسه | التخطيط أولًا، والتنفيذ بعد الموافقة |
| عمليات الملفات | يقرأ الملفات ويكتبها فورًا | للقراءة فقط، التحليل والبحث فقط |
| تنفيذ الأوامر | قد يشغّل الأوامر مباشرة | لا ينفّذ أي أوامر معدِّلة |
| مناسب لـ | تعديلات بسيطة، إصلاحات سريعة | إعادة هيكلة متعددة الملفات، تطوير ميزات معقّدة |
| ضبط المخاطر | يعتمد على نظام الأذونات | لا مخاطر أثناء مرحلة التخطيط |
ببساطة، Claude في وضع Plan Mode أشبه بمهندس معماري لا يملك سوى دفتر ملاحظات — سيتفحّص الموقع بعناية (يقرأ الشيفرة، ويبحث في الملفات)، ويرسم مخططات بناء مفصّلة (خطة التنفيذ)، لكنه لن يضع لبنة واحدة أبدًا.
لماذا التخطيط قبل التنفيذ¶
تتجاوز فوائد التخطيط قبل التنفيذ مجرد «السلامة» بكثير:
- منظور شامل: يفحص Claude جميع الملفات ذات الصلة أولًا لبناء فهم عام، بدلًا من اكتشاف الإغفالات في منتصف الطريق
- خطط قابلة للمراجعة: يمكنك مراجعة الخطة قبل التنفيذ، ورصد المشكلات المحتملة، وتقديم الملاحظات
- تقليل إعادة العمل: يمكن اكتشاف تعارضات التبعيات وعدم اتساق الواجهات أثناء مرحلة التخطيط
- مواءمة المعرفة: بقراءة الخطة، يمكنك التحقق مما إذا كان فهم Claude للمشروع صحيحًا
- قابلة لإعادة الاستخدام: يمكن حفظ الخطط الجيدة كقوالب مرجعية للمهام المشابهة
متى تستخدم وضع Plan Mode¶
يُوصَى بشدة باستخدام وضع Plan Mode في:
- التعديلات التي تشمل أكثر من 5 ملفات
- تعديل الوحدات الأساسية أو الواجهات العامة
- إضافة ميزات جديدة (خصوصًا ما يتعلق بقواعد البيانات وواجهات API وما إلى ذلك)
- إعادة هيكلة بنية الشيفرة الحالية
- إصلاح الأخطاء ذات الأسباب غير المعروفة (يلزم التحقيق أولًا)
- إذا لم تكن على دراية بالمشروع بعد وتحتاج إلى أن يساعدك Claude في توضيح البنية أولًا
يمكن استخدام الوضع الافتراضي مباشرة:
- إصلاح خطأ صغير محدد
- تعديل محتوى محلي في ملف واحد
- إضافة تعليقات أو وثائق
- تنسيق بسيط أو إعادة تسمية
كيفية استخدام وضع التخطيط¶
التبديل بين الأوضاع باستخدام Shift+Tab¶
بدء وضع التخطيط بسيط جدًا. في حقل الإدخال في Claude Code، اضغط Shift+Tab للتنقل بين الأوضاع:
auto → default → acceptEdits → plan → auto → ...
اعتبارًا من Claude Code 2.1.283، تبدأ الجلسات التفاعلية في auto، لذا يلزمك ثلاث ضغطات للوصول إلى plan (ضغطتان من default). لا ينضم bypassPermissions إلى دورة التبديل إلا عندما تبدأ باستخدام --dangerously-skip-permissions أو --allow-dangerously-skip-permissions.
عندما ترى مؤشر الوضع في الجانب الأيسر من حقل الإدخال يعرض plan، تكون قد دخلت وضع التخطيط.
يمكنك أيضًا التعبير عن نيتك في التخطيط مباشرةً في الـ prompt:
Please help me create a plan first, don't modify the code directly. I want to add email verification to the user system.
نصيحة: اضغط
Escapeللخروج والعودة إلى الوضع default في أي وقت.
سلوك Claude في وضع التخطيط¶
بعد دخول وضع التخطيط، تُقيَّد قدرات Claude:
ما يمكنه فعله:
- قراءة أي ملف
- البحث في الشيفرة (Grep، Glob)
- تحليل بنية المشروع
- عرض سجل Git
- البحث في معلومات الويب
- إنشاء خطط تنفيذ مفصّلة
ما لن يفعله:
- إنشاء ملفات أو تعديلها
- تنفيذ أوامر قد تكون لها آثار جانبية
- تثبيت حزم التبعيات
- تشغيل عمليات البناء أو الاختبارات
يعني ذلك أنه يمكنك أن تدع Claude يستكشف أي شيفرة في وضع التخطيط بأمان من دون القلق من أن «ينزلق» عن غير قصد ويغيّر شيئًا.
عرض الخطط وتحريرها¶
تتضمن الخطط التي يولّدها Claude عادةً البنية التالية:
## Execution Plan: Add Email Verification Feature
### Goal
Add email verification to the user registration flow.
### Impact Analysis
- Files to modify: 6
- Files to create: 3
- Database changes: 1 new table needed
- Risk points: Existing users are not affected, but migration scripts are needed
### Execution Steps
**Phase 1: Database Layer**
1. Create migration script for `email_verifications` table
2. Modify `users` table, add `email_verified` field
**Phase 2: Backend Logic**
3. Create new `email_verification_service.py`
4. Modify `auth_router.py`, add verification-related endpoints
5. Modify `user_service.py`, trigger verification email in registration flow
**Phase 3: Frontend Adaptation**
6. Modify registration page, add verification prompts
7. Create new email verification page
8. Modify routing configuration
### Risks and Notes
- SMTP configuration must be prepared in advance
- Need to consider expiration time for verification links
- Existing users should skip verification
يمكنك تقديم ملاحظات على الخطة:
The plan looks good overall, but I have a few adjustments:
1. No need to create a new verification page, just use the existing toast notification
2. Set verification link expiration to 24 hours
3. Don't modify the users table in phase 1, use the status in email_verifications table instead
Please update the plan.
سيعدّل Claude الخطة بناءً على ملاحظاتك حتى ترضى.
اعتماد الخطة وبدء التنفيذ¶
بعد التأكد من صحة الخطة، اضغط Shift+Tab للتبديل إلى الوضع الذي تريد التنفيذ فيه (مثل auto أو default)، ثم اطلب من Claude تنفيذ الخطة:
The plan looks good, please start executing according to the plan. Start with phase one.
يمكنك أيضًا اختيار التنفيذ على مراحل:
Execute phase one (database layer) first, then stop and let me verify.
دليل عملي لوضع التخطيط¶
المثال 1: إضافة مصادقة المستخدم إلى مشروع موجود¶
لنفترض أن لديك مشروع FastAPI بلا آلية مصادقة حاليًا، وتحتاج إلى إضافة مصادقة JWT.
الخطوة 1: انتقل إلى وضع التخطيط وصِف المتطلبات
My FastAPI project has no user authentication currently. Please help me create a plan to add a JWT-based user authentication system.
Requirements:
- User registration and login
- JWT token issuance and verification
- Route protection (some endpoints require login)
- Use SQLAlchemy to manage user table
Please analyze the existing code structure first, then create a detailed execution plan.
الخطوة 2: يحلل Claude المشروع ويُنشئ خطة
سيقوم Claude أولًا بفحص بنية مشروعك:
I have analyzed your project structure. Here are my findings and execution plan:
## Current Project Analysis
- Framework: FastAPI 0.115.x
- Database: Existing SQLAlchemy configuration (database.py), using PostgreSQL
- Existing models: Product, Order (in models/ directory)
- Routers: product_router.py, order_router.py (both without authentication protection)
- Dependency management: Using requirements.txt
## Execution Plan
### Phase 1: Infrastructure (2 files)
1. Add python-jose[cryptography], passlib[bcrypt] to requirements.txt
2. Add JWT-related configuration items to config.py (SECRET_KEY, ALGORITHM, TOKEN_EXPIRE)
### Phase 2: User Model and Database (2 files)
3. Create new models/user.py — User model
4. Create new alembic migration script
### Phase 3: Authentication Logic (3 files)
5. Create new services/auth_service.py — password hashing, JWT issuance/verification
6. Create new schemas/auth.py — request/response models
7. Create new routers/auth_router.py — /register, /login, /me endpoints
### Phase 4: Route Protection (3 files)
8. Create new dependencies/auth.py — get_current_user dependency
9. Modify product_router.py — write operations require authentication
10. Modify order_router.py — all operations require authentication
### Risk Notes
- SECRET_KEY in config.py must use environment variables, cannot be hardcoded
- Existing API clients need to adapt to authentication headers
- Recommend verifying in test environment first
الخطوة 3: راجع ونفّذ
The plan is good. Two adjustments:
1. Don't use alembic, use SQLAlchemy's create_all directly
2. Read operations on product_router don't need authentication, only create and delete need it
Everything else looks fine, please execute the plan.
المثال 2: إعادة هيكلة وحدة كبيرة¶
لنفترض أن مشروعك يحتوي على ملف utils.py مكوّن من 3000 سطر ويحتاج إلى تقسيمه وإعادة هيكلته.
ادخل وضع التخطيط:
utils.py has ballooned to 3000 lines with everything mixed in. Please help me analyze this file and create a refactoring plan to split it into multiple modules with clear responsibilities. Requirements:
1. Analyze the responsibilities of all functions in utils.py
2. Design a new module structure
3. List all files that import utils.py and their affected imports
4. Ensure all existing functionality remains unaffected after refactoring
سيُنشئ Claude خطة مثل هذه:
## utils.py Refactoring Plan
### Current State Analysis
utils.py contains 47 functions, which can be categorized into 5 types based on their responsibilities:
| Category | Function Count | Example Functions |
|----------|---------------|-------------------|
| String processing | 12 | slugify, truncate, sanitize_html |
| Date and time | 8 | parse_date, format_datetime, get_timezone |
| File operations | 9 | read_file, ensure_dir, get_file_hash |
| Data validation | 11 | validate_email, validate_phone, check_url |
| HTTP utilities | 7 | retry_request, parse_response, build_url |
### Import Analysis
A total of 23 files import utils.py, detailed list as follows:
(List each file and the specific functions used...)
### New Module Structure
utils/
├── __init__.py # Re-exports for backward compatibility
├── strings.py # String processing
├── datetime.py # Date and time
├── files.py # File operations
├── validators.py # Data validation
└── http.py # HTTP utilities
### Execution Steps
(List step by step...)
### Backward Compatibility Strategy
Keep all original exports in utils/__init__.py:
from .strings import *
from .datetime import *
...
This way, undiscovered references won't break.
المثال 3: إصلاح الأخطاء عبر ملفات متعددة¶
يُبلغ المستخدمون بأن «مبالغ الطلبات تُحسب بشكل خاطئ أحيانًا»، لكنك لست متأكدًا من مكان المشكلة.
ادخل وضع التخطيط:
Users report that order amounts are occasionally calculated incorrectly, but not every time. Please help me investigate this issue:
1. Find all code involved in amount calculations
2. Analyze possible causes of occasional errors
3. Create a fix plan
سيُحلّل Claude بعمق في وضع التخطيط:
## Bug Investigation Report
### Amount Calculation Related Code
After comprehensive search, code related to amount calculations is distributed across 4 files:
- order_service.py:calculate_total() — main calculation logic
- discount_service.py:apply_discount() — discount calculation
- tax_service.py:calculate_tax() — tax calculation
- cart_service.py:get_cart_total() — cart total
### Issues Found
**Root cause: Floating point precision problem**
In order_service.py line 127:
total = sum(item.price * item.quantity for item in items)
Python's floating point arithmetic has precision issues:
>>> 0.1 + 0.2
0.30000000000000004
When orders contain multiple items with decimal amounts, cumulative errors may cause the final amount to be off by 1 cent.
**Secondary issue: Discount calculation order**
discount_service.py's discount calculation is executed after tax_service.py's tax calculation,
but in some concurrent scenarios, the order may be reversed (because they are called asynchronously).
### Fix Plan
1. Change all amount calculations to use Decimal type
2. Modify the call order of discount and tax to be synchronous and sequential
3. Add unit tests for amount consistency
يوضح هذا المثال قيمة وضع التخطيط في التحقيق في الأخطاء — لن يتسرّع Claude في تغيير الشيفرة؛ بل يجري تحليلًا شاملًا أولًا.
أفضل ممارسات وضع التخطيط¶
1. وصف «السبب» بدلًا من «الكيفية»¶
غير مستحسن:
Please add a verify_email method to user.py that accepts a token parameter,
queries the email_verifications table, and if the token matches and hasn't
expired, sets user.email_verified to True.
مستحسن:
We need to allow users to verify their email addresses. Users will receive
an email with a verification link after registration. After clicking the
link, their email status becomes verified. Please help me plan the implementation.
لماذا؟ لأنك عندما تصف «السبب»، تتوفر لدى Claude مساحة أكبر لتصميم الحل الأمثل. قد يكتشف حالات حدية لم تفكر فيها، أو يقترح تنفيذًا أكثر أناقة. إذا حددت تفاصيل التنفيذ الدقيقة، تنخفض قيمة وضع التخطيط بدرجة كبيرة.
2. اطلب من Claude تحديد مواطن الخطر في الخطة¶
اطلب من Claude أن يحلل المخاطر بشكل استباقي:
Please pay special attention to the following in the plan:
1. What existing functionality might this modification break?
2. Are there configuration files that need to be modified together?
3. Do database changes require migration scripts?
4. Are there any concurrency safety concerns?
3. تنفيذ الخطط المعقدة على مراحل¶
بالنسبة إلى المهام الكبيرة، لا تنفّذ الخطة كاملة دفعة واحدة. جزّئها إلى مراحل قابلة للتحقق منها بشكل مستقل:
This plan has 4 phases, please execute as follows:
- Stop after completing each phase
- Report the completion status of that phase
- Wait for my confirmation before continuing to the next phase
تكمن فائدة هذا الأسلوب في أنه إذا حدث خطأ ما في إحدى المراحل، يمكنك تصحيحه في الوقت المناسب دون التراجع عن عدد كبير من التغييرات.
4. دمج الخطط مع فروع Git¶
سير العمل الأمثل هو: ينشئ وضع التخطيط خطة → إنشاء فرع جديد → التنفيذ على الفرع الجديد → مراجعة الشيفرة → الدمج
# Create plan in Plan mode first
(Switch to Plan mode, describe requirements, review plan)
# After satisfied, switch back to default mode
Please create a new branch feature/email-verification first, then execute the plan.
إذا اكتشفت أن الخطة خاطئة أثناء التنفيذ، فيمكنك دائمًا العودة إلى الفرع الرئيسي والبدء من جديد.
وضع التخطيط مقابل البرمجة المباشرة¶
متى لا تكون هناك حاجة إلى وضع التخطيط¶
- مهام بسيطة تعدّل ملفًا واحدًا أو ملفين
- معرفة واضحة بما يجب تغييره وكيفية تغييره
- تغييرات غير وظيفية مثل إضافة التعليقات أو تعديل النصوص
- تشغيل الأوامر (مثل تثبيت التبعيات وتشغيل الاختبارات)
متى يكون وضع التخطيط مطلوبًا¶
- تغييرات تشمل أكثر من 5 ملفات
- تعديل الواجهات العامة أو الوحدات الأساسية
- عدم الإلمام الكافي ببنية المشروع بعد
- أسباب الأخطاء غير معروفة، ويلزم التحقيق أولًا
- الحاجة إلى تقييم المقايضات بين عدة حلول
مرجع القرار¶
What is your task?
│
├─ Simple modification (1-2 files, clear direction)
│ → Default mode, start directly
│
├─ Medium task (3-5 files, clear logic)
│ → Can use Plan mode first for quick scan, then switch to execute
│
└─ Complex task (multiple files, uncertain solutions, high risk)
→ Must use Plan mode, plan in detail before executing
نصائح متقدمة¶
1. تخصيص قوالب الخطة عبر CLAUDE.md¶
يمكنك تعريف متطلبات التخطيط في ملف CLAUDE.md الخاص بمشروعك كي تتبع كل أوضاع Plan الصيغة نفسها:
## Plan Mode Requirements
When entering Plan mode, please generate plans according to the following template:
### Required Sections
1. **Current State Analysis**: Current code structure and relevant files
2. **Solution Design**: Specific implementation approach, including alternatives
3. **Impact Scope**: Which files will be modified, which features will be affected
4. **Risk Assessment**: Possible issues and countermeasures
5. **Execution Steps**: In sequential order, each step verifiable independently
6. **Testing Plan**: How to verify the correctness of changes
### Format Requirements
- Each execution step should indicate the files involved
- New files should be marked with [NEW]
- Files to modify should be marked with [MODIFY]
- Risk points should be marked with High/Medium/Low severity
بعد إضافة هذا إلى CLAUDE.md، سينظّم Claude الخطط وفق هذا القالب في كل مرة تستخدم فيها وضع Plan.
2. استخدام الوكلاء الفرعيين للاستكشاف في وضع Plan¶
في وضع Plan، يمكنك أن تطلب من Claude استخدام الوكلاء الفرعيين (أدوات Agent) لاستكشاف أعمق:
Before creating the plan, please help me figure out the following:
1. What does the current database schema look like? Use a sub-agent to analyze all model files
2. What is the list of existing API endpoints? Use a sub-agent to scan all router files
3. What third-party libraries does the project use? Check requirements.txt or pyproject.toml
سينفّذ الوكلاء الفرعيون مهام الاستكشاف هذه في سياقات منفصلة، ثم يلخّصون النتائج للجلسة الرئيسية، مما يساعد Claude على إنشاء خطط أكثر دقة.
3. حفظ الخطط وإعادة استخدامها¶
يمكن حفظ الخطط الجيدة كقوالب مرجعية. يمكنك أن تطلب من Claude تصدير الخطة إلى ملف Markdown:
Please save the plan we just created to docs/plans/add-email-verification.md.
We can reference it when working on similar features in the future.
في المرة التالية التي تصادف فيها متطلبات مشابهة، يمكنك الرجوع إليها مباشرة:
Please refer to the plan structure in docs/plans/add-email-verification.md
and create a similar plan for SMS verification.
4. استخدام وضع Plan لمراجعة الشيفرة¶
بفضل طبيعته القابلة للقراءة فقط، يعد وضع Plan مناسبًا جدًا لمراجعة الشيفرة:
(Enter Plan mode)
Please review all service files in the src/services/ directory, focusing on:
1. Is error handling comprehensive?
2. Are there any SQL injection risks?
3. Are there unclosed resources (database connections, file handles)?
4. Do async code have race conditions?
Please provide a detailed review report and improvement suggestions.
بما أن وضع Plan لا يعدّل أي ملفات، يمكنك أن تدع Claude يراجع شيفرة الإنتاج بأمان من دون القلق من أن يغيّر شيئًا «بشكل ملائم» عن غير قصد.
5. الدمج مع /compact لجلسات Plan الطويلة¶
قد تستهلك عملية الاستكشاف في وضع Plan الكثير من السياق (خصوصًا بعد تحليل ملفات كثيرة). إذا شعرت أن السياق على وشك النفاد، يمكنك استخدام /compact بعد إكمال الخطة وقبل التنفيذ:
/compact Keep the complete execution plan and impact analysis, compress the intermediate exploration process
وهذا يترك مساحة سياق وفيرة لمرحلة التنفيذ.
الأسئلة الشائعة¶
س: هل سيعدّل Claude الملفات عن غير قصد في وضع Plan؟
ج: لا. يمنع وضع Plan جميع عمليات الكتابة على مستوى النظام. يستطيع Claude قراءة أي ملف، لكنه لا يستطيع إنشاء أي محتوى أو تعديله أو حذفه.
س: بعد إنشاء الخطة، عند التبديل إلى الوضع الافتراضي للتنفيذ، هل سيظل Claude يتذكر الخطة؟
ج: نعم. ما دمت لم تستخدم /clear لمسح السجل، فإن تبديل الأوضاع لا يفقد السياق. تبقى الخطة في سجل المحادثة، ويستطيع Claude تنفيذها مباشرة.
س: هل يمكنني استخدام أدوات MCP في وضع Plan؟
ج: يمكنك استخدام أدوات MCP للقراءة فقط (مثل البحث والاستعلام عن الوثائق)، لكن لا يمكنك استخدام أدوات تُحدث آثارًا جانبية.
س: إذا رأيت أن الخطة ليست جيدة، فهل يمكنني أن أطلب من Claude إعادة التخطيط؟
ج: بالتأكيد. يمكنك أن تطلب من Claude تعديل الخطة مرارًا حتى تكون راضيًا. إن طبيعة وضع Plan الخالية من المخاطر تعني أنه يمكنك الاستكشاف والتعديل بحرية.
س: كيف أشارك الخطط في التعاون ضمن الفريق؟
ج: يمكنك أن تطلب من Claude حفظ الخطة في ملف Markdown وإيداعه في مستودع Git. يمكنك أيضًا تضمين محتوى الخطة مباشرة في وصف طلب السحب لتسهيل مراجعة الكود.
ابدأ مع QCode
مفتاح API واحد لـ Claude Code وCodex وغيرها — تُحسب حسب التوكن، وأسعار كل نموذج على qcode.cc/models