شعار Hooks Automation

Hooks Automation

المجتمع
frankxai
hooks-automation

Configure and automate Claude Code hooks in .claude/settings.json (PreToolUse, PostToolUse, UserPromptSubmit, Stop, SubagentStop, SessionEnd). Use when setting up Claude Code hooks to auto-format files after edits, run pre-commit or safety checks before Bash commands, guard secrets or protected files, save session state on Stop or SessionEnd, or wire optional external CLI and MCP hook runners.

نظرة عامة

الناشرfrankxai
المستودعclaude-skills-library
اسم المهارةhooks-automation
النجوم
47
التفريعات
6
الملفات المرفقة
5
الترخيصMIT
الروابط
  • تعليمات بصيغة Markdown

    ملف SKILL.md يُحمّله النموذج عند الحاجة، فلا يستهلك توكنات إلا عندما يَرِد طلب ذو صلة فعلًا.

  • تعمل مع أي نموذج لغوي كبير

    مهارات الذكاء الاصطناعي مكتوبة بصيغة Markdown وليست شيفرة خاصة بمزوّد معيّن، لذا تعمل مع GPT أو Claude أو Gemini أو Grok أو نموذج محلي.

  • الملفات المرفقة: 5

    نصوص برمجية وقوالب ومراجع يمكن للنموذج قراءتها أثناء عمله. الملفات للقراءة فقط ولا تُنفّذ أبدًا.

  • مفتوحة المصدر

    نشرها frankxai على GitHub. اطّلع على المصدر قبل تثبيتها.

التثبيت

ثبّت مهارة الذكاء الاصطناعي Hooks Automation في TypingMind لاستخدامها مع أي نموذج لغوي كبير، أو أضفها إلى وكيل ذكاء اصطناعي آخر يقرأ SKILL.md.

1

التثبيت في TypingMind

يُثبّت TypingMind المهارة مباشرةً من مجلدها على GitHub — فيقرأ SKILL.md، ويجمع ملفات الموارد في حزمة، ويحفظ النتيجة محليًا.

  1. افتح التطبيق وانتقل إلى «الإضافات» ثم «المهارات».
  2. اختر «تثبيت من GitHub».
  3. الصق رابط مجلد المهارة الموضّح أدناه وأكّد التثبيت.
    https://github.com/frankxai/claude-skills-library/tree/main/free-skills/hooks-automation
  4. فعّل المهارة في كل محادثة تريد إتاحتها فيها.
الإضافات ← المهارات ← إضافة مهارة ← من رابط GitHub، ثم الصق رابط المجلد واضغط على «متابعة».
2

التثبيت في وكيل ذكاء اصطناعي آخر

يمكن لأي وكيل ذكاء اصطناعي يقرأ تنسيق Agent Skills استخدام هذه المهارة — انسخ المجلد إلى مجلد المهارات الخاص بذلك الوكيل.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/frankxai/claude-skills-library.git /tmp/claude-skills-library
mkdir -p .claude/skills
cp -r /tmp/claude-skills-library/free-skills/hooks-automation .claude/skills/hooks-automation
أعد تشغيل Claude Code بعد النسخ ليتعرّف على المهارة الجديدة.

استخدمها في TypingMind

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

يُحمّل النموذج مهارة Hooks Automation تلقائيًا بمجرد ورود طلب ذي صلة بها.

تعمل مع أي نموذج ذكاء اصطناعي

مهارات الذكاء الاصطناعي هي تعليمات بصيغة Markdown وليست شيفرة خاصة بمزوّد معيّن، لذا لا ترتبط Hooks Automation بالنموذج الذي كُتبت له. ثبّتها مرة واحدة في TypingMind واستخدمها مع GPT-5 أو Claude أو Gemini أو Grok أو DeepSeek أو Mistral أو Llama أو نموذج محلي تشغّله بنفسك — كل ذلك باستخدام مفاتيح API الخاصة بك.

  • تُحمَّل عند الحاجة فقط

    تتضمن مطالبة النظام الاسم والوصف فقط. وتُجلب التعليمات عند أول طلب ذي صلة، لذا لا تستهلك تعليمات المهارة أي توكنات ما دامت المهارة غير مستخدمة.

  • بدّل النماذج أثناء المحادثة

    لأن المهارة تعليمات وليست شيفرة، فإن تغيير النموذج لا يعطّلها — فالنموذج التالي يقرأ ملف SKILL.md نفسه.

تعليمات المهارة

هذا هو محتوى SKILL.md الذي يُحمّله النموذج. اقرأه قبل التثبيت — فالمهارة عبارة عن تعليمات سيتبعها نموذجك.

Claude Code Hooks Automation

