{
  "$schema": "https://json.schemastore.org/claude-code-settings.json",
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "*",
        "hooks": [
          {
            "type": "command",
            "command": "cortex-agent hook claude PostToolUse >/dev/null",
            "timeout": 5
          }
        ],
        "description": "从受治理 Claude 工具完成事件写入受限 Cortex progress/testing 信号；原始工具输入和输出立即丢弃"
      },
      {
        "matcher": "Write|Edit|MultiEdit",
        "hooks": [
          {
            "type": "command",
            "command": ".claude/hooks/pre-commit-check.sh",
            "async": true,
            "timeout": 15
          }
        ],
        "description": "Layer 1（确定性）：文件编辑后自动执行质量检查（Lint / 密钥扫描），失败时阻断"
      }
    ],
    "SessionStart": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "cortex-agent hook claude SessionStart >/dev/null",
            "timeout": 5
          }
        ],
        "description": "受治理 Claude 会话启动时校验私有 Cortex 上下文；任务 accepted 仍只由 launcher 写入"
      },
      {
        "matcher": "*",
        "hooks": [
          {
            "type": "command",
            "command": "node -e \"const f='.agent/plans/task-progress.md'; const fs=require('fs'); if(fs.existsSync(f)){console.log('[Cortex] Task progress loaded: '+f);}\""
          }
        ],
        "description": "会话启动时提示加载任务进度文件"
      },
      {
        "matcher": "*",
        "hooks": [
          {
            "type": "command",
            "command": "node -e \"const fs=require('fs');const p='.agent/memory/MEMORY.md';if(fs.existsSync(p)){const c=fs.readFileSync(p,'utf8');const lines=c.split('\\n').slice(0,200);const cap=Buffer.byteLength(c,'utf8')>25*1024;if(cap)lines.push('... [truncated, 25KB cap reached]');console.log('[Cortex] Memory index loaded:\\n'+lines.join('\\n'));}\"",
            "async": true,
            "timeout": 5
          }
        ],
        "description": "会话启动时加载 .agent/memory/MEMORY.md 索引（≤200 行 / 25KB cap，topic 文件按需 Read）"
      },
      {
        "matcher": "*",
        "hooks": [
          {
            "type": "command",
            "command": "PROJ=$(node -e \"console.log(require('path').basename(process.cwd()))\"); CORTEX_SESSION_START=1 node .agent/skills/runtime-continuity/scripts/index.js warm --auto --project \"$PROJ\" 2>/dev/null; exit 0",
            "async": true,
            "timeout": 5
          }
        ],
        "description": "会话启动时启动或续期唯一的 runtime-continuity 守护进程：补齐陈旧归档、每 2 小时自动归档并在 5 小时窗口结束后退出"
      },
      {
        "matcher": "*",
        "hooks": [
          {
            "type": "command",
            "command": "cortex-agent dashboard ensure --project \"$PWD\" --reason session-start >/dev/null 2>&1; exit 0",
            "async": true,
            "timeout": 5
          }
        ],
        "description": "仅当项目显式启用 Dashboard 自动化时，确保唯一 Supervisor 已运行；默认关闭时零写入、零进程"
      },
      {
        "matcher": "*",
        "hooks": [
          {
            "type": "command",
            "command": "cortex-agent bridge sync --auto >/dev/null 2>&1; exit 0",
            "async": true,
            "timeout": 10
          }
        ],
        "description": "P-006 §3.5：自动从 topology 注册表中为每个订阅的 peer 项目解析 host_root 并把 outbox 拉入本地 inbox；无订阅的项目零读取；源不可达的 peer 仅报告、不阻断会话"
      },
      {
        "matcher": "*",
        "hooks": [
          {
            "type": "command",
            "command": "cortex-agent memory validate --quiet 2>&1",
            "timeout": 10
          }
        ],
        "description": "Session start: silently validate .agent/memory/MEMORY.md integrity (drift/missing/schema/orphan/duplicate/over-cap); one-line summary printed to session context if issues exist"
      }
    ],
    "PermissionRequest": [
      {
        "matcher": "*",
        "hooks": [
          {
            "type": "command",
            "command": "cortex-agent hook claude Permission >/dev/null",
            "timeout": 5
          }
        ],
        "description": "仅上报受治理 Claude 的权限请求；不批准、拒绝或修改权限"
      }
    ],
    "Notification": [
      {
        "matcher": "permission_prompt|agent_needs_input",
        "hooks": [
          {
            "type": "command",
            "command": "cortex-agent hook claude Notification >/dev/null",
            "timeout": 5
          }
        ],
        "description": "将 Claude 的等待输入通知转换为 Cortex task.input_required；不转发通知正文"
      }
    ],
    "Stop": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "cortex-agent hook claude Stop >/dev/null",
            "timeout": 5
          }
        ],
        "description": "记录非终态 Stop；绝不据此推断 completed 或 ready_for_review"
      }
    ]
  }
}
