hooks-session-end-issue-hook

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

/hooks:session-end-issue-hook

/hooks:session-end-issue-hook

Configure a
Stop
hook that checks for unfinished
TodoWrite
todos at the end of each Claude response. If any pending or in-progress todos exist when you try to end the session, Claude is prompted to create GitHub issues for them before the conversation closes.
配置一个
Stop
钩子,在每次Claude响应结束时检查未完成的
TodoWrite
待办事项。当你尝试结束会话时,如果存在任何待处理或进行中的待办事项,Claude会在对话关闭前被提示为它们创建GitHub Issue。

When to Use This Skill

何时使用该技能

Use this skill when...Use
/hooks:hooks-configuration
instead when...
You want unfinished todos deferred to GitHub issuesConfiguring other hook types (PreToolUse, SessionEnd, etc.)
Preventing tasks from being forgotten at session endNeed general hooks knowledge or debugging
Projects with active issue trackers on GitHubUnderstanding hook lifecycle events
Teams that rely on GitHub issues for work trackingWriting custom hook logic from scratch
适合使用该技能的场景适合使用
/hooks:hooks-configuration
的场景
你希望将未完成的待办事项延期至GitHub Issue配置其他类型的钩子(PreToolUse、SessionEnd等)
避免在会话结束时遗忘任务需要了解钩子的通用知识或进行调试
项目在GitHub上使用活跃的问题追踪器理解钩子的生命周期事件
团队依赖GitHub Issue进行工作追踪从零开始编写自定义钩子逻辑

Context

上下文

Detect current state:
  • Settings file: !
    find .claude -maxdepth 1 -name 'settings.json'
  • Existing Stop hooks: !
    jq -r '.hooks.Stop // empty' .claude/settings.json
  • gh auth: !
    gh auth status
  • jq available: !
    jq --version
检测当前状态:
  • 设置文件:!
    find .claude -maxdepth 1 -name 'settings.json'
  • 已存在的Stop钩子:!
    jq -r '.hooks.Stop // empty' .claude/settings.json
  • gh认证状态:!
    gh auth status
  • jq可用性:!
    jq --version

Parameters

参数

FlagDefaultDescription
--no-verify
offSkip checking
gh
authentication status
标志默认值描述
--no-verify
关闭跳过检查
gh
的认证状态

Execution

执行步骤

Step 1: Check prerequisites

步骤1:检查前置条件

Verify that
jq
is installed — the hook requires it to parse the session transcript. Report if missing.
Unless
--no-verify
is passed: verify
gh
is installed and authenticated (
gh auth status
). Report the auth state so the user knows whether GitHub issue creation will work when the hook fires.
验证
jq
是否已安装——该钩子需要它来解析会话记录。如果缺失则进行报告。
除非传递了
--no-verify
参数,否则需验证
gh
是否已安装并完成认证(执行
gh auth status
)。报告认证状态,让用户了解钩子触发时GitHub Issue创建功能是否可用。

Step 2: Locate hook script

步骤2:定位钩子脚本

The hook script ships with the hooks-plugin. Determine its path:
  • If
    ${CLAUDE_PLUGIN_ROOT}
    is set: use
    ${CLAUDE_PLUGIN_ROOT}/hooks/session-end-issue-hook.sh
  • Otherwise: look for the script relative to this skill's location (
    ../../hooks/session-end-issue-hook.sh
    )
  • Last resort: ask the user for the absolute path to the installed hooks-plugin