Configure deterministic lifecycle hooks in .claude/settings.json (project) or ~/.claude/settings.json (user) so Claude Code automatically formats edited files, gates risky shell or Git commands before execution, blocks secret leaks or protected-file writes, and persists session state on completion.

Trigger Boundaries

  • Activate when: Setting up or debugging .claude/settings.json or ~/.claude/settings.json "hooks", writing PreToolUse / PostToolUse / UserPromptSubmit / Stop / SubagentStop / SessionEnd scripts, enforcing exit 2 blocking gates, or returning structured JSON decisions on stdout.
  • Do NOT activate when: Writing React hooks (useState, useEffect), Git-only .git/hooks/ without Claude Code lifecycle integration, or generic webhook endpoints (Stripe/Polar/GitHub HTTP webhooks).

Native Claude Code Hooks (settings.json)

Claude Code executes shell commands registered under the "hooks" key in .claude/settings.json at specific lifecycle events. Every hook receives a JSON payload on stdin and communicates back via exit codes and stdout/stderr.

Hook Lifecycle Events

EventWhen It FiresCommon Use Cases
PreToolUseBefore a tool call executes (matches tool_name via regex matcher)Block unsafe Bash commands, run pre-commit checks before git commit, guard secrets and protected files
PostToolUseAfter a tool call completes successfullyAuto-format files after Write, Edit, or MultiEdit; run targeted tests
UserPromptSubmitWhen the user submits a prompt, before Claude processes itInject repository context, validate prompt constraints
StopWhen the main Claude Code agent finishes respondingSave session state, log trajectory metrics, verify completion checks
SubagentStopWhen a spawned subagent (Task) finishes respondingAggregate subagent outputs, verify handoff receipts
SessionEndWhen a Claude Code session closes or terminatesPersist final session state, export metrics, clean up temporary artifacts

Exit Code, Stdin & JSON Stdout Decision Contract

  • Stdin JSON payload: Every hook command receives JSON on stdin containing session_id, transcript_path, cwd, hook_event_name, and (for tool hooks) tool_name, tool_input, and tool_response.
  • Exit code 0 (Allow): Operation proceeds normally. When exiting 0, a hook may also print structured JSON to stdout for fine-grained decision control:
    json
    {
      "hookSpecificOutput": {
        "hookEventName": "PreToolUse",
        "permissionDecision": "allow",
        "permissionDecisionReason": "Verified safe read-only command"
      }
    }
    (Supported permissionDecision values for PreToolUse: "allow", "deny", "ask"; for Stop / SubagentStop: {"decision": "block", "reason": "Run test suite before stopping"}.)
  • Exit code 2 (Block): Immediately blocks the action (for PreToolUse, prevents the tool call; for Stop, prevents stopping) and feeds stderr directly back to Claude so it can self-correct.
  • Any other non-zero exit code: Non-blocking warning; logged to debug output while execution continues.

Primary Recipes (.claude/settings.json)

Recipe 1: Auto-Format After Every Edit + Pre-Commit Check + Secret/File Guard

Place this configuration in .claude/settings.json to:

  1. Guard against secret leaks and protected file edits (PreToolUse on Write|Edit|MultiEdit),
  2. Run a pre-commit check before git commit (PreToolUse on Bash), and
  3. Run Prettier automatically after every file edit (PostToolUse on Write|Edit|MultiEdit):
json
{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Write|Edit|MultiEdit",
        "hooks": [
          {
            "type": "command",
            "command": ".claude/hooks/file-and-secret-guard.sh"
          }
        ]
      },
      {
        "matcher": "Bash",
        "hooks": [
          {
            "type": "command",
            "command": ".claude/hooks/pre-commit-check.sh"
          }
        ]
      }
    ],
    "PostToolUse": [
      {
        "matcher": "Write|Edit|MultiEdit",
        "hooks": [
          {
            "type": "command",
            "command": "jq -r '.tool_input.file_path // empty' | xargs -r npx prettier --write"
          }
        ]
      }
    ]
  }
}
Blocking Pre-Commit Gate (.claude/hooks/pre-commit-check.sh)
bash
#!/usr/bin/env bash
set -euo pipefail
PAYLOAD="$(cat)"
CMD="$(printf '%s' "$PAYLOAD" | jq -r '.tool_input.command // empty')"

if [[ "$CMD" =~ git[[:space:]]+commit ]]; then
  if ! npm run lint --silent || ! npm test --silent; then
    echo "Pre-commit check failed: fix lint/test errors before committing." >&2
    exit 2
  fi
fi
exit 0
Blocking Secret & Protected-File Guard (.claude/hooks/file-and-secret-guard.sh)
bash
#!/usr/bin/env bash
set -euo pipefail
PAYLOAD="$(cat)"
FILE_PATH="$(printf '%s' "$PAYLOAD" | jq -r '.tool_input.file_path // empty')"
CONTENT="$(printf '%s' "$PAYLOAD" | jq -r '(.tool_input.content // .tool_input.new_string // empty)')"

