Files
oh-my-claudecode/scripts/lib/encode-project-path.mjs
우종호 fb032107cd fix(session-search): encode underscores in project dir name (current-scope returns 0 matches) (#3330)
* fix(session-search): encode underscores (and all non-alphanumerics) in project dir name

encodeProjectPath replaced only / \ . : , leaving underscores intact. Claude
Code names ~/.claude/projects/<dir> by replacing every non-alphanumeric char
with '-', so any project whose path contained '_' was looked up under a dir
that never existed -> session_search returned 0 matches in 'current' scope
(project: 'all' was unaffected). Widen the class to [^a-zA-Z0-9], a superset
that still covers the path-separator/dot/drive-colon cases. Mirror the change
in the hook-runtime .mjs copy and add regression tests.

Fixes #3329

* docs: clarify Claude Code path encoding scope

---------

Co-authored-by: Yeachan-Heo <hurrc04@gmail.com>
Co-authored-by: Codex Review <codex-review@example.com>
2026-06-24 10:34:30 +09:00

29 lines
1.4 KiB
JavaScript

/**
* Claude Code project-directory character sanitization (hook-runtime mirror).
*
* Mirror of `src/utils/encode-project-path.ts` — keep the two in sync. The TS
* helper is the source of truth; this `.mjs` copy exists because the hook
* runtime loads raw scripts and cannot import the compiled `dist/` util.
*
* Claude Code stores a project's transcripts under
* `~/.claude/projects/<encoded>`. For normal-length project paths, this helper
* mirrors Claude Code's character replacement step: every character that is not
* an ASCII letter or digit is replaced by `-` (path separators, dots, the
* Windows drive colon, and also underscores, spaces, and non-ASCII characters).
* For example:
*
* POSIX: /home/me/proj -> -home-me-proj
* POSIX: /home/me/my.proj -> -home-me-my-proj
* POSIX: /home/me/00_proj -> -home-me-00-proj
* Windows: C:\Users\me\proj -> C--Users-me-proj
*
* Any character left unsanitized produces a name that never matches the real
* directory, so any lookup keyed on the encoded name silently finds nothing.
* This helper intentionally mirrors only Claude Code's normal-length character
* replacement/sanitization step, not its full long-path contract (which also
* truncates very long encoded names and appends a hash).
*/
export function encodeProjectPath(projectPath) {
return projectPath.replace(/[^a-zA-Z0-9]/g, '-');
}