Claude chats: pass the chat title as --name so terminal resume lists them by name
Spawns pass the session title with --name (Claude Code records it as the transcript's custom-title). A rename tells the harness the new title for its next spawn, and the first routing of a session after a restart hands it the registry title.
This commit is contained in:
@@ -273,13 +273,22 @@ func (m *chatManager) brokerFor(ctx context.Context, sessionID string) (chatBrok
|
||||
if adapter == nil {
|
||||
return nil, errors.New("chat backend " + backend + " is not available")
|
||||
}
|
||||
if hinter, ok := adapter.(chatDirectoryHinter); ok && m.registry != nil {
|
||||
hinter, hintsDirectory := adapter.(chatDirectoryHinter)
|
||||
titler, takesTitle := adapter.(chatTitleSetter)
|
||||
if (hintsDirectory || takesTitle) && m.registry != nil {
|
||||
m.mu.Lock()
|
||||
done := m.hinted[sessionID]
|
||||
m.mu.Unlock()
|
||||
if !done {
|
||||
if row, found, err := m.registry.OperatorSession(ctx, sessionID); err == nil && found {
|
||||
hinter.HintDirectory(ctx, sessionID, row.Directory)
|
||||
if hintsDirectory {
|
||||
hinter.HintDirectory(ctx, sessionID, row.Directory)
|
||||
}
|
||||
// The registry holds the operator's title, renames included, so
|
||||
// a session rebuilt after a restart keeps its name.
|
||||
if takesTitle && row.Title != "" {
|
||||
titler.SetTitle(ctx, sessionID, row.Title)
|
||||
}
|
||||
m.mu.Lock()
|
||||
if m.hinted == nil {
|
||||
m.hinted = map[string]bool{}
|
||||
@@ -292,6 +301,26 @@ func (m *chatManager) brokerFor(ctx context.Context, sessionID string) (chatBrok
|
||||
return adapter, nil
|
||||
}
|
||||
|
||||
// chatTitleSetter is a harness that names its own sessions from the operator's
|
||||
// chat title (Claude Code passes it as --name on the next spawn). SetTitle
|
||||
// records the title in memory only and does no I/O.
|
||||
type chatTitleSetter interface {
|
||||
SetTitle(ctx context.Context, sessionID, title string)
|
||||
}
|
||||
|
||||
// SetTitle hands a renamed chat's title to its harness when the harness keeps
|
||||
// one. The registry stays the source of truth; this only refreshes the name the
|
||||
// harness shows outside the app.
|
||||
func (m *chatManager) SetTitle(ctx context.Context, sessionID, title string) {
|
||||
adapter, err := m.brokerFor(ctx, sessionID)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if titler, ok := adapter.(chatTitleSetter); ok {
|
||||
titler.SetTitle(ctx, sessionID, title)
|
||||
}
|
||||
}
|
||||
|
||||
// chatDirectoryHinter is a harness that needs a session's recorded directory
|
||||
// to find it after a restart (Claude Code keeps a transcript in the
|
||||
// directory's own CLAUDE_CONFIG_DIR). HintDirectory is cheap after the first
|
||||
|
||||
Reference in New Issue
Block a user