Skip to content

本 PR 为 /stop 命令添加快速中断功能,解决 Claude Code 在思考循环中卡死时的无法中断的问题。#407

Open
dragonLongZ wants to merge 8 commits intochenhg5:mainfrom
dragonLongZ:main
Open

本 PR 为 /stop 命令添加快速中断功能,解决 Claude Code 在思考循环中卡死时的无法中断的问题。#407
dragonLongZ wants to merge 8 commits intochenhg5:mainfrom
dragonLongZ:main

Conversation

@dragonLongZ
Copy link
Copy Markdown

No description provided.

dragonLongZ and others added 6 commits March 18, 2026 11:32
- 新增 ForceTerminator 接口定义于 core/interfaces.go
- claudeSession 实现 ForceKill() 方法,立即终止底层进程
- 修复 cmdStop 使用正确的 session key (interactiveKeyForSessionKey)
- /stop 命令优先调用 ForceKill() 快速终止,无需等待优雅关闭

适用场景:agent 陷入思考循环或无响应状态时的快速恢复。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@dragonLongZ dragonLongZ closed this Apr 1, 2026
@dragonLongZ dragonLongZ changed the title 增加对于claude code的/stop 本 PR 为 /stop 命令添加快速中断功能,解决 Claude Code 在思考循环中卡死时的中断问题。 Apr 1, 2026
@dragonLongZ dragonLongZ changed the title 本 PR 为 /stop 命令添加快速中断功能,解决 Claude Code 在思考循环中卡死时的中断问题。 本 PR 为 /stop 命令添加快速中断功能,解决 Claude Code 在思考循环中卡死时的无法中断的问题。 Apr 1, 2026
@dragonLongZ
Copy link
Copy Markdown
Author

概述

本 PR 为 /stop 命令添加快速中断功能,解决 Claude Code 在思考循环中卡死时的中断问题,并修复多工作区环境下的 /stop 命令查找失败问题。

变更内容

  1. core/interfaces.go 中添加 ForceTerminator 接口

    • 定义 ForceKill() 方法用于立即终止进程
    • 允许代理实现快速中断而不必等待优雅关闭
  2. agent/claudecode/session.go 中实现 claudeSession.ForceKill()

    • 立即终止底层 Claude Code 进程
    • 跳过 8 秒优雅超时,专门用于卡死进程
  3. 修复 core/engine.go 中的 /stop 命令查找逻辑

    • 使用 interactiveKeyForSessionKey() 匹配创建状态时使用的相同 key
    • 修复多工作区功能启用时 /stop 命令失效的问题
    • 保证 /stop 命令在所有环境中都能正确终止会话

影响范围

所有平台(包括但不限于)

  • ✅ 钉钉、飞书、Telegram、Slack、Discord、QQ、LINE 等

所有环境

  • 多工作区环境:修复了 /stop 命令因 key 不匹配而失效的问题
  • 非多工作区环境:提升 /stop 命令为快速终止,无需等待 8 秒超时

AI 工具

  • Claude Code:新增 ForceKill() 功能,实现快速终止
  • 🔄 其他 AI 代理:如需快速终止功能,可实现 ForceTerminator 接口

问题解决

  • 多工作区环境下:修复了 /stop 命令无法终止 Claude Code 的问题
  • 思考循环卡死时:从等待 8 秒优雅关闭改为立即终止进程
  • 性能优化:提高 /stop 命令响应速度

向后兼容性

  • 完全向后兼容 - 现有的 Close() 方法保持不变
  • 其他代理将继续使用优雅关闭,除非它们实现了 ForceTerminator

测试

  • 验证编译通过:go build ./...
  • 变更仅影响 /stop 命令执行路径

@dragonLongZ dragonLongZ reopened this Apr 1, 2026
@chenhg5
Copy link
Copy Markdown
Owner

chenhg5 commented Apr 1, 2026

⚠️ Issue detected in this PR

The PR deletes CLAUDE.md (236 lines deleted) which is not related to the /stop force kill feature.

What's good:

  • ✅ ForceKill interface for immediate termination
  • ✅ ForceTerminator interface definition
  • ✅ cmdStop uses interactiveKey correctly

Problem:

  • ❌ CLAUDE.md deletion is unrelated to the feature

Recommendation: Please restore CLAUDE.md and only include the feature changes (agent/claudecode/session.go, core/engine.go, core/interfaces.go).

@chenhg5
Copy link
Copy Markdown
Owner

chenhg5 commented Apr 1, 2026

LGTM! The ForceKill implementation is clean and well-designed:

✅ Feature correctness: The ForceTerminator interface pattern allows optional implementation by agent sessions. claudeSession.ForceKill() properly cancels context, kills process, and waits for cleanup.

✅ Integration: Correctly integrated into stopInteractiveSession() for faster termination when agent is stuck.

✅ Code quality: Good documentation, proper error handling.

✅ CI: All checks pass.

Note: Most other changes are whitespace/formatting fixes in test files which are fine.

Ready for merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants