كيف تبدأ مع «agentic coding»: المستوى المتوسط

25 دقيقة قراءة
Claude CodeAgentic AITutorialIntermediate

إذا وصلت هنا، فأنت تجاوزت البداية. صرت تعرف كيف تثبت «Claude Code»، وتتحدث معه، وتبني مشروعًا من داخل المحادثة. الآن يبدأ الجزء الذي يفرق بين الاستخدام العابر والاستخدام الجاد.

هذه المقالة عن الطبقات المتقدمة في «Claude Code»: الـ «sub-agents»، والـ «hooks»، والـ «skills»، والـ «MCP servers»، وملفات الإعدادات، والـ «plugins». الفكرة ليست حفظ الأسماء. الفكرة أن تجعل «Claude Code» يعمل بالطريقة التي يعمل بها مشروعك.

الجزء الأول: فهم البنية

قبل أن ندخل في التفاصيل، نحتاج صورة واحدة توضّح أين تقف كل قطعة داخل «Claude Code»:

text
+-----------------------------------------------------------------------------+
|                           CLAUDE CODE ARCHITECTURE                          |
+-----------------------------------------------------------------------------+
|                                                                             |
|    +----------------------------------------------------------------+       |
|    |                     YOUR TERMINAL                              |       |
|    |                                                                |       |
|    |   $ claude                                                     |       |
|    |                                                                |       |
|    |   +--------------------------------------------------------+   |       |
|    |   |                 MAIN AGENT (Claude)                    |   |       |
|    |   |                                                        |   |       |
|    |   |  +----------+  +----------+  +----------+              |   |       |
|    |   |  |Sub-Agent |  |Sub-Agent |  |Sub-Agent |              |   |       |
|    |   |  |(Explore) |  |(Plan)    |  |(Custom)  |              |   |       |
|    |   |  +----------+  +----------+  +----------+              |   |       |
|    |   |                                                        |   |       |
|    |   +--------------------------------------------------------+   |       |
|    |                              |                                  |       |
|    |                              v                                  |       |
|    |   +--------------------------------------------------------+   |       |
|    |   |                    TOOLS & EXTENSIONS                  |   |       |
|    |   |                                                        |   |       |
|    |   |  +--------+ +--------+ +--------+ +--------+           |   |       |
|    |   |  | Hooks  | | Skills | |  MCP   | |Plugins |           |   |       |
|    |   |  |        | |        | |Servers | |        |           |   |       |
|    |   |  +--------+ +--------+ +--------+ +--------+           |   |       |
|    |   |                                                        |   |       |
|    |   +--------------------------------------------------------+   |       |
|    |                              |                                  |       |
|    |                              v                                  |       |
|    |   +--------------------------------------------------------+   |       |
|    |   |                   CONFIGURATION                        |   |       |
|    |   |                                                        |   |       |
|    |   |  ~/.claude/CLAUDE.md         (User-level)              |   |       |
|    |   |  ./CLAUDE.md                 (Project-level)           |   |       |
|    |   |  ~/.claude/settings.json     (User settings)           |   |       |
|    |   |  ./.claude/settings.json     (Project settings)        |   |       |
|    |   |                                                        |   |       |
|    |   +--------------------------------------------------------+   |       |
|    |                                                                |       |
|    +----------------------------------------------------------------+       |
|                                                                             |
+-----------------------------------------------------------------------------+

كل طبقة تضيف قدرة. نبدأ بها واحدة واحدة.

الجزء الثاني: «sub-agents»، فريقك المتخصص

ما هي «sub-agents»؟

الـ «sub-agents» نسخ متخصصة من «Claude» يستعين بها الـ «agent» الرئيسي عندما تكبر المهمة. بدل أن يراجع شخص واحد الأمن، ويكتب الاختبارات، ويفهم المشروع، تعطي كل مهمة لمن صمم لها.

