Skip to content

Keep the mailbox of a Claude Code session when the agent changes directory - #6

Merged
Melow-code merged 2 commits into
mainfrom
fix/stable-claude-mailbox
Oct 3, 2026
Merged

Melow-code merged 2 commits into
mainfrom
fix/stable-claude-mailbox

Conversation

@Melow-code

Copy link
Copy Markdown
Owner

Problem

A lead session received no mail in real time. The daemon answered no-wake-configured for each message to it.

The hooks named the mailbox from the cwd of the hook input. Claude Code sets that cwd to the new directory after each cd of the agent. The shim named the mailbox from the session registry, which keeps the directory where the session started. After a cd, the same session thus had two mailboxes: the team command made the second one the lead, and the shim listened to the first one.

Fix

The hooks and the shim name the mailbox from CLAUDE_PROJECT_DIR. Claude Code sets it for the hooks and for the stdio MCP servers, and it stays on the directory where the session started. The cwd of the hook input and of the registry stay as the fallback.

A session that does no cd keeps its mailbox name.

Tests

  • the_project_directory_names_the_mailbox: the choice of the directory, with and without the variable.
  • a_changed_working_directory_keeps_the_mailbox: /lead x from a hook with another cwd applies to the mailbox of the start.
  • the_registry_names_the_mailbox_from_the_project_directory: the shim, when the registry gives another directory.

cargo test: 170 passed.

🤖 Generated with Claude Code

Melow-code and others added 2 commits October 3, 2026 17:16
…ctory

The hooks named the mailbox from the cwd of the hook input. Claude Code
sets that cwd to the new directory after each cd of the agent. The shim
named the mailbox from the session registry, which keeps the directory
where the session started. After a cd, a team command thus made a lead
with a second mailbox, and the shim did not listen to it: the lead got
its mail only when a hook ran.

The hooks and the shim now name the mailbox from CLAUDE_PROJECT_DIR, the
directory where the session started. Claude Code sets it for the hooks
and for the stdio MCP servers, and it does not change. The cwd of the
hook input, and the cwd of the registry, stay as the fallback.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Melow-code
Melow-code merged commit da4e392 into main Oct 3, 2026
4 checks passed
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