feat(naming)!: auto-derive mailbox name from project + runtime rename
Mailbox names are now built as <project>-<session-short>, where <project> is the sanitized git-repo basename (or cwd basename) — no more env-var prefix step. Sessions can re-tag themselves at runtime via the new mcp__mailbox__rename tool (POST /v1/rename), which transfers all pending messages to the new name in a single transaction. Peers using the old name re-discover via list_mailboxes. BREAKING: \$CLAUDE_MAILBOX_NAME is no longer read. Existing setups that relied on the env-var prefix should remove it from .claude/settings.json; the prefix now comes from the working directory automatically. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -137,22 +137,19 @@ function resolveHookMailboxName(explicit: string | undefined): string | null {
|
||||
if (explicit && explicit.trim()) return explicit.trim();
|
||||
const stdin = parseHookStdin(readStdinIfPiped());
|
||||
const sid = stdin?.session_id?.trim();
|
||||
if (sid) {
|
||||
const base = (process.env["CLAUDE_MAILBOX_NAME"] ?? "").trim() || null;
|
||||
return deriveSessionName(sid, base);
|
||||
}
|
||||
const envName = (process.env["CLAUDE_MAILBOX_NAME"] ?? "").trim();
|
||||
return envName || null;
|
||||
if (!sid) return null;
|
||||
const cwd = typeof stdin?.cwd === "string" ? stdin.cwd : process.cwd();
|
||||
return deriveSessionName(sid, cwd);
|
||||
}
|
||||
|
||||
program
|
||||
.command("check")
|
||||
.description(
|
||||
"Pull pending messages and mark delivered. In --hook mode the name is auto-derived from the SessionStart/UserPromptSubmit stdin (session_id), optionally flavored by $CLAUDE_MAILBOX_NAME.",
|
||||
"Pull pending messages and mark delivered. In --hook mode the name is auto-derived from the SessionStart/UserPromptSubmit stdin: <project>-<session-short>, where <project> is the git-repo or cwd basename from stdin.",
|
||||
)
|
||||
.option(
|
||||
"--name <name>",
|
||||
"Explicit mailbox name. Overrides hook stdin and $CLAUDE_MAILBOX_NAME.",
|
||||
"Explicit mailbox name. Overrides hook stdin auto-derivation.",
|
||||
)
|
||||
.option("--url <url>", "Daemon base URL", DEFAULT_URL)
|
||||
.option(
|
||||
@@ -162,10 +159,10 @@ program
|
||||
.action(async (opts: { name?: string; url: string; hook?: boolean }) => {
|
||||
const name = opts.hook
|
||||
? resolveHookMailboxName(opts.name)
|
||||
: (opts.name ?? process.env["CLAUDE_MAILBOX_NAME"] ?? "").trim() || null;
|
||||
: (opts.name ?? "").trim() || null;
|
||||
if (!name) {
|
||||
if (opts.hook) return;
|
||||
console.error("Missing --name (or set CLAUDE_MAILBOX_NAME).");
|
||||
console.error("Missing --name.");
|
||||
process.exit(1);
|
||||
}
|
||||
try {
|
||||
@@ -217,12 +214,13 @@ program
|
||||
const stdin = parseHookStdin(readStdinIfPiped());
|
||||
const sid = stdin?.session_id?.trim();
|
||||
if (!sid) return;
|
||||
const base = (process.env["CLAUDE_MAILBOX_NAME"] ?? "").trim() || null;
|
||||
const name = deriveSessionName(sid, base);
|
||||
const cwd = typeof stdin?.cwd === "string" ? stdin.cwd : process.cwd();
|
||||
const name = deriveSessionName(sid, cwd);
|
||||
|
||||
const lines = [
|
||||
`Claude-Mailbox: your mailbox name this session is \`${name}\`.`,
|
||||
`When using mcp__mailbox__* tools, ALWAYS pass this name explicitly:`,
|
||||
`The name is auto-derived as <project>-<session-short>. You can rename it (e.g. to tag your working area) with mcp__mailbox__rename(current_name="${name}", new_name="<project>-<area>-<short>"); after that, use the new name everywhere.`,
|
||||
`When using mcp__mailbox__* tools, ALWAYS pass your current name explicitly:`,
|
||||
` - mcp__mailbox__send: from="${name}"`,
|
||||
` - mcp__mailbox__check_inbox: name="${name}"`,
|
||||
` - mcp__mailbox__peek_inbox: name="${name}"`,
|
||||
|
||||
Reference in New Issue
Block a user