text
+-----------------------------------------------------------------------------+
|                         SUB-AGENT DELEGATION                                |
+-----------------------------------------------------------------------------+
|                                                                             |
|    You: "Review this code and add tests"                                    |
|                              |                                              |
|                              v                                              |
|                    +-----------------+                                      |
|                    |   Main Agent    |                                      |
|                    |   (Orchestrator)|                                      |
|                    +--------+--------+                                      |
|                             |                                               |
|              +--------------+--------------+                                |
|              |              |              |                                |
|              v              v              v                                |
|     +--------------+ +------------+ +-------------+                         |
|     | Code Reviewer| |Test Writer | |  Explore    |                         |
|     |  Sub-Agent   | | Sub-Agent  | |  Sub-Agent  |                         |
|     |              | |            | |             |                         |
|     | Own context  | |Own context | | Own context |                         |
|     | Own tools    | |Own tools   | | Read-only   |                         |
|     +------+-------+ +-----+------+ +------+------+                         |
|            |               |               |                                |
|            +---------------+---------------+                                |
|                            v                                                |
|                   Results returned to                                       |
|                      Main Agent                                             |
|                                                                             |
+-----------------------------------------------------------------------------+

لماذا تستخدم «sub-agents»؟

  • نوافذ سياق منفصلة: كل «sub-agent» له «context window» خاص. لا يلوث المحادثة الرئيسية بتفاصيل لا تحتاجها.
  • تعليمات متخصصة: مراجع الـ «code» يركز على الأمن. كاتب الاختبارات يتبع أسلوب مشروعك في الاختبار.
  • صلاحيات محددة للـ «tools»: المراجع يحتاج قراءة فقط. كاتب الاختبارات يحتاج كتابة. أنت تحدد ذلك لكل «agent».
  • عمل متوازٍ: أكثر من «sub-agent» يستطيع العمل في الوقت نفسه على أجزاء مختلفة من المهمة.

الـ «sub-agents» الجاهزة

يأتي «Claude Code» باثنين من الـ «sub-agents» الجاهزة:

text
+---------+-----------------------------------------+--------------------------------+
| Agent   | Purpose                                 | Tools                          |
+---------+-----------------------------------------+--------------------------------+
| Explore | Fast codebase search and analysis       | Read-only: ls, cat, grep, find |
| Plan    | Creates detailed implementation plans   | Read-only: analyzes before     |
|         |                                         | suggesting changes             |
+---------+-----------------------------------------+--------------------------------+

إنشاء «sub-agents» خاصة بك

تستطيع بناء «agents» متخصصة تناسب مشروعك.

الخطوة 1: شغل الأمر

bash
/agents

الخطوة 2: اختر إنشاء «agent» جديد

سيطلب منك «Claude» وصفًا لما يفعله هذا الـ «agent». كن محددًا:

text
> Create an agent called "security-reviewer" that:
  - Reviews code for security vulnerabilities
  - Focuses on input validation, SQL injection, XSS, and auth issues
  - Only has read access to files
  - Returns findings in a structured format

الخطوة 3: يكتب «Claude» ملف الـ «agent»

يحفظ الملف في .claude/agents/security-reviewer.md:

yaml
---
name: security-reviewer
description: Reviews code for security vulnerabilities including
  input validation, SQL injection, XSS, and authentication issues.
  Use when reviewing PRs or auditing code for security.
tools:
  - Read
  - Grep
  - Glob
---

# Security Reviewer

You are a security-focused code reviewer. Your job is to identify
vulnerabilities in code.

## Focus Areas
- Input validation and sanitization
- SQL injection vulnerabilities
- Cross-site scripting (XSS)
- Authentication and authorization flaws
- Sensitive data exposure
- Insecure dependencies

## Output Format
For each issue found:
1. File and line number
2. Vulnerability type
3. Risk level (Critical/High/Medium/Low)
4. Recommended fix

## Guidelines
- Be thorough but avoid false positives
- Prioritize critical issues first
- Suggest specific fixes, not vague advice

استخدام «sub-agents»

بعد إنشائها، يفوض «Claude» العمل لها تلقائيًا عندما يرى أن المهمة تناسبها. وتستطيع أيضًا استدعاءها صراحة:

text
> Use the security-reviewer agent to audit the authentication module

أو تكتب ببساطة:

text
> Use sub-agents to review this codebase

سيشغل «Claude» الـ «agents» المناسبة بالتوازي.

أماكن ملفات الـ «agents»

text
+--------------------+----------------------------------------------+
| Location           | Scope                                        |
+--------------------+----------------------------------------------+
| ~/.claude/agents/  | Available in all your projects               |
| .claude/agents/    | Available only in this project (can be       |
|                    | version controlled)                          |
+--------------------+----------------------------------------------+

الجزء الثالث: «hooks»، تشغيل تلقائي في الوقت المناسب

ما هي «hooks»؟

