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:
+41
-23
@@ -55,6 +55,46 @@ type controlReply struct {
|
||||
err string
|
||||
}
|
||||
|
||||
// cliArgs builds the CLI arguments for one spawn and returns the permission
|
||||
// mode it applied. resume continues an existing transcript; otherwise the CLI
|
||||
// pins the id recorded at create time. A known chat title is passed as --name,
|
||||
// which Claude Code records as the session's display name, so `claude --resume`
|
||||
// in a terminal lists the chat by its title.
|
||||
func (s *session) cliArgs(resume bool) ([]string, string) {
|
||||
args := []string{
|
||||
"-p",
|
||||
"--input-format", "stream-json",
|
||||
"--output-format", "stream-json",
|
||||
"--verbose",
|
||||
"--include-partial-messages",
|
||||
"--permission-prompt-tool=stdio",
|
||||
"--permission-prompts", "host",
|
||||
}
|
||||
if resume {
|
||||
args = append(args, "--resume", s.id)
|
||||
} else {
|
||||
args = append(args, "--session-id", s.id)
|
||||
}
|
||||
s.mu.Lock()
|
||||
model, mode, title := s.model, s.mode, s.title
|
||||
s.mu.Unlock()
|
||||
if model != "" {
|
||||
args = append(args, "--model", model)
|
||||
}
|
||||
if mode != "" && mode != defaultMode {
|
||||
args = append(args, "--permission-mode", mode)
|
||||
}
|
||||
if name := sessionDisplayName(title); name != "" {
|
||||
args = append(args, "--name", name)
|
||||
}
|
||||
return args, mode
|
||||
}
|
||||
|
||||
// sessionDisplayName folds a chat title onto one line for the CLI's session name.
|
||||
func sessionDisplayName(title string) string {
|
||||
return strings.Join(strings.Fields(title), " ")
|
||||
}
|
||||
|
||||
// spawn starts the CLI in the session directory. A session whose transcript
|
||||
// already exists resumes it; a new one pins the id we recorded at create time.
|
||||
func (s *session) spawn(ctx context.Context) (*process, error) {
|
||||
@@ -67,29 +107,7 @@ func (s *session) spawn(ctx context.Context) (*process, error) {
|
||||
if info, err := os.Stat(s.directory); err != nil || !info.IsDir() {
|
||||
return nil, fmt.Errorf("Claude session directory is not available: %s", s.directory)
|
||||
}
|
||||
args := []string{
|
||||
"-p",
|
||||
"--input-format", "stream-json",
|
||||
"--output-format", "stream-json",
|
||||
"--verbose",
|
||||
"--include-partial-messages",
|
||||
"--permission-prompt-tool=stdio",
|
||||
"--permission-prompts", "host",
|
||||
}
|
||||
if findTranscriptFile(s.id) != "" {
|
||||
args = append(args, "--resume", s.id)
|
||||
} else {
|
||||
args = append(args, "--session-id", s.id)
|
||||
}
|
||||
if s.model != "" {
|
||||
args = append(args, "--model", s.model)
|
||||
}
|
||||
s.mu.Lock()
|
||||
mode := s.mode
|
||||
s.mu.Unlock()
|
||||
if mode != "" && mode != defaultMode {
|
||||
args = append(args, "--permission-mode", mode)
|
||||
}
|
||||
args, mode := s.cliArgs(findTranscriptFile(s.id) != "")
|
||||
cmd := exec.CommandContext(s.chat.ctx, s.chat.binary, args...)
|
||||
cmd.Dir = s.directory
|
||||
env, notices := s.chat.processEnv(ctx, s.directory)
|
||||
|
||||
Reference in New Issue
Block a user