Skip to content

feat(hooks): include assistant response text in Stop hook payload#969

Open
itxaiohanglover wants to merge 2 commits into
MoonshotAI:mainfrom
itxaiohanglover:feat/stop-hook-response-text
Open

feat(hooks): include assistant response text in Stop hook payload#969
itxaiohanglover wants to merge 2 commits into
MoonshotAI:mainfrom
itxaiohanglover:feat/stop-hook-response-text

Conversation

@itxaiohanglover

Copy link
Copy Markdown

Fixes #952

Problem

The Stop hook payload only contains stop_hook_active and basic fields (session_id, cwd). Users building persistent session memory or conversation logging on top of Kimi Code hooks have no way to access the assistant response text.

What changed

Added an optional responseText field to the Stop hook payload. It extracts the last assistant message text from the conversation history before the Stop hook fires.

  • responseText is null when the assistant response is empty
  • Fully backward compatible — existing hooks that do not read this field are unaffected
  • No changes to hook execution flow or timing

Validation

  • The extraction happens right before triggerBlock(Stop, ...) is called
  • Only text content parts are joined — tool calls and images are excluded
  • null is passed when there is no assistant message (edge case)

The Stop hook payload only contained stop_hook_active. Users building
memory/logging layers need the assistant response text to persist
conversation context. Add an optional responseText field that
extracts the last assistant message text.

Fixes MoonshotAI#952
@changeset-bot

changeset-bot Bot commented Jun 22, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 1c206ab

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f06d6d642e

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

inputData: { stopHookActive: stopHookContinuationUsed },
inputData: {
stopHookActive: stopHookContinuationUsed,
responseText: responseText || null,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Add a changeset for this hook payload change

This line adds a user-visible Stop hook payload field, but the commit contains no .changeset entry. The repo-level AGENTS.md says, “After finishing a task and before submitting a PR, you must run the gen-changesets skill,” and without that release tooling will not version or changelog the new hook behavior for users.

Useful? React with 👍 / 👎.

@itxaiohanglover

Copy link
Copy Markdown
Author

Thanks for the review — changeset added.

@itxaiohanglover

Copy link
Copy Markdown
Author

Changeset was added in a follow-up commit (1c206ab). The latest commit includes .changeset/stop-hook-response-text.md.

@GlobalInvestor152

Copy link
Copy Markdown

Thanks for opening this - it's exactly the missing piece for conversation logging.

We use the Stop hook to persist each turn to a local SQLite database for cross-session recall. Right now we can log the user's prompt via UserPromptSubmit, but the assistant's response isn't available in the Stop payload, so the transcript is one-sided. With responseText added, we'll finally have a complete back-and-forth history.

Happy to test this against our logger once it's in a release and report back.

@itxaiohanglover

Copy link
Copy Markdown
Author

Thanks @GlobalInvestor152! That is exactly the use case this PR was designed for — the Stop hook had session_id and cwd but no response text, making conversation logging one-sided.

Your SQLite cross-session recall setup sounds great. Once this merges and hits a release, I would love to hear how it works with your logger. If you run into any issues with the responseText field (e.g. empty for tool-only turns, or truncation on very long responses), please let me know.

@GlobalInvestor152

Copy link
Copy Markdown

@itxaiohanglover , great. When can we expect the pull request to merge and go live?

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.

Feature Request: Include assistant response text in Stop hook payload (or add a post-response hook event)

2 participants