Claude Code: إعداد الصلاحيات

آخر تحديث: 2026-08-31

يملك Claude Code صلاحيات عالية — يستطيع قراءة/كتابة الملفات وتنفيذ الأوامر والوصول للشبكات. فهم وإعداد الصلاحيات أساس للاستخدام الآمن.

💡 نصيحة: افتراضياً، يوافق Claude Code تلقائياً على القراءة، ويطلب تأكيداً للكتابة والتنفيذ. يمكنك تعديل هذا التوازن عبر إعداد الصلاحيات.

📋 المتطلبات المسبقة: الفصل 10 - إدارة السياق

1. ما ستتعلمه


2. نموذج الصلاحيات

(1) فئات العمليات والصلاحيات الافتراضية

نوع العملية مثال الصلاحية الافتراضية ملاحظات
قراءة قراءة ملفات، عرض أدلة مسموح تلقائياً للقراءة فقط، بلا مخاطرة
كتابة إنشاء/تعديل ملفات يتطلب تأكيداً الموافقة التلقائية قابلة للتكوين
باش تنفيذ أوامر shell يتطلب تأكيداً مخاطرة عالية، يُوصى بالاحتفاظ بالتأكيد
شبكة تثبيت حزم، استدعاءات API يتطلب تأكيداً وصول خارجي، مخاطرة أمنية
MCP استدعاء أدوات MCP يتطلب تأكيداً يعتمد على وظيفة الأداة

(2) خيارات التأكيد

TEXT 📖 للعرض فقط
Claude wants to execute: npm install lodash
  [Allow / Deny / Always for this session]

▶ مثال 1: سيناريوهات تأكيد الصلاحيات

TEXT 📖 للعرض فقط
# Read: auto-approved
→ Reading src/index.ts ✓ (auto-approved)

# Modify: needs confirmation
→ Modifying src/index.ts
  Allow editing? [y/n/a] y

# Execute: needs confirmation
→ Running: npm test
  Allow executing: npm test? [y/n/a] a
  (Set to auto-allow for this session)

3. إعداد الموافقة التلقائية

(1) الإعداد في CLAUDE.md

MARKDOWN
## Permission Configuration
- Auto-allow editing .ts and .test.ts files under src/
- Auto-allow running npm test and npm run lint
- Auto-allow running npm install (adding dependencies)
- Require confirmation: modifying prisma/schema.prisma
- Require confirmation: modifying package.json scripts
- Require confirmation: any git operations
- Deny: executing curl/wget and other network request commands

(2) معاملات سطر الأوامر

BASH
# Only allow read and write (no command execution)
claude --allowed-tools Read,Write

# Allow read, write, and specific Bash commands
claude --allowed-tools Read,Write,Bash(npm test),Bash(npm run lint)

# Fully auto mode (dangerous!)
claude --allow-full-auto

▶ مثال 2: إعداد صلاحيات على مستوى المشروع

MARKDOWN
<!-- Test project CLAUDE.md (relaxed permissions) -->
## Permissions
- Auto-allow: All file edits
- Auto-allow: npm test, npm run build, npm run lint
- Auto-allow: git add, git commit
- Require confirmation: npm publish, git push

<!-- Production project CLAUDE.md (strict permissions) -->
## Permissions
- Auto-allow: Read-only operations
- Require confirmation: All file modifications
- Require confirmation: All command executions
- Deny: git push, npm publish, rm -rf
- Deny: Modifying .env and config files

4. الوضع المقيد

(1) وضع القراءة فقط

BASH
# Completely read-only, no file modifications
claude --allowed-tools Read

# Read-only + safe Bash commands
claude --allowed-tools Read,Bash(git status),Bash(npm test)

(2) وضع الصندوق الرملي

BASH
# Run in sandbox, changes don't affect real files
claude --sandbox

5. حماية المشاريع الحساسة

(1) ملف .claudeignore

TEXT 📖 للعرض فقط
# .claudeignore - Exclude sensitive files
.env
.env.*
**/secrets/**
**/credentials/**
**/private-key.*
config/production.*

(2) استراتيجية الحماية

نوع الملف طريقة الحماية السبب
.env استبعاد بـ .claudeignore يحتوي أسراراً
secrets/ .claudeignore + تأكيد دليل بيانات الاعتماد
schema.prisma وضع علامة في CLAUDE.md للتأكيد تغييرات هيكل قاعدة البيانات عالية المخاطرة
package.json وضع علامة في CLAUDE.md للتأكيد تغييرات التبعيات تحتاج مراجعة

▶ مثال 3: إعداد صلاحيات مشروع مالي

MARKDOWN
## Permissions (Strict Mode)
- Auto-allow: Read-only operations
- Require confirmation: All file modifications (including src/)
- Require confirmation: All Bash commands
- Deny: Modify files under src/payment/ and src/billing/
- Deny: Run any database operation commands
- Deny: Modify Docker and CI configuration

6. مثال شامل: استراتيجية صلاحيات الفريق

TEXT 📖 للعرض فقط
# Level 1: Personal experimental projects
claude --allow-full-auto (Fully auto, rapid iteration)

# Level 2: Team development projects
- CLAUDE.md configures auto-edit src/ and tests/
- Auto-run npm test
- Git operations need confirmation

# Level 3: Core business projects
- Read-only mode + manual confirm writes
- .claudeignore protects sensitive directories
- All changes go through git diff review

# Level 4: Production/Financial projects
- Read-only mode
- Output suggestions, don't directly modify
- Human review before manual application

❓ أسئلة شائعة

س هل --allow-full-auto آمن؟
ج لا. وضع الأتمتة الكاملة لا يؤكد، يناسب مشاريع الاختبار و CI. لا تستخدمه أبداً في الإنتاج.
س ما الفرق بين .claudeignore و .gitignore؟
ج .gitignore يتحكم بالملفات التي يتجاهلها git؛ .claudeignore يتحكم بالملفات التي لن يقرأها Claude Code. يعملان بشكل مستقل.
س هل يمكن لـ Claude Code تجاوز إعداد الصلاحيات؟
ج عادةً لا. لكنه قد ينفذ عمليات غير مصرح بها بشكل غير مباشر عبر أوامر باش. احمِ البيانات الحرجة على مستوى نظام الملفات.
س كيف ألغي تفويض "دائماً"؟
ج اخرج من الجلسة الحالية. "دائماً" يعمل فقط ضمن الجلسة الحالية؛ الجلسات الجديدة تعيد الصلاحيات الافتراضية.
س كيف أوحّد إعداد صلاحيات الفريق؟
ج ألتزم CLAUDE.md و .claudeignore في git؛ أعضاء الفريق يتشاركون تلقائياً نفس قواعد الصلاحيات.

📖 ملخص


📝 تمارين

  1. أساسي (⭐): اضبط .claudeignore لاستبعاد .env، تحقق أن Claude Code لم يعد يقرأه.
  2. متوسط (⭐⭐): اكتب إعداد صلاحيات لمشروعك يميز بين العمليات بموافقة تلقائية والعمليات التي تحتاج تأكيد.
  3. متقدم (⭐⭐⭐): صمم استراتيجية صلاحيات على مستوى الفريق تغطي السيناريوهات الشخصية والفريقية والإنتاجية.
Web-Tutorial.com

فريق Web-Tutorial التقني

منصة دروس برمجية يديرها عدة مطورين. كل درس يتم كتابته ومراجعته بواسطة مطورين متخصصين في المجال. نعمل على ضمان دقة وموثوقية المحتوى — إذا لاحظت أي مشكلة، فيرجى إخبارنا.

100%