الـ «hooks» أوامر «shell» تعمل تلقائيًا في نقاط محددة من دورة حياة «Claude Code». فائدتها أنها لا تعتمد على ذاكرة «Claude». إذا أردت فحصًا قبل أمر خطر، أو تنسيقًا بعد تعديل ملف، اجعله «hook».

text
+-----------------------------------------------------------------------------+
|                            HOOK LIFECYCLE                                   |
+-----------------------------------------------------------------------------+
|                                                                             |
|   +---------------+                                                         |
|   | SessionStart  | --> Runs when Claude Code starts                        |
|   +---------------+                                                         |
|           |                                                                 |
|           v                                                                 |
|   +-------------------+                                                     |
|   | UserPromptSubmit  | --> Runs when you submit a prompt                   |
|   +-------------------+                                                     |
|           |                                                                 |
|           v                                                                 |
|   +---------------+                                                         |
|   |  PreToolUse   | --> Runs BEFORE a tool executes (can block)             |
|   +---------------+                                                         |
|           |                                                                 |
|           v                                                                 |
|   +---------------+                                                         |
|   |   Tool Runs   |                                                         |
|   +---------------+                                                         |
|           |                                                                 |
|           v                                                                 |
|   +---------------+                                                         |
|   | PostToolUse   | --> Runs AFTER a tool completes                         |
|   +---------------+                                                         |
|           |                                                                 |
|           v                                                                 |
|   +---------------+                                                         |
|   |  Notification | --> Runs when Claude sends a notification               |
|   +---------------+                                                         |
|           |                                                                 |
|           v                                                                 |
|   +---------------+                                                         |
|   |     Stop      | --> Runs when Claude finishes responding                |
|   +---------------+                                                         |
|                                                                             |
+-----------------------------------------------------------------------------+

الأحداث الثمانية للـ «hooks»

text
+------------------+---------------------------+------------------------------+
| Hook             | When It Fires             | Use Cases                    |
+------------------+---------------------------+------------------------------+
| SessionStart     | Claude Code starts or     | Load context, check          |
|                  | resumes                   | environment                  |
| UserPromptSubmit | You submit a prompt       | Validate input, add context  |
| PreToolUse       | Before any tool runs      | Block dangerous commands,    |
|                  |                           | validate paths               |
| PostToolUse      | After any tool completes  | Run formatters, log actions  |
| PreCompact       | Before context compaction | Backup transcripts           |
| Notification     | Claude sends notification | Custom alerts, Slack msgs    |
| Stop             | Claude finishes responding| Play sound, send notification|
| SubagentStop     | A sub-agent finishes      | Validate sub-agent output    |
+------------------+---------------------------+------------------------------+

إنشاء «hooks»

الطريقة 1: من الأمر التفاعلي

bash
/hooks

يفتح لك هذا الأمر قائمة لإعداد الـ «hooks».

الطريقة 2: من ملف الإعدادات

أنشئ أو عدل .claude/settings.json:

json
{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "Write|Edit",
        "hooks": [
          {
            "type": "command",
            "command": "prettier --write \"$CLAUDE_FILE_PATH\"",
            "timeout": 30
          }
        ]
      }
    ]
  }
}

أمثلة عملية على «hooks»

تنسيق تلقائي بعد تعديل الملفات:

json
{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "Write|Edit",
        "hooks": [
          {
            "type": "command",
            "command": "npx prettier --write \"$CLAUDE_PROJECT_DIR\"/**/*.{js,ts,jsx,tsx}"
          }
        ]
      }
    ]
  }
}

منع الأوامر الخطرة:

json
{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Bash",
        "hooks": [
          {
            "type": "command",
            "command": "echo \"$CLAUDE_TOOL_INPUT\" | grep -qE 'rm\\s+-rf|sudo\\s+rm' && exit 2 || exit 0"
          }
        ]
      }
    ]
  }
}

تشغيل صوت عندما ينهي «Claude» رده:

json
{
  "hooks": {
    "Stop": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "afplay /System/Library/Sounds/Glass.aiff"
          }
        ]
      }
    ]
  }
}

إضافة سياق عند بداية الجلسة:

json
{
  "hooks": {
    "SessionStart": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "echo \"Git status: $(git status --short)\nRecent commits: $(git log --oneline -5)\""
          }
        ]
      }
    ]
  }
}

رموز الخروج في «hooks»

text
+-----------+------------------------------------------------+
| Exit Code | Behavior                                       |
+-----------+------------------------------------------------+
| 0         | Success - continue normally                    |
| 1         | Failure - show error but continue              |
| 2         | Block - prevent the action (for PreToolUse)    |
+-----------+------------------------------------------------+

متغيرات البيئة المتاحة داخل «hooks»

text
+---------------------+------------------------------------------+
| Variable            | Description                              |
+---------------------+------------------------------------------+
| CLAUDE_PROJECT_DIR  | Absolute path to project root           |
| CLAUDE_TOOL_INPUT   | JSON input for the tool                  |
| CLAUDE_FILE_PATH    | Path to file being modified              |
| CLAUDE_CODE_REMOTE  | "true" if running remotely               |
+---------------------+------------------------------------------+

الجزء الرابع: «skills»، خبرة محفوظة في مجلد

ما هي «skills»؟

الـ «skills» مجلدات فيها تعليمات و«scripts» ومراجع يحملها «Claude» عند الحاجة. هي طريقة لتغليف خبرة متكررة، ثم استخدامها في أكثر من مهمة من دون إعادة شرحها كل مرة.

text
~/.claude/skills/
|
|-- pdf/
|   |-- SKILL.md            <-- Required: metadata + instructions
|   |-- extract_text.py     <-- Optional: executable scripts
|   |-- forms.md            <-- Optional: reference documentation
|   +-- templates/
|       +-- summary.html    <-- Optional: templates
|
+-- code-review/
    |-- SKILL.md
    |-- checklist.md
    +-- patterns/
        |-- security.md
        +-- performance.md

كيف تعمل «skills»: الكشف التدريجي

تعتمد الـ «skills» على فكرة بسيطة: لا تحمل كل شيء من البداية. يحمل «Claude» ما يحتاجه فقط، عندما يحتاجه.

text
+-----------------------------------------------------------------------------+
|                      PROGRESSIVE DISCLOSURE                                 |
+-----------------------------------------------------------------------------+
|                                                                             |
|   STAGE 1: Startup                                                          |
|   +---------------------------------------------------------------------+   |
|   | Context Window                                                      |   |
|   |                                                                     |   |
|   |  System Prompt + Skill Metadata Only                                |   |
|   |                                                                     |   |
|   |  "pdf: Manipulates PDF files. Use when working with PDFs."          |   |
|   |  "code-review: Reviews code quality. Use when reviewing code."      |   |
|   |                                                                     |   |
|   |  (~100 tokens per skill)                                            |   |
|   +---------------------------------------------------------------------+   |
|                                                                             |
|   STAGE 2: Skill Triggered                                                  |
|   +---------------------------------------------------------------------+   |
|   | Context Window                                                      |   |
|   |                                                                     |   |
|   |  System Prompt + SKILL.md Contents Loaded                           |   |
|   |                                                                     |   |
|   |  Full instructions from pdf/SKILL.md now in context                 |   |
|   |                                                                     |   |
|   |  (~2-5k tokens)                                                     |   |
|   +---------------------------------------------------------------------+   |
|                                                                             |
|   STAGE 3: Reference Files (As Needed)                                      |
|   +---------------------------------------------------------------------+   |
|   | Context Window                                                      |   |
|   |                                                                     |   |
|   |  SKILL.md references forms.md -> Claude reads it                    |   |
|   |  SKILL.md says "run extract_text.py" -> Claude runs it              |   |
|   |  (Script output added, not script code)                             |   |
|   |                                                                     |   |
|   +---------------------------------------------------------------------+   |
|                                                                             |
+-----------------------------------------------------------------------------+

إنشاء «skill»

الخطوة 1: أنشئ المجلد

bash
mkdir -p ~/.claude/skills/api-design

الخطوة 2: أنشئ ملف SKILL.md

yaml
---
name: api-design
description: Designs RESTful APIs following best practices. Use when
  creating new APIs, reviewing API designs, or discussing REST conventions.
---

# API Design Skill

## Instructions

When designing APIs:

1. Use plural nouns for resources (`/users`, not `/user`)
2. Use HTTP methods correctly:
   - GET: Read (no side effects)
   - POST: Create
   - PUT: Replace
   - PATCH: Partial update
   - DELETE: Remove

3. Return appropriate status codes:
   - 200: Success
   - 201: Created
   - 204: No content
   - 400: Bad request
   - 401: Unauthorized
   - 404: Not found
   - 500: Server error

4. Use consistent response formats:

```json
{
  "data": { ... },
  "meta": { "total": 100, "page": 1 },
  "errors": []
}
```

