fix: /cwd 切换工作目录前校验路径存在#42
Open
1359484419 wants to merge 2 commits into
Open
Conversation
added 2 commits
June 19, 2026 21:35
/cwd 原来直接把参数写入 session、不做任何校验,输错路径后下次对话 claude 会在不存在的 cwd 里 spawn 失败,错误很隐晦、难排查。 - 展开 ~、把相对路径解析为绝对路径(基于当前工作目录) - 校验目标存在且确实是目录,否则提示并拒绝切换 - 存储解析后的绝对路径,与 /send 的校验风格保持一致
手机输入法或 markdown 代码格式常给路径自动加上反引号或引号(如 \`/path\`、'/path'),导致路径开头不是 / 被当成相对路径拼接、校验失败。 切换前先剥离首尾的反引号/单双引号/空格。
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.
问题
/cwd原来直接把用户输入写入 session,不做任何校验。一旦路径输错,下次对话时claude会在一个不存在的cwd里 spawn,导致失败,且错误信息隐晦、难以排查。(对比之下/send已经有existsSync校验,/cwd缺。)改动
~、把相对路径解析为绝对路径(基于当前工作目录)/send的校验风格保持一致验证
npm run build(tsc)通过handleCwd四种情况:存在目录→切换、不存在→拒绝、是文件→拒绝、空参→显示当前 —— 全部符合预期