ATLAS ROOM
→ الرئيسية
🪝HOOKS

Claude يختبر الكود بنفسه

مرحبًا! 👋 إليك ما وعدتك به:

Claude Code Hooks — أوامر تعمل تلقائيًا مع كل خطوة يقوم بها Claude: هو يقوم بالتعديل، والـ hook يختبر بعده مباشرة — دون أن تطلب منه ذلك. هذان هما الـ hook اللذان أستخدمهما أنا:

- ON EDIT → أي code تعدّله، يُجرى عليه test + lint تلقائيًا.

- PRE-COMMIT → قبل أي commit، يفحص إن كان هناك أي secret / password / API key في الـ files — إذا وجد شيئًا يمنع الـ commit حتى لا تكسر شيئًا.

🔗الوثائق الرسميةhttps://code.claude.com/docs/en/hooks

كيفية البدء

  1. أضف هذا إلى ملف `.claude/settings.json` الخاص بمشروعك (استبدل `npm test && npm run lint` بأوامر مشروعك):
{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "Edit|Write",
        "hooks": [
          { "type": "command", "command": "npm test && npm run lint" }
        ]
      }
    ],
    "PreToolUse": [
      {
        "matcher": "Bash",
        "hooks": [
          { "type": "command", "command": "git diff --cached | grep -qiE 'api[_-]?key|secret|password' && echo 'STOP: secrets f staged files!' >&2 && exit 2 || exit 0" }
        ]
      }
    ]
  }
}
`exit 2` هو ما يمنع العملية: يتوقف Claude ويقرأ رسالة الخطأ.
  1. أضف الـ rule إلى ملف `CLAUDE.md` الخاص بالمشروع حتى تصبح عادة لدى Claude:
Any code you write or edit, run the tests before you consider the task done.
Big changes = test the whole workflow.
  1. جرّب: اطلب من Claude أن يعدّل ملفًا — سترى الـ tests تعمل من تلقاء نفسها بعده مباشرة. ✅