## Reference
See `conventions.md` for company-specific patterns.

الخطوة 3: أضف ملفات مرجعية إذا احتجت

أنشئ conventions.md وضع فيه قواعد الـ API الخاصة بفريقك.

أماكن «skills»

text
+--------------------+--------------------+----------------------+
| Location           | Scope              | Version Controlled?  |
+--------------------+--------------------+----------------------+
| ~/.claude/skills/  | All your projects  | No                   |
| .claude/skills/    | This project only  | Yes (recommended)    |
| Plugin skills      | Via plugin install | Depends on plugin    |
+--------------------+--------------------+----------------------+

الـ «skills» الجاهزة

يتضمن «Claude Code» مهارات جاهزة لإنشاء المستندات:

text
+-------+----------------------------------------------+
| Skill | Purpose                                      |
+-------+----------------------------------------------+
| docx  | Create and edit Word documents               |
| xlsx  | Create and edit Excel spreadsheets           |
| pptx  | Create and edit PowerPoint presentations     |
| pdf   | Create, fill, and manipulate PDFs            |
+-------+----------------------------------------------+

الجزء الخامس: «MCP servers»، وصلات إلى العالم الخارجي

ما هو «MCP»؟

الـ «MCP» معيار مفتوح لربط الذكاء الاصطناعي بالـ «tools» والبيانات خارج المحادثة. ومع «MCP servers»، يصل «Claude» إلى أشياء خارج جهازك المحلي: مستودعات، قواعد بيانات، أدوات تصميم، أو أنظمة مراقبة.

text
+-----------------------------------------------------------------------------+
|                           MCP ARCHITECTURE                                  |
+-----------------------------------------------------------------------------+
|                                                                             |
|                         +-----------------+                                 |
|                         |   Claude Code   |                                 |
|                         |   (MCP Client)  |                                 |
|                         +--------+--------+                                 |
|                                  |                                          |
|              +-------------------+-------------------+                      |
|              |                   |                   |                      |
|              v                   v                   v                      |
|     +-----------------+ +-----------------+ +-----------------+             |
|     |  GitHub MCP     | |   Slack MCP     | |  Database MCP   |             |
|     |    Server       | |    Server       | |    Server       |             |
|     +--------+--------+ +--------+--------+ +--------+--------+             |
|              |                   |                   |                      |
|              v                   v                   v                      |
|     +-----------------+ +-----------------+ +-----------------+             |
|     |    GitHub       | |     Slack       | |   PostgreSQL    |             |
|     |      API        | |      API        | |    Database     |             |
|     +-----------------+ +-----------------+ +-----------------+             |
|                                                                             |
+-----------------------------------------------------------------------------+

ماذا يفعل «MCP»؟

عندما تربط «MCP servers»، يستطيع «Claude» أن يعمل مع:

  • GitHub: إنشاء «PRs»، وإدارة «issues»، ومراجعة «code»
  • Slack: إرسال الرسائل وقراءة القنوات
  • Databases: الاستعلام من PostgreSQL وMySQL وغيرها
  • Notion: قراءة الصفحات وكتابتها
  • Sentry: فحص سجلات الأخطاء
  • Figma: استخراج التصاميم
  • File systems: الوصول إلى ملفات بعيدة

إضافة «MCP servers»

الطريقة 1: أمر «CLI»

bash
# Add GitHub MCP server
claude mcp add github -- npx -y @anthropic-ai/github-mcp-server

# Add with environment variable
claude mcp add github -- npx -y @anthropic-ai/github-mcp-server \
  --env GITHUB_TOKEN=your_token_here

# Add HTTP server
claude mcp add --transport http notion https://mcp.notion.com/mcp

الطريقة 2: إعدادات المشروع

أنشئ .mcp.json في جذر المشروع:

json
{
  "mcpServers": {
    "github": {
      "command": "npx",
      "args": ["-y", "@anthropic-ai/github-mcp-server"],
      "env": {
        "GITHUB_TOKEN": "${GITHUB_TOKEN}"
      }
    },
    "postgres": {
      "command": "npx",
      "args": ["-y", "@anthropic-ai/postgres-mcp-server"],
      "env": {
        "DATABASE_URL": "${DATABASE_URL}"
      }
    }
  }
}

الطريقة 3: إعدادات على مستوى المستخدم

أضفها إلى ~/.claude/settings.json إذا أردت أن تكون الخوادم متاحة في كل مشاريعك.