if [[ "$FILE_PATH" =~ (^|/)(\.env|CANON_LOCKED\.md)$ ]]; then
  echo "Blocked write to protected file: $FILE_PATH" >&2
  exit 2
fi

if printf '%s' "$CONTENT" | grep -Eq '(sk-[A-Za-z0-9_-]{20,}|ghp_[A-Za-z0-9]{20,}|AKIA[0-9A-Z]{16})'; then
  echo "Blocked write: detected hardcoded secret token in $FILE_PATH" >&2
  exit 2
fi

exit 0

Recipe 2: Save Session State When a Session Ends (Stop / SessionEnd)

Use Stop (end of turn/task) and SessionEnd (when the session closes) in .claude/settings.json to persist session state and transcript metadata:

json
{
  "hooks": {
    "Stop": [
      {
        "matcher": "",
        "hooks": [
          {
            "type": "command",
            "command": ".claude/hooks/save-session-state.sh"
          }
        ]
      }
    ],
    "SessionEnd": [
      {
        "matcher": "",
        "hooks": [
          {
            "type": "command",
            "command": ".claude/hooks/save-session-state.sh"
          }
        ]
      }
    ]
  }
}

Example .claude/hooks/save-session-state.sh:

bash
#!/usr/bin/env bash
set -euo pipefail
mkdir -p .claude/state
PAYLOAD="$(cat)"
SESSION_ID="$(printf '%s' "$PAYLOAD" | jq -r '.session_id // "unknown"')"
printf '%s\n' "$PAYLOAD" > ".claude/state/session-${SESSION_ID}.json"
exit 0

Optional Integration: External CLI & Swarm Hook Runners

When running multi-agent swarms or external memory coordination alongside native .claude/settings.json hooks, you can wire optional CLI runners such as claude-flow inside the command field of a native hook:

bash
# Optional: pre-task and post-edit swarm memory hooks invoked from a command script
npx claude-flow hook pre-task --description "Implement authentication"
npx claude-flow hook post-edit --file "src/auth.js" --memory-key "auth/login"
npx claude-flow hook session-end --session-id "dev-session" --export-metrics

Reference

Detailed catalogs and extended patterns live in references/ and load on demand:

Verification Checklist

  1. Valid JSON: Verify .claude/settings.json parses cleanly with jq empty .claude/settings.json.
  2. Stdin Payload Test: Pipe a synthetic payload (echo '{"tool_name":"Bash","tool_input":{"command":"git commit -m test"}}' | .claude/hooks/pre-commit-check.sh) and verify exit code 0 vs 2.
  3. Fast Execution: Keep synchronous PreToolUse and PostToolUse hooks under 100ms or scope matcher tightly (Write|Edit|MultiEdit, Bash).
  4. Fail Closed with Exit Code 2: Always write the blocking reason to stderr (>&2) before exit 2 so Claude receives actionable feedback.

الملفات المرفقة

يقرأ النموذج هذه الملفات عند الحاجة ما دامت المهارة محمّلة. وهي متاحة للقراءة ولا تُنفّذ أبدًا.

الأسئلة الشائعة

ماذا تفعل مهارة الذكاء الاصطناعي Hooks Automation؟

Configure and automate Claude Code hooks in .claude/settings.json (PreToolUse, PostToolUse, UserPromptSubmit, Stop, SubagentStop, SessionEnd). Use when setting up Claude Code hooks to auto-format files after edits, run pre-commit or safety checks before Bash commands, guard secrets or protected files, save session state on Stop or SessionEnd, or wire optional external CLI and MCP hook runners.

لماذا تستخدم Hooks Automation على TypingMind؟

لأنك تثبّتها مرة واحدة وتستخدمها مع أي نموذج. مهارة Hooks Automation عبارة عن نص Markdown وليست شيفرة خاصة بمزود بعينه، لذا تعمل المهارة نفسها مع GPT-5 أو Claude أو Gemini أو Grok أو نموذج محلي، ويمكنك تبديل النموذج أثناء المحادثة دون تعطّل المهارة. يعمل TypingMind بمفاتيح API الخاصة بك، فتدفع للمزودين مباشرةً بدلًا من اشتراك لكل مقعد، وتبقى مهاراتك ومحادثاتك في مساحة التخزين الخاصة بك.

كيف أثبّت Hooks Automation في TypingMind؟

