Skip to content

fix(discover): sanitize drive-letter colon so Windows discover finds sessions - #2952

Merged
KuSh merged 2 commits into
rtk-ai:developfrom
zbl1998-sdjn:fix/discover-windows-drive-colon
Aug 13, 2026
Merged

KuSh merged 2 commits into
rtk-ai:developfrom
zbl1998-sdjn:fix/discover-windows-drive-colon

Conversation

@zbl1998-sdjn

@zbl1998-sdjn zbl1998-sdjn commented Jul 11, 2026 •

Copy link
Copy Markdown
Contributor

Problem

On Windows, the default rtk discover (current-project mode) always reports Scanned: 0 sessions. --all and -p PROJECT work, so history parsing is fine — only current-project resolution fails. (#2919)

Root cause

ClaudeProvider::encode_project_path mirrors Claude Code's cwd → ~/.claude/projects/ slug encoding, replacing separators with -. Its SANITIZED_CHARS list ('/', '.', '_', '\\', ' ', '[', ']') is missing the drive-letter colon :.

Every Windows cwd carries one, so:

C:\Users\me\proj   -> rtk encodes    "C:-Users-me-proj"
C:\Users\me\proj   -> Claude folder  "C--Users-me-proj"   (Claude replaces ':' too)

The C:- vs C-- mismatch means the encoded slug is never a substring of the real folder name, so the substring match in discover_sessions_in_projects_dir finds nothing → 0 sessions. This also lines up with @superjaff's note above that Claude's sanitizer maps : \ / and spaces to -.

Ground truth on a Windows box: C:\Users\Administrator lands in ~/.claude/projects/C--Users-Administrator — Claude replaces the colon with -.

Fix

Add ':' to SANITIZED_CHARS (one char). The encoder is shared, so this also fixes the same 0-sessions symptom in rtk learn.

Tests (TDD, red → green)

  • test_encode_project_path_windows — corrected expectation: C:\Users\foo\bar → C--Users-foo-bar (was C:-Users-foo-bar, which had encoded the bug).
  • test_encode_project_path_windows_full_path — regression for a full Windows cwd.

Verified on Windows (rustc 1.96.0)

  • cargo fmt --all -- --check — clean
  • cargo clippy --all-targets -- -D warnings — zero warnings
  • cargo test discover::provider::tests — 21/21 pass
  • End-to-end from a real project dir:
    • before: Scanned: 0 sessions
    • after: Scanned: 1 sessions

(A full cargo test --all on my local Windows box has 16 pre-existing core::stream failures that spawn cat/echo, absent from my PATH — the identical 16 fail on unmodified develop, and they pass on CI's windows-latest.)

Scope

Colon sanitization is the deterministic root cause that breaks every Windows path. Drive-letter case-insensitivity (an uppercase E: cwd vs a lowercase e-- folder created by a different launch) is a separate, situational concern, left out of this focused PR.

Closes #2919

…sessions

encode_project_path mirrors Claude Code's cwd -> ~/.claude/projects slug, but
never replaced the drive-letter ':' with '-'. Every Windows cwd carries one, so
the encoded slug (C:-Users-me) never matched Claude's real folder (C--Users-me)
and the default `rtk discover` scanned 0 sessions on Windows. Add ':' to
SANITIZED_CHARS; the shared encoder also fixes `rtk learn`.

Refs rtk-ai#2919
Copilot AI review requested due to automatic review settings July 11, 2026 15:43
@CLAassistant

CLAassistant commented Jul 11, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes Windows-only current-project discovery by aligning ClaudeProvider::encode_project_path with Claude Code’s project-folder slug sanitization (drive-letter : → -), so rtk discover (and shared users like rtk learn) can find sessions under ~/.claude/projects/.

Changes:

  • Add : to the SANITIZED_CHARS list used by encode_project_path, preventing C:-... vs C--... mismatches on Windows.
  • Update the Rustdoc examples/comments to reflect the corrected Windows encoding output.
  • Update/extend unit tests to assert the corrected Windows slug and add a full-path regression case.

@zbl1998-sdjn

Copy link
Copy Markdown
Contributor Author

A correction to my own description above, now that I've had the chance to pin it down.

I wrote that a full cargo test --all on my Windows box had 16 pre-existing core::stream failures. That was true, but I misattributed the cause — it's just PATH. Those tests spawn cat and echo; run the suite from PowerShell, where neither is on PATH, and exactly those 16 fail (2440 passed / 16 failed). Run it from Git Bash, where both resolve, and the whole suite is green (2467 passed / 0 failed / 8 ignored). Same commit either way, so the caveat in the description doesn't really apply and this branch is clean on a full run. Sorry for the noise.

Something I should have checked before opening this, and have now: instead of inferring the encoding from folder names, I read the slug function in the installed Claude Code binary (2.1.215). It replaces every non-alphanumeric character with -, then truncates at 200 characters and appends a hash of the original path. That's good news for this PR — it means the colon is replaced on every platform, not just Windows, so adding ':' can't regress a Unix path that happens to contain one.

It also means SANITIZED_CHARS will keep drifting from that rule. (, ), +, &, @, , and friends still aren't replaced, and the 200-character cap isn't mirrored, so those paths still find zero sessions on any platform. I've kept this PR to the one character that breaks every Windows path, since that's the deterministic root cause, but if you'd prefer the encoder to mirror the rule directly I'm happy to open a follow-up for it.

Thanks for your time, and no rush from my side.

@KuSh KuSh left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Could you remove the duplicated test as it doesn't add anything except more maintenance surface. Thanks

Comment thread src/discover/provider.rs Outdated
@KuSh KuSh self-assigned this Aug 12, 2026
@KuSh
KuSh merged commit 6f0b0ca into rtk-ai:develop Aug 13, 2026
10 of 11 checks passed
@rtk-release-bot rtk-release-bot Bot mentioned this pull request Aug 13, 2026
social4hyq pushed a commit to social4hyq/homebrew-core that referenced this pull request Sep 20, 2026
rtk 0.46.0

Created-by: HarmonybrewBot
Commit-by: HarmonybrewBot
Merged-by: HarmonybrewBot
Description: Created by `brew bump`

---

Created with `brew bump-formula-pr`.<details>
  <summary>release notes</summary>
  <pre>## [0.46.0](rtk-ai/rtk@v0.45.0...v0.46.0) (2026-08-26)


### Features

- find: dispatch on find's grammar; compress find output for unmodeled predicates ([#3603](rtk-ai/rtk#3603))
- find: tee tail hint when rtk imposes the result cap ([#3603](rtk-ai/rtk#3603))

### Bug Fixes

- find: never-worse guard, recovery hint, and dispatch on find's grammar ([#3603](rtk-ai/rtk#3603))
- git: don't misdetect a value-taking option's argument as a patch flag ([#3575](rtk-ai/rtk#3575))
- cicd: stop benchmark.sh deleting the tracked scripts/benchmark harness ([#3595](rtk-ai/rtk#3595))
- tee: hash long recovery-file slugs to prevent collisions and shorten hints ([#3266](rtk-ai/rtk#3266))
- benchmark: avoid negative curl/cargo cases that fail the benchmark job ([#3430](rtk-ai/rtk#3430))
- test: accept both Ask and Allow verdicts in rewrite tests ([#3147](rtk-ai/rtk#3147)) — Closes [#3146](rtk-ai/rtk#3146)
- core: decode process output using Windows console code page ([#2717](rtk-ai/rtk#2717)) — Closes [#2452](rtk-ai/rtk#2452)
- git: preserve patch output from log commands ([#2951](rtk-ai/rtk#2951)) — Closes [#2944](rtk-ai/rtk#2944)
- discover: sanitize drive-letter colon so Windows discover finds sessions ([#2952](rtk-ai/rtk#2952)) — Closes [#2919](rtk-ai/rtk#2919)
- stream: decode lossily instead of dropping lines on invalid UTF-8 ([#2997](rtk-ai/rtk#2997)) — Closes [#2994](rtk-ai/rtk#2994)

### Other

- test(find): use the platform temp dir instead of /tmp ([#3717](https://github.com/rtk-ai/rtk/pull/3717))</pre>
  <p>View the full release notes at <a href="https://github.com/rtk-ai/rtk/releases/tag/v0.46.0">https://github.com/rtk-ai/rtk/releases/tag/v0.46.0</a>.</p>
</details>
<hr>

See merge request: Harmonybrew/homebrew-core!17826
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.

discover: 0 sessions scanned on Windows - drive-letter case mismatch when resolving current project

4 participants