«MCP servers» شائعة

text
+-------------------------+----------------------------------+
| Server                  | What It Does                     |
+-------------------------+----------------------------------+
| github-mcp-server       | GitHub repos, issues, PRs        |
| slack-mcp-server        | Slack messages and channels      |
| postgres-mcp-server     | PostgreSQL queries               |
| notion-mcp-server       | Notion pages and databases       |
| puppeteer-mcp-server    | Browser automation               |
| filesystem-mcp-server   | Remote file access               |
| sentry-mcp-server       | Error monitoring                 |
+-------------------------+----------------------------------+

موارد «MCP»

تستطيع «MCP servers» كشف موارد تشير إليها باستخدام @:

text
> @github:issues list open issues assigned to me
> @notion:pages find the Q4 roadmap
> @postgres:schema show me the users table structure

الجزء السادس: CLAUDE.md، ملفات الذاكرة

ما هو CLAUDE.md؟

ملفات CLAUDE.md هي ذاكرة يحملها «Claude» عند بداية الجلسة. تضع فيها سياق المشروع، وقواعد الفريق، والتعليمات التي تريدها أن تبقى بين جلسة وأخرى.

text
+-----------------------------------------------------------------------------+
|                         CLAUDE.MD HIERARCHY                                 |
+-----------------------------------------------------------------------------+
|                                                                             |
|   PRECEDENCE (Higher overrides lower)                                       |
|                                                                             |
|   +-----------------------------------------+                               |
|   |  Enterprise Settings                    |  <-- Managed by admins        |
|   |  (highest precedence)                   |                               |
|   +-----------------------------------------+                               |
|                     |                                                       |
|                     v                                                       |
|   +-----------------------------------------+                               |
|   |  Project: ./CLAUDE.md                   |  <-- Shared with team         |
|   |  (version controlled)                   |      via git                  |
|   +-----------------------------------------+                               |
|                     |                                                       |
|                     v                                                       |
|   +-----------------------------------------+                               |
|   |  Project Local: ./CLAUDE.local.md       |  <-- Your personal            |
|   |  (gitignored)                           |      project overrides        |
|   +-----------------------------------------+                               |
|                     |                                                       |
|                     v                                                       |
|   +-----------------------------------------+                               |
|   |  User: ~/.claude/CLAUDE.md              |  <-- Your personal            |
|   |  (lowest precedence)                    |      preferences              |
|   +-----------------------------------------+                               |
|                                                                             |
+-----------------------------------------------------------------------------+

CLAUDE.md على مستوى المستخدم

يوجد في ~/.claude/CLAUDE.md، ويطبق على كل مشاريعك.

yaml
# Global Development Preferences

## Code Style
- Use TypeScript strict mode
- Prefer functional programming patterns
- Write descriptive variable names
- Add JSDoc comments for public functions

## Communication
- Be concise and direct
- Show code, don't just describe it
- Ask clarifying questions before large changes

## Testing
- Write tests for new features
- Prefer integration tests over unit tests
- Use descriptive test names

## Git
- Write clear commit messages
- Keep commits atomic
- Reference issue numbers when applicable

CLAUDE.md على مستوى المشروع

يوجد في ./CLAUDE.md داخل جذر المشروع. هذا ملف خاص بمشروع واحد، والأفضل أن يدخل في «git» مع باقي ملفات المشروع.

yaml
# Project: E-commerce Platform

## Tech Stack
- Next.js 14 with App Router
- TypeScript strict mode
- Tailwind CSS
- PostgreSQL with Prisma ORM
- Redis for caching

## Directory Structure

src/
|-- app/          # Next.js pages and layouts
|-- components/   # React components
|-- lib/          # Utilities and helpers
|-- services/     # Business logic
+-- types/        # TypeScript types

## Key Commands
- `npm run dev` - Start development server
- `npm run build` - Build for production
- `npm run test` - Run test suite
- `npm run lint` - Run ESLint
- `npm run db:migrate` - Run database migrations

## Conventions
- Components use PascalCase
- Utilities use camelCase
- Database tables use snake_case
- API routes return JSON with `{ data, error }` shape

## Important Notes
- Auth is handled by NextAuth.js in `src/lib/auth.ts`
- Environment variables are in `.env.local` (never commit)
- Legacy code in `/legacy` should not be modified

CLAUDE.local.md للملاحظات الشخصية