في TypingMind، افتح «الإضافات»، ثم «المهارات»، ثم اختر «التثبيت من GitHub» والصق https://github.com/frankxai/claude-skills-library/tree/main/free-skills/hooks-automation. يقرأ TypingMind ملف SKILL.md الخاص بالمهارة، ويجمع ملفاتها ويثبّتها كمهارة يمكنك تفعيلها لكل محادثة على حدة.

ما نماذج الذكاء الاصطناعي التي يمكنها استخدام Hooks Automation؟

أي نموذج تربطه في TypingMind. مهارات الذكاء الاصطناعي عبارة عن تعليمات Markdown وليست شيفرة خاصة بمزود بعينه، لذا يمكن لكل من GPT وClaude وGemini وGrok والنماذج المحلية تحميل هذه المهارة عندما يتوافق الطلب معها.

كم نموذج ذكاء اصطناعي يمكنني استخدامه مع Hooks Automation؟

أي عدد تريده. ما دام النموذج يدعم المهارات، يمكنك استخدام Hooks Automation معه، سواء كان GPT أو Claude أو Gemini أو Grok أو DeepSeek أو Mistral أو Llama أو غيرها، وكل ذلك على TypingMind باستخدام مفاتيح API الخاصة بك.

هل مهارة الذكاء الاصطناعي Hooks Automation مجانية؟

نعم. نشرها frankxai على GitHub بموجب ترخيص MIT. لا تدفع إلا لمزود الذكاء الاصطناعي الخاص بك مقابل التوكنات التي تستخدمها.

ما هي مهارات الذكاء الاصطناعي؟

مهارة الذكاء الاصطناعي حزمة تعليمات قابلة لإعادة الاستخدام تعلّم نموذج الذكاء الاصطناعي كيفية تنفيذ مهمة محددة. وتتبع تنسيق Agent Skills المفتوح: ملف SKILL.md يتضمن اسمًا ووصفًا، إلى جانب أي نصوص برمجية أو قوالب أو ملفات مرجعية قد يحتاج إليها النموذج. لا يقرأ النموذج التعليمات إلا عندما يتوافق طلبك مع المهارة، لذا لا تترتب على المهارة المثبتة أي تكلفة حتى تُستخدم.

كيف تختلف مهارات الذكاء الاصطناعي عن الإضافات أو موصلات MCP؟

تمنح الإضافة أو موصل MCP النموذج أدوات جديدة يمكنه استدعاؤها، وهي شيفرة تُنفَّذ في مكان ما وتُرجع نتيجة. أما مهارة الذكاء الاصطناعي فتزوّد النموذج بالمعرفة ومنهجية العمل: كيفية التعامل مع مهمة، والخطوات التي ينبغي اتباعها، وما ينبغي أن تكون عليه المخرجات الجيدة. المهارات عبارة عن نصوص Markdown، لذا لا تحتاج إلى خادم أو مفتاح API أو بيئة تشغيل، وتعمل مع أي نموذج.

عرض الكل
شعار openclaw

Clawsweeper

openclaw
مؤسسةشائع

استخدم هذا لكل أعمال ClawSweeper: تقارير فحص مشكلات/طلبات سحب OpenClaw، ومهام الإصلاح، وطلبات السحب لإصلاحات السحابة، وأوامر منشن المشرفين @clawsweeper، والإصلاح التلقائي/الدمج التلقائي الموثوق الذي راجعه ClawSweeper، ومراقبة GitHub Actions…

82.2K
391K
الملفات: 1
عرض
شعار openclaw

Control Ui E2e

openclaw
مؤسسةشائع

استخدم هذا عند تصميم واجهة OpenClaw Control UI الرسومية أو اختبارها أو إصلاحها أو توسيعها، بما في ذلك معارض اختبار الإجهاد للواجهة مع مدخلات الملاحظات، وفحوص Vitest + Playwright الشاملة، وتدفقات Gateway المحاكية…

82.2K
391K
الملفات: 1
عرض
شعار openclaw

Deslop

openclaw
مؤسسةشائع

تنظيف مقتصر على تغييرات الفرع من الحشو البرمجي المولّد بالذكاء الاصطناعي: أزِل حشو التعليقات، وفحوص التحوط الزائدة، وتمويه الأنواع، وانحراف الأسلوب من تغييرات الفرع الحالية قبل المراجعة التلقائية.

82.2K
391K
التعليمات
عرض
شعار openclaw

Discord Clawd

openclaw
مؤسسةشائع

استخدم هذا للتواصل مع وكيل/جلسة OpenClaw المتصل بـ Discord؛ وليس للبحث في الأرشيف.

82.2K
391K
الملفات: 1
عرض

أنشئ مساحة عملك للذكاء الاصطناعي الآن

اشترك في نشرتنا الإخبارية لتصلك أخبار الميزات الجديدة والهدايا القادمة 👇