Repository navigation
Match the Claude CLI's project-dir encoding when checking a resume target - #522
Merged
Merged
Conversation
The CLI names a session's history directory after the cwd with every character outside [a-zA-Z0-9] replaced by '-'. The resume check replaced only '/', so for a workspace path with '_' or '.' it looked in a directory that does not exist, and every client rebuild started a new conversation. Use the CLI's regex, per UTF-16 code unit. For a name over 200 characters the CLI cuts it and adds '-<hash>'; match on the cut name plus '-', as the CLI does when it looks up a session. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
alex-clickhouse
marked this pull request as ready for review
October 17, 2026 09:34
pufit
approved these changes
Oct 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
ClaudeBackend.validate_resume_targetnow builds the history directory name with the same rule as the Claude CLI. Before Nerve resumes a stored SDK session, it checks that~/.claude/projects/<encoded-cwd>/<session-id>.jsonlexists. The check encoded the cwd by replacing only/with-.Why
The CLI replaces every character outside
[a-zA-Z0-9]with-. For a workspace path that contains another character, for example_or., the check looks in a directory that does not exist and returnsFalse. The engine then drops the stored session ID and starts a new conversation on each client rebuild: model change, dead client, restart. Seen with a workspace at/tmp/<name>_/ws: the CLI wrote to-tmp-<name>--ws, and the check looked in-tmp-<name>_-ws. Paths such as~/nerve-workspaceare not affected.How
The rule comes from the CLI bundled with
claude-agent-sdk0.2.161:_encode_project_dir()applies the same regex. The JS regex works on UTF-16 code units, so a character outside the Basic Multilingual Plane becomes--.nodegives the same output for the test inputs.-<hash>. When the CLI looks up a session, it lists the projects directory and matches on the cut name plus-._long_project_dir_names()does the same, so Nerve does not compute the hash. A missing projects directory givesFalse, the same as for a short name.exceptdo not change.Tests
tests/test_engine.py::TestValidateResumeTarget:_and.(mocked and on a real filesystem), a character outside the BMP, a name over 200 characters with a suffixed directory, a sibling that does not match, and a missing projects directory.replace("/", "-"). pytest'stmp_pathcontains_, so they now use the CLI rule.Full backend suite: 5753 passed, 38 skipped.
🤖 Generated with Claude Code