يوجد في ./CLAUDE.local.md. هذا مكان مناسب للتفضيلات الشخصية أو إعدادات جهازك، ولا يفترض مشاركته مع الفريق.

yaml
# My Local Overrides

## Personal Preferences
- I prefer verbose explanations when learning new patterns
- Always show me the git diff before committing

## Local Environment
- My database is running on port 5433 (not default 5432)
- Use `docker compose -f docker-compose.local.yml up`

تعديل ملفات الذاكرة

استخدم أمر /memory لتعديل ملفات الذاكرة مباشرة:

bash
/memory

أو استخدم اختصار # لإضافة ملاحظة بسرعة:

text
# Always run tests before committing

سيضيفها «Claude» إلى ملف CLAUDE.md المناسب.

قواعد عملية لملفات CLAUDE.md

  • اجعلها قصيرة: انتباه «Claude» محدود. كل سطر زائد ينافس ما هو أهم.
  • كن محددًا: «استخدم Tailwind» أوضح من «اتبع ممارسات CSS حديثة».
  • حدثها باستمرار: أضف ما تتعلمه أثناء العمل. واحذف المعلومات القديمة.
  • استخدم الكشف التدريجي: أشر إلى ملفات أخرى بدل أن تضع كل شيء في ملف واحد.

الجزء السابع: «plugins»، حزم جاهزة للتخصيص

ما هي «plugins»؟

الـ «plugins» تجمع أكثر من تخصيص في حزمة واحدة: «slash commands»، و«sub-agents»، و«MCP servers»، و«hooks»، و«skills». تثبتها بأمر واحد، فتنتقل معها مجموعة كاملة من السلوكيات.

text
my-plugin/
|
|-- manifest.json          <-- Plugin metadata
|
|-- commands/              <-- Slash commands
|   |-- review.md
|   +-- deploy.md
|
|-- agents/                <-- Sub-agents
|   |-- security-expert.md
|   +-- performance-analyst.md
|
|-- skills/                <-- Skills
|   +-- api-testing/
|       +-- SKILL.md
|
|-- hooks/                 <-- Hooks
|   +-- hooks.json
|
+-- mcp/                   <-- MCP server configs
    +-- servers.json

تثبيت «plugins»

من متجر:

bash
/plugin marketplace add anthropics/skills
/plugin install document-skills@anthropics/skills

من رابط:

bash
/plugin install https://github.com/user/my-plugin

من مجلد محلي:

bash
/plugin add /path/to/my-plugin

إدارة «plugins»

bash
/plugin list                  # See installed plugins
/plugin remove plugin-name    # Uninstall a plugin
/plugin update plugin-name    # Update to latest version

متاجر «plugins» شائعة

text
+-------------------------------+----------------------------------+
| Marketplace                   | Focus                            |
+-------------------------------+----------------------------------+
| anthropics/skills             | Official Anthropic skills        |
| Community marketplaces        | Third-party collections          |
| Your organization's           | Internal tools                   |
| marketplace                   |                                  |
+-------------------------------+----------------------------------+

الجزء الثامن: «slash commands»، اختصاراتك الخاصة

ما هي «slash commands»؟

الـ «slash commands» هي «prompts» قابلة لإعادة الاستخدام، محفوظة كملفات «markdown». اكتب / لترى الأوامر المتاحة.

إنشاء «slash commands»

على مستوى المستخدم، لكل المشاريع:

bash
mkdir -p ~/.claude/commands

أنشئ ~/.claude/commands/review.md:

yaml
Review this code for:

1. **Security Issues**
   - Input validation
   - SQL injection
   - XSS vulnerabilities

2. **Performance**
   - Unnecessary loops
   - N+1 queries
   - Missing indexes

3. **Code Quality**
   - Naming conventions
   - Code duplication
   - Error handling

Be specific about file locations and line numbers.

على مستوى المشروع:

أنشئ .claude/commands/fix-issue.md:

yaml
Fix GitHub issue: $ARGUMENTS

Steps:
1. Use `gh issue view $ARGUMENTS` to get details
2. Search codebase for relevant files
3. Implement the fix
4. Write tests
5. Create a commit with message referencing the issue

استخدام «slash commands»

bash
/review                      # Run user-level command
/project:fix-issue 1234      # Run project command with argument

متغير $ARGUMENTS

تستطيع الأوامر استقبال مدخلات عبر $ARGUMENTS:

