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 hook that checks for unfinished 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.
StopTodoWrite配置一个钩子,在每次Claude响应结束时检查未完成的待办事项。当你尝试结束会话时,如果存在任何待处理或进行中的待办事项,Claude会在对话关闭前被提示为它们创建GitHub Issue。
StopTodoWriteWhen to Use This Skill
何时使用该技能
| Use this skill when... | Use |
|---|---|
| You want unfinished todos deferred to GitHub issues | Configuring other hook types (PreToolUse, SessionEnd, etc.) |
| Preventing tasks from being forgotten at session end | Need general hooks knowledge or debugging |
| Projects with active issue trackers on GitHub | Understanding hook lifecycle events |
| Teams that rely on GitHub issues for work tracking | Writing custom hook logic from scratch |
| 适合使用该技能的场景 | 适合使用 |
|---|---|
| 你希望将未完成的待办事项延期至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
参数
| Flag | Default | Description |
|---|---|---|
| off | Skip checking |
| 标志 | 默认值 | 描述 |
|---|---|---|
| 关闭 | 跳过检查 |
Execution
执行步骤
Step 1: Check prerequisites
步骤1:检查前置条件
Verify that is installed — the hook requires it to parse the session transcript. Report if missing.
jqUnless is passed: verify is installed and authenticated (). Report the auth state so the user knows whether GitHub issue creation will work when the hook fires.
--no-verifyghgh auth status验证是否已安装——该钩子需要它来解析会话记录。如果缺失则进行报告。
jq除非传递了参数,否则需验证是否已安装并完成认证(执行)。报告认证状态,让用户了解钩子触发时GitHub Issue创建功能是否可用。
--no-verifyghgh auth statusStep 2: Locate hook script
步骤2:定位钩子脚本
The hook script ships with the hooks-plugin. Determine its path:
- If is set: use
${CLAUDE_PLUGIN_ROOT}${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
.claude/settings.json步骤3:配置.claude/settings.json
.claude/settings.jsonRead existing if it exists. Merge the Stop hook — preserve all existing configuration.
.claude/settings.jsonIf a hook pointing to already exists, report that the hook is already configured and skip to Step 4.
Stopsession-end-issue-hook.shIf other Stop hooks exist, add alongside them (both will run).
Configuration to merge under the key:
hooksjson
{
"Stop": [
{
"matcher": "*",
"hooks": [
{
"type": "command",
"command": "bash \"${CLAUDE_PLUGIN_ROOT}/hooks/session-end-issue-hook.sh\"",
"timeout": 15
}
]
}
]
}Use (15 seconds) — transcript parsing is fast. Create directory if it does not exist.
timeout: 15.claude/如果存在现有文件则读取。合并Stop钩子——保留所有现有配置。
.claude/settings.json如果已存在指向的Stop钩子,则报告该钩子已配置完成并跳至步骤4。
session-end-issue-hook.sh如果存在其他Stop钩子,则将其添加进去(两者都会运行)。
需要在键下合并的配置:
hooksjson
{
"Stop": [
{
"matcher": "*",
"hooks": [
{
"type": "command",
"command": "bash \"${CLAUDE_PLUGIN_ROOT}/hooks/session-end-issue-hook.sh\"",
"timeout": 15
}
]
}
]
}设置(15秒)——会话记录解析速度很快。如果目录不存在则创建它。
timeout: 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 auth is ready
gh
报告已配置内容的摘要,包括:
- 钩子脚本的路径
- 的位置
.claude/settings.json - 认证是否就绪
gh
Post-Actions
后续操作
After configuring the hook:
- Suggest committing to share the hook with the team
.claude/settings.json - 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
- If is not authenticated, remind the user to run
ghso GitHub issue creation works when the hook firesgh auth login
配置钩子后:
- 建议提交以与团队共享该钩子
.claude/settings.json - 提醒用户该钩子会在每次Claude响应结束时触发——当所有待办事项完成时会静默运行,仅当存在待处理待办事项时才会中断会话
- 如果未完成认证,提醒用户运行
gh,以便钩子触发时GitHub Issue创建功能正常工作gh auth login
How the Hook Works
钩子工作原理
When the hook fires at the end of a Claude response:
- It reads the session transcript from
transcript_path - Finds the last call — the final state of the todo list
TodoWrite - Extracts any todos with or
status: "pending"status: "in_progress" - If none exist → silently exits (no interruption)
- If any exist → outputs a block decision with the list of pending todos and suggested commands
gh issue create
Claude then has the opportunity to create the issues or ask the user what to do with the deferred work.
当钩子在Claude响应结束时触发:
- 从读取会话记录
transcript_path - 找到最后一次调用——待办事项列表的最终状态
TodoWrite - 提取所有或
status: "pending"的待办事项status: "in_progress" - 如果没有此类待办事项→静默退出(不中断会话)
- 如果存在此类待办事项→输出一个包含待处理待办事项列表和建议的命令的区块决策
gh issue create
随后Claude会有机会创建Issue,或询问用户如何处理这些延期工作。
Agentic Optimizations
智能优化方案
| Context | Approach |
|---|---|
| Quick setup, skip auth check | |
| Full setup with auth verification | |
| Test the hook manually | |
| 场景 | 方案 |
|---|---|
| 快速设置,跳过认证检查 | |
| 完整设置并验证认证 | |
| 手动测试钩子 | |
Quick Reference
快速参考
| Item | Value |
|---|---|
| Hook event | |
| Settings location | |
| Timeout | 15 seconds |
| Trigger condition | Pending or in-progress todos in last TodoWrite call |
| Silent when | All todos completed or no TodoWrite calls in transcript |
| Issue label | |
| 项 | 值 |
|---|---|
| 钩子事件 | |
| 设置位置 | |
| 超时时间 | 15秒 |
| 触发条件 | 最后一次TodoWrite调用中存在待处理或进行中的待办事项 |
| 静默触发场景 | 所有待办事项已完成,或会话记录中无TodoWrite调用 |
| Issue标签 | |