fix: call sessions end endpoint from session-stop hook#47
Merged
Alan-TheGentleman merged 1 commit intoGentleman-Programming:mainfrom Mar 8, 2026
Merged
Conversation
2 tasks
Collaborator
There was a problem hiding this comment.
Fix looks good — clean, mirrors session-start.sh, does exactly what it should.
One thing worth noting: if the server happens to be down when the session ends, this fails silently (which is fine for a hook). But the agent also can't call mem_session_end as a fallback because that tool isn't in the ToolSearch select list from #43. Not a blocker for this PR — just something to address in #43.
Also flagging that this only covers Claude Code. OpenCode, Gemini, and Codex don't have session-end hooks so their sessions still get ended_at = NULL. We should open a follow-up for that — the MCP tool exists, agents just need to be told to call it.
Approve from my side, good to merge.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
session-stop.shto callPOST /sessions/{id}/endwhen Claude Code stops, soended_atis always set regardless of agent cooperationMotivation
Closes #46
session-stop.shwas a placeholder that did nothing. The server already exposedPOST /sessions/{id}/end, and the Stop hook already receivedsession_idvia stdin, but the connection was never made. As a result, every session in the database hasended_at = NULLand sessions grow unbounded with no duration data.The fix mirrors the pattern already used in
session-start.sh: readsession_idfrom stdin, call the HTTP API.Changes
plugin/claude-code/scripts/session-stop.sh— replaced placeholder with a curl call toPOST /sessions/{id}/end. Readssession_idfrom stdin (same assession-start.sh), exits cleanly if no session_id is present. Runs async (already configured inhooks.json) so it never blocks Claude's response.Test plan
go test ./...passesPOST /sessionsended_at = NULLin the databaseecho '{"session_id":"test","cwd":"/tmp"}' | bash session-stop.shended_atwas set correctly in the database