yaml
Create a new component called $ARGUMENTS with:
- TypeScript
- Tailwind styling
- Unit tests
- Storybook story

الاستخدام: /project:new-component Button

الجزء التاسع: كيف تجتمع القطع؟

مثال إعداد كامل

في مشروع حقيقي، قد تبدو الصورة بهذا الشكل:

text
my-project/
|
|-- .claude/
|   |-- settings.json              # Hooks and permissions
|   |-- settings.local.json        # Personal settings (gitignored)
|   |
|   |-- commands/                  # Project slash commands
|   |   |-- review-pr.md
|   |   |-- fix-issue.md
|   |   +-- deploy.md
|   |
|   |-- agents/                    # Project sub-agents
|   |   |-- security-reviewer.md
|   |   |-- test-writer.md
|   |   +-- docs-writer.md
|   |
|   +-- skills/                    # Project skills
|       +-- api-conventions/
|           +-- SKILL.md
|
|-- .mcp.json                      # MCP server configuration
|
|-- CLAUDE.md                      # Project memory (version controlled)
|-- CLAUDE.local.md                # Personal memory (gitignored)
|
+-- src/
    +-- ...

مثال سير عمل

text
+-----------------------------------------------------------------------------+
|                      EXAMPLE WORKFLOW: FIX A BUG                            |
+-----------------------------------------------------------------------------+
|                                                                             |
|   You: /project:fix-issue 1234                                              |
|                                                                             |
|   +---------------------------------------------------------------------+   |
|   |                                                                     |   |
|   |   1. SessionStart hook runs                                         |   |
|   |      +-> Loads git status and recent commits                        |   |
|   |                                                                     |   |
|   |   2. Claude reads CLAUDE.md                                         |   |
|   |      +-> Understands project conventions                            |   |
|   |                                                                     |   |
|   |   3. Claude uses GitHub MCP server                                  |   |
|   |      +-> Fetches issue #1234 details                                |   |
|   |                                                                     |   |
|   |   4. Claude delegates to Explore sub-agent                          |   |
|   |      +-> Finds relevant files without bloating context              |   |
|   |                                                                     |   |
|   |   5. Claude makes the fix                                           |   |
|   |      +-> PreToolUse hook validates file paths                       |   |
|   |      +-> PostToolUse hook runs Prettier                             |   |
|   |                                                                     |   |
|   |   6. Claude delegates to test-writer sub-agent                      |   |
|   |      +-> Adds test coverage                                         |   |
|   |                                                                     |   |
|   |   7. Claude commits with issue reference                            |   |
|   |      +-> Uses GitHub MCP to create PR                               |   |
|   |                                                                     |   |
|   |   8. Stop hook runs                                                 |   |
|   |      +-> Desktop notification sent                                  |   |
|   |                                                                     |   |
|   +---------------------------------------------------------------------+   |
|                                                                             |
+-----------------------------------------------------------------------------+

مرجع سريع

أماكن الملفات

text
+----------+---------------------------+---------------------------+
| What     | User-Level                | Project-Level             |
+----------+---------------------------+---------------------------+
| Memory   | ~/.claude/CLAUDE.md       | ./CLAUDE.md               |
| Settings | ~/.claude/settings.json   | ./.claude/settings.json   |
| Commands | ~/.claude/commands/       | ./.claude/commands/       |
| Agents   | ~/.claude/agents/         | ./.claude/agents/         |
| Skills   | ~/.claude/skills/         | ./.claude/skills/         |
| MCP      | ~/.claude/settings.json   | ./.mcp.json               |
+----------+---------------------------+---------------------------+

أوامر مفيدة

text
+----------+------------------------------------+
| Command  | Purpose                            |
+----------+------------------------------------+
| /agents  | Manage sub-agents                  |
| /hooks   | Configure hooks                    |
| /memory  | Edit memory files                  |
| /plugin  | Manage plugins                     |
| /config  | Open settings                      |
| /model   | Switch AI model                    |
| /compact | Compress context                   |
+----------+------------------------------------+

أنواع «hooks»

text
+------------------+---------+----------------------------+
| Hook             | Blocks? | When to Use                |
+------------------+---------+----------------------------+
| SessionStart     | No      | Load context               |
| UserPromptSubmit | Yes     | Validate input             |
| PreToolUse       | Yes     | Block dangerous commands   |
| PostToolUse      | No      | Run formatters             |
| Stop             | No      | Notifications              |
+------------------+---------+----------------------------+