Skip to content

Add /rename builtin slash command#662

Open
daniel-agentee wants to merge 2 commits into
agentclientprotocol:mainfrom
daniel-agentee:acp-rename-builtin
Open

Add /rename builtin slash command#662
daniel-agentee wants to merge 2 commits into
agentclientprotocol:mainfrom
daniel-agentee:acp-rename-builtin

Conversation

@daniel-agentee
Copy link
Copy Markdown

Summary

Adds /rename <new title> as a builtin slash command. Typing it in any ACP client (including stock Zed.app) renames the current session: renameSession() from @anthropic-ai/claude-agent-sdk writes a custom-title entry to the session JSONL, and a session_info_update notification is emitted so the client can repaint its session list inline — no restart, no listSessions() round-trip required.

Empty argument prints a usage hint instead of being a silent no-op. SDK errors are surfaced as a chat message rather than thrown.

Why

ACP sessions can be retitled programmatically via renameSession(), but until now there was no way for a user to trigger that from inside a session — the title was either auto-summarised or unchangeable. The slash-command path also avoids needing any client-side UI work, so it ships value immediately on stock Zed.app.

What's in this PR

  • src/acp-agent.ts:
    • Imports renameSession from @anthropic-ai/claude-agent-sdk.
    • At the top of prompt(), before any SDK round-trip, intercepts /rename .... Empty → Usage: agent message; non-empty → calls renameSession(sessionId, title, { dir }), emits session_info_update with the new title and a fresh updatedAt, then sends a confirmation chunk. Returns { stopReason: "end_turn" } immediately.
    • In getAvailableSlashCommands, appends { name: "rename", description: "rename this session", input: { hint: "new session title" } } so the / picker surfaces it alongside SDK commands.
  • src/tests/rename-slash-command.test.ts: 4 tests covering happy path, empty-arg usage, SDK-error surfacing, and that /renamed doesn't accidentally match.

Tests

npx tsc --noEmit
npx vitest run

10 test files / 263 tests pass (4 new + 259 existing).

Companion notes

This PR is a single, self-contained feature: the rename machinery is provided by the SDK (renameSession), so there's no separate "rename infrastructure" PR to split out — only the slash command + the session_info_update emit that goes with it.

Mirrors the codex-acp builtin: typing `/rename <new title>` in a Claude
session calls `renameSession` from @anthropic-ai/claude-agent-sdk and
appends a custom-title entry to the session JSONL. The new title shows
up via listSessions() on the next refresh.

The command is intercepted at the top of `prompt()` before the SDK loop
starts, so it never round-trips through Claude. Empty argument prints a
usage hint; SDK errors are surfaced as a chat message rather than
thrown. `/rename` is also appended to the available-commands list so it
appears alongside SDK-provided slash commands in the picker.
renameSession() persists the new title to the session JSONL, but the
connected client only sees it on the next listSessions() refresh —
usually after restart. Send a session_info_update notification with
the new title (and a fresh updatedAt) so the client can repaint its
session list in place.
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.

1 participant