feat(claude): sync Claude Code session title to HAPI web UI#394
Open
koenzhao wants to merge 1 commit intotiann:mainfrom
Open
feat(claude): sync Claude Code session title to HAPI web UI#394koenzhao wants to merge 1 commit intotiann:mainfrom
koenzhao wants to merge 1 commit intotiann:mainfrom
Conversation
Intercept `custom-title` events from Claude Code's JSONL session files and update HAPI session metadata.name, so /rename in Claude Code automatically reflects in the HAPI web UI. - Add onTitleChange callback to session scanner - Detect custom-title events in readSessionLog before schema validation - Apply latest title on session startup from JSONL history - Emit title changes during live scanning (within 3s poll interval)
There was a problem hiding this comment.
Findings
- [Major] Pending-session title events can overwrite the active session title.
findSessionFiles()still scanspendingSessionsduring Claude session rollover, andparseSessionFile()now forwards everycustom-titleit sees. A late rename written to the previous JSONL file can therefore replacemetadata.namefor the new active Claude session. Evidencecli/src/claude/utils/sessionScanner.ts:104,cli/src/claude/utils/sessionScanner.ts:123.
Summary
Review mode: initial
1 finding. Static review only. Residual risk: the new title-sync path has no regression coverage for startup hydration or session rollover in cli/src/claude/utils/sessionScanner.test.ts:41.
Testing
Not run (automation; bun is not installed in this runner).
HAPI Bot
| } | ||
| const { events, totalLines } = await readSessionLog(filePath, cursor); | ||
| const { events, titleChanges, totalLines } = await readSessionLog(filePath, cursor); | ||
| for (const title of titleChanges) { |
There was a problem hiding this comment.
[MAJOR] This applies custom-title updates from every scanned file, not just the current Claude session. During /clear or resume, findSessionFiles() still includes pendingSessions, so a late rename in the previous JSONL file can overwrite metadata.name for the new active session.
Suggested fix:
const { events, titleChanges, totalLines } = await readSessionLog(filePath, cursor)
if (sessionId === this.currentSessionId) {
for (const title of titleChanges) {
logger.debug(`[SESSION_SCANNER] Title change: ${title}`)
this.onTitleChange?.(title)
}
}
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
custom-titleevents from Claude Code's JSONL session files and update HAPI sessionmetadata.name/renamein Claude Code, the title automatically syncs to the HAPI web UI within ~3 secondsMotivation
Currently, HAPI relies on its own
mcp__hapi__change_titleMCP tool (via system prompt injection) to set session titles. This means Claude Code's native/renamecommand has no effect on the HAPI web UI — they are two separate naming systems.This PR makes Claude Code the single source of truth for session titles by reading
custom-titleevents directly from the JSONL files.Changes
cli/src/claude/utils/sessionScanner.ts— AddedonTitleChangecallback;readSessionLognow detectscustom-titleevents before Zod schema validation and returns them separatelycli/src/claude/claudeLocalLauncher.ts— WiresonTitleChangetosession.client.updateMetadatato setmetadata.nameTest plan
hapi claude, verify session appears in web UI/rename my-sessionin Claude Code, verify title updates in web UI within ~3s