Skip to content

capture(claudecode): Discover with a Dir query silently matches almost nothing #28

Description

@JumpTechCode

encodeProjectDir renders a path the way the store names its project
directories:

return strings.ReplaceAll(strings.TrimSuffix(dir, "/"), "/", "-")

The store's actual rule replaces every character outside [A-Za-z0-9-], not
just the separator. Recovering all 730 project-root transcripts' directory names
from the cwd they record: 73 are reproduced by replacing slashes alone, and
657 need the wider substitution. None are unexplained.

So Discover(ctx, Query{Dir: <a session's own working directory>}) returns zero
refs for most sessions, with no error — which is indistinguishable from a
directory that genuinely holds no transcripts. Any path containing . or _ is
affected; on a macOS store the temporary-directory paths alone are a large
share.

Nothing caught it because TestDiscoverHonoursTheQuery only asserts the
negative direction: that /nowhere/at/all yields nothing.

A second, smaller defect sits on the same line — the comparison is
strings.Contains, so Dir: "/work" also matches a project directory named for
/workspace/other.

Fix

func encodeProjectDir(dir string) string {
	return strings.Map(func(r rune) rune {
		switch {
		case r >= 'a' && r <= 'z', r >= 'A' && r <= 'Z', r >= '0' && r <= '9', r == '-':
			return r
		}
		return '-'
	}, strings.TrimSuffix(dir, "/"))
}

and compare for equality, or on a path boundary, rather than by substring.

Test

A positive case: a store whose project directory is named for a path containing
. and _ must be found by a Dir query naming that path.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcapture-adapterThe Claude Code capture adapter

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions