模极社社区 - 制造业全产业链交流平台

    • 登录
    • 版块
    • 最新
    • 话题
    • 热门
    • 用户
    • 群组

    Hook Setup Guide——模具行业从业者必备知识手册

    社区公告
    1
    1
    0
    正在加载更多帖子
    • 从旧到新
    • 从新到旧
    • 最多赞同
    回复
    • 在新帖中回复
    登录后回复
    此主题已被删除。只有拥有主题管理权限的用户可以查看。
    • S
      system 2 最后由 编辑

      <h2>Hook Setup Guide</h2>

      <p>Configure automatic self-improvement triggers for AI coding agents.</p>

      <h3>Overview</h3>

      <p>Hooks enable proactive learning capture by injecting reminders at key moments:</p>
      <ul>
      <li><strong>UserPromptSubmit</strong>: Reminder after each prompt to evaluate learnings</li>
      <li><strong>PostToolUse (Bash)</strong>: Error detection when commands fail</li>
      </ul>

      <h3>Claude Code Setup</h3>

      <h4>Option 1: Project-Level Configuration</h4>

      <p>Create <code>.claude/settings.json</code> in your project root:</p>

      <pre><code>
      {
      "hooks": {
      "UserPromptSubmit": [
      {
      "matcher": "",
      "hooks": [
      {
      "type": "command",
      "command": "./skills/self-improvement/scripts/activator.sh"
      }
      ]
      }
      ],
      "PostToolUse": [
      {
      "matcher": "Bash",
      "hooks": [
      {
      "type": "command",
      "command": "./skills/self-improvement/scripts/error-detector.sh"
      }
      ]
      }
      ]
      }
      }
      </code></pre>

      <h4>Option 2: User-Level Configuration</h4>

      <p>Add to <code>~/.claude/settings.json</code> for global activation:</p>

      <pre><code>
      {
      "hooks": {
      "UserPromptSubmit": [
      {
      "matcher": "",
      "hooks": [
      {
      "type": "command",
      "command": "~/.claude/skills/self-improvement/scripts/activator.sh"
      }
      ]
      }
      ]
      }
      }
      </code></pre>

      <h4>Minimal Setup (Activator Only)</h4>

      <p>For lower overhead, use only the UserPromptSubmit hook:</p>

      <pre><code>
      {
      "hooks": {
      "UserPromptSubmit": [
      {
      "matcher": "",
      "hooks": [
      {
      "type": "command",
      "command": "./skills/self-improvement/scripts/activator.sh"
      }
      ]
      }
      ]
      }
      }
      </code></pre>

      <h3>Codex CLI Setup</h3>

      <p>Codex uses the same hook system as Claude Code. Create <code>.codex/settings.json</code>:</p>

      <pre><code>
      {
      "hooks": {
      "UserPromptSubmit": [
      {
      "matcher": "",
      "hooks": [
      {
      "type": "command",
      "command": "./skills/self-improvement/scripts/activator.sh"
      }
      ]
      }
      ]
      }
      }
      </code></pre>

      <h3>GitHub Copilot Setup</h3>

      <p>Copilot doesn't support hooks directly. Instead, add guidance to <code>.github/copilot-instructions.md</code>:</p>

      <pre><code>

      Self-Improvement

      After completing tasks that involved:

      • Debugging non-obvious issues
      • Discovering workarounds
      • Learning project-specific patterns
      • Resolving unexpected errors

      Consider logging the learning to .learnings/ using the format from the self-improvement skill.

      For high-value learnings that would benefit other sessions, consider skill extraction.
      </code></pre>

      <h3>Verification</h3>

      <h4>Test Activator Hook</h4>

      <ol>
      <li>Enable the hook configuration</li>
      <li>Start a new Claude Code session</li>
      <li>Send any prompt</li>
      <li>Verify you see <code><self-improvement-reminder></code> in the context</li>
      </ol>

      <h4>Test Error Detector Hook</h4>

      <ol>
      <li>Enable PostToolUse hook for Bash</li>
      <li>Run a command that fails: <code>ls /nonexistent/path</code></li>
      <li>Verify you see <code><error-detected></code> reminder</li>
      </ol>

      <h4>Dry Run Extract Script</h4>

      <pre><code>
      ./skills/self-improvement/scripts/extract-skill.sh test-skill --dry-run
      </code></pre>

      <p>Expected output shows the skill scaffold that would be created.</p>

      <h3>Troubleshooting</h3>

      <h4>Hook Not Triggering</h4>

      <ol>
      <li><strong>Check script permissions</strong>: <code>chmod +x scripts/*.sh</code></li>
      <li><strong>Verify path</strong>: Use absolute paths or paths relative to project root</li>
      <li><strong>Check settings location</strong>: Project vs user-level settings</li>
      <li><strong>Restart session</strong>: Hooks are loaded at session start</li>
      </ol>

      <h4>Permission Denied</h4>

      <pre><code>
      chmod +x ./skills/self-improvement/scripts/activator.sh
      chmod +x ./skills/self-improvement/scripts/error-detector.s


      还有什么补充参数吗?一起完善。
      </code></pre>

      1 条回复 最后回复 回复 引用 0
      • First post
        Last post
      Powered by NodeBB | Contributors