Report the resolved path to the user.
该钩子脚本随hooks-plugin一起发布。确定其路径:
  • 如果已设置
    ${CLAUDE_PLUGIN_ROOT}
    :使用
    ${CLAUDE_PLUGIN_ROOT}/hooks/session-end-issue-hook.sh
  • 否则:相对于该技能的位置查找脚本(
    ../../hooks/session-end-issue-hook.sh
  • 最后手段:询问用户已安装的hooks-plugin的绝对路径
向用户报告解析后的路径。

Step 3: Configure
.claude/settings.json

步骤3:配置
.claude/settings.json

Read existing
.claude/settings.json
if it exists. Merge the Stop hook — preserve all existing configuration.
If a
Stop
hook pointing to
session-end-issue-hook.sh
already exists, report that the hook is already configured and skip to Step 4.
If other Stop hooks exist, add alongside them (both will run).
Configuration to merge under the
hooks
key:
json
{
  "Stop": [
    {
      "matcher": "*",
      "hooks": [
        {
          "type": "command",
          "command": "bash \"${CLAUDE_PLUGIN_ROOT}/hooks/session-end-issue-hook.sh\"",
          "timeout": 15
        }
      ]
    }
  ]
}
Use
timeout: 15
(15 seconds) — transcript parsing is fast. Create
.claude/
directory if it does not exist.
如果存在现有
.claude/settings.json
文件则读取。合并Stop钩子——保留所有现有配置。
如果已存在指向
session-end-issue-hook.sh
的Stop钩子,则报告该钩子已配置完成并跳至步骤4。
如果存在其他Stop钩子,则将其添加进去(两者都会运行)。
需要在
hooks
键下合并的配置:
json
{
  "Stop": [
    {
      "matcher": "*",
      "hooks": [
        {
          "type": "command",
          "command": "bash \"${CLAUDE_PLUGIN_ROOT}/hooks/session-end-issue-hook.sh\"",
          "timeout": 15
        }
      ]
    }
  ]
}
设置
timeout: 15
(15秒)——会话记录解析速度很快。如果
.claude/
目录不存在则创建它。

Step 4: Finalize

步骤4:完成配置

Report a summary of what was configured, including:
  • Path to the hook script
  • Location of
    .claude/settings.json
  • Whether
    gh
    auth is ready
报告已配置内容的摘要,包括:
  • 钩子脚本的路径
  • .claude/settings.json
    的位置
  • gh
    认证是否就绪

Post-Actions

后续操作

After configuring the hook:
  1. Suggest committing
    .claude/settings.json
    to share the hook with the team
  2. Remind the user that the hook fires at the end of every Claude response — it is silent when all todos are completed and only blocks when pending todos exist
  3. If
    gh
    is not authenticated, remind the user to run
    gh auth login
    so GitHub issue creation works when the hook fires
配置钩子后:
  1. 建议提交
    .claude/settings.json
    以与团队共享该钩子
  2. 提醒用户该钩子会在每次Claude响应结束时触发——当所有待办事项完成时会静默运行,仅当存在待处理待办事项时才会中断会话
  3. 如果
    gh
    未完成认证,提醒用户运行
    gh auth login
    ,以便钩子触发时GitHub Issue创建功能正常工作

How the Hook Works

钩子工作原理

When the hook fires at the end of a Claude response:
  1. It reads the session transcript from
    transcript_path
  2. Finds the last
    TodoWrite
    call
    — the final state of the todo list
  3. Extracts any todos with
    status: "pending"
    or
    status: "in_progress"
  4. If none exist → silently exits (no interruption)
  5. If any exist → outputs a block decision with the list of pending todos and suggested
    gh issue create
    commands
Claude then has the opportunity to create the issues or ask the user what to do with the deferred work.
当钩子在Claude响应结束时触发:
  1. transcript_path
    读取会话记录
  2. 找到最后一次
    TodoWrite
    调用
    ——待办事项列表的最终状态
  3. 提取所有
    status: "pending"
    status: "in_progress"
    的待办事项
  4. 如果没有此类待办事项→静默退出(不中断会话)
  5. 如果存在此类待办事项→输出一个包含待处理待办事项列表和建议的
    gh issue create
    命令的区块决策
随后Claude会有机会创建Issue,或询问用户如何处理这些延期工作。

Agentic Optimizations

智能优化方案

ContextApproach
Quick setup, skip auth check
/hooks:session-end-issue-hook --no-verify
Full setup with auth verification
/hooks:session-end-issue-hook
Test the hook manually
echo '{"transcript_path":"/path/to/transcript","cwd":"."}' | bash hooks/session-end-issue-hook.sh
场景方案
快速设置,跳过认证检查
/hooks:session-end-issue-hook --no-verify
完整设置并验证认证
/hooks:session-end-issue-hook
手动测试钩子
echo '{"transcript_path":"/path/to/transcript","cwd":"."}' | bash hooks/session-end-issue-hook.sh

Quick Reference

快速参考

ItemValue
Hook event
Stop
(fires after each Claude response)
Settings location
.claude/settings.json
Timeout15 seconds
Trigger conditionPending or in-progress todos in last TodoWrite call
Silent whenAll todos completed or no TodoWrite calls in transcript
Issue label
claude-deferred
(suggested in output, not auto-applied)
钩子事件
Stop
(在每次Claude响应后触发)
设置位置
.claude/settings.json
超时时间15秒
触发条件最后一次TodoWrite调用中存在待处理或进行中的待办事项
静默触发场景所有待办事项已完成,或会话记录中无TodoWrite调用
Issue标签
claude-deferred
(在输出中建议,不会自动添加)