ccver

package
v0.26.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 8, 2026 License: MIT Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package ccver names the Claude Code that is installed on this machine, and does it without running one.

Why this exists at all

Three places in ccdad need the installed version, and all three need the same boundary rather than the number: 2.1.112 is the last release whose credential store reads the macOS Keychain, and the last that does not know CLAUDE_SECURESTORAGE_CONFIG_DIR. internal/cclink's keychain header carries the measurement and the consequences; this package answers "is this machine on that side of it".

Why nothing here spawns claude

`claude --version` is the obvious source and it is the wrong one. doctor's rule is that a probe must not create or disturb what it probes, and the native launcher resolves — and can update itself — on invocation, so asking it its version can CHANGE its version. It is also a ~300 MB process started to render one diagnostic row.

It is not needed, because the version is on the filesystem. Measured out of the installed 2.1.241 binary, which computes its own install layout as:

fpr()  = XDG_DATA_HOME ?? join(home, ".local", "share")
G8n()  = join(fpr(), "claude", "versions")     // where a version installs
q1e()  = join(home, ".local", "bin")           // the launcher directory
dan(e) = windows ? true
       : lstat(e).isSymbolicLink()
         && resolve(dirname(e), readlink(e)).includes(sep+"claude"+sep+"versions"+sep)
pan(e) = realpath(e).endsWith(".js") || realpath(e).includes("node_modules")

dan is Claude Code's own "is this launcher mine" test and pan its "is this an npm shim"; nativeVersion and npmVersion below are those two predicates, read for the version they imply. A native install is a symlink into .../claude/versions/<VERSION>, so one readlink names it. An npm install of any era resolves into node_modules, so the package's own package.json names it.

The launcher that is a copy

On Windows the installer does not link. dan() is `windows ? true` there because there is nothing to readlink: the install copies versions/<V> to <home>/.local/bin/claude.exe, and no manifest, marker or link records which <V> it took. Claude Code answers that question for itself by comparing SIZES, in its Windows update and again in its orphan cleanup, and both are already wrong on the machine this was written on. identifyCopy carries the measurement; the ruling is that the bytes are the only exact source, and that they are cheap enough to read.

One place this does MORE than dan: dan wants a boolean, so one readlink level answers it, while a version has to name what actually runs. Describe therefore reads the version off the fully resolved chain and keeps the one-level target only as a fallback -- a versions/2.1.100 entry that is itself a link to versions/2.1.241 runs 2.1.241, and naming the link would be a WRONG version rather than an unknown one.

To re-derive the layout against a newer build, take the byte offset first — a regex with a multi-thousand-character lookbehind over 229 MB does not return:

tr -d '\000' < ~/.local/share/claude/versions/<V> > cc.js
OFF=$(grep -abFo -m1 'function q1e(' cc.js | cut -d: -f1)
tail -c +$((OFF+1)) cc.js | head -c 900

What is deliberately NOT a source

Claude Code reports its own version from a compiled-in VERSION constant, inlined at every use site, so there is no on-disk manifest to mirror. The three files that look like one are all something else: ~/.claude.json's lastOnboardingVersion is the release that last ran onboarding (2.1.123 on the machine this was written on, against an installed 2.1.241), lastReleaseNotesSeen is what the user has read, and ~/.claude/.last-update-result.json's version_to is what the updater last wrote. A pinned or hand-placed launcher makes all three disagree with what runs. They are corroboration, never the answer.

Index

Constants

View Source
const PackageName = "@anthropic-ai/claude-code"

PackageName is the npm package every era of Claude Code ships under. It is checked rather than assumed: the walk up from a launcher passes through package.json files belonging to other things, and `claude install --local` writes one of them itself — ~/.claude/local/package.json is {"name":"claude-local","version":"0.0.1"}, which without this check would be reported as Claude Code 0.0.1.

Variables

View Source
var ErrNoClaudeCode = errors.New("ccdad could not find a claude launcher")

ErrNoClaudeCode is returned when no launcher could be found at all. It is distinct from "found one and could not name its version": a machine with no Claude Code is not a machine whose Claude Code is unreadable.

View Source
var LastPreSecureStorageDir = Version{2, 1, 112}

LastPreSecureStorageDir is the last Claude Code that does not know CLAUDE_SECURESTORAGE_CONFIG_DIR. 2.1.113 introduced the variable.

IT WAS CALLED LastPreSecureStorageDir, and the rename is the point of this comment. The keychain half was measured again and is FALSE: 2.1.234, 2.1.238 and 2.1.251 each carry a whole keychain backend that spawns `security find-generic-password`, and the combinator still reads the item BEFORE .credentials.json. The backend was never removed.

The two facts were bisected as one and only one of them held. The npm metadata that "agreed from the outside" -- bin entry "cli.js" through 2.1.112, "bin/claude.exe" from 2.1.113, unpacked size ~49 MB to ~132 KB -- dated the PACKAGING change, which is real and is not evidence about the backend. The code half searched a release for `name:"plaintext"`, found it, and stopped; the combinator is named `keychain-with-plaintext-fallback`, so finding the fallback proves nothing about the primary. See internal/cclink/keychain.go.

Every caller was re-read before the rename rather than swept: run.go and probe.go gate `ccdad run`'s default scoping on it, and doctor.go prints it in the claude-version row. All three want the variable, and doctor's keychain row -- the one caller that did want the keychain -- had already stopped asking, because an item is the login on every release and there is no era to be on.

Functions

This section is empty.

Types

type Install

type Install struct {
	// Launcher is the path that named it — what PATH resolved, or the
	// well-known location the fallback found.
	Launcher string
	// Target is where the launcher resolves to -- or, when Copied, the binary
	// its bytes were taken from, which is the nearest thing a copy has. It
	// EQUALS Launcher when the launcher is itself the binary, and is empty only
	// when the path could not be resolved at all. Whether a report prints it is String's decision, not
	// this field's: two places deciding the same thing is how one of them
	// becomes unreachable.
	Target string
	// Copied reports that Launcher is a byte-for-byte COPY of Target rather
	// than a link to it, which is the launcher the installer writes on
	// Windows. It is a field rather than a rendering decision taken inside
	// String, because the two shapes go out of step: replace the versions
	// entry and a symlink follows it while a copy does not, so a reader
	// checking ccdad's answer needs to know which of the two they have.
	Copied bool
	// Method is how it was installed, as far as the layout shows.
	Method Method
	// Version is the release, when Known.
	Version Version
	// Known reports whether Version means anything. False is a real answer —
	// a launcher ccdad cannot classify — and callers must not treat it as an
	// old version or as a new one.
	Known bool
	// Why explains an unknown version in the words doctor prints. Empty when
	// Known.
	Why string
}

Install is what ccdad could learn about the Claude Code on this machine.

func Describe

func Describe(launcher string) Install

Describe reports the version at a launcher path, reading only.

Every branch stats or reads; nothing here executes, creates or writes. That is what lets doctor call it.

func Probe

func Probe() (Install, error)

Probe finds the claude this machine would run and describes it.

PATH first, because that is what `ccdad run` execs and what a user's shell starts. The two fallbacks are the launcher locations Claude Code's own diagnostics fall back to in the same order, for the machine where claude is installed but its directory was never added to PATH — which is a state ccdad already reports on for its own binary.

func (Install) PreSecureStorageDir added in v0.9.4

func (in Install) PreSecureStorageDir() bool

PreSecureStorageDir reports whether this install is one where CLAUDE_SECURESTORAGE_CONFIG_DIR does nothing, which is what `ccdad run`'s default mode scopes with. It says nothing about the keychain: every release reads that item, so there is no era to be on.

An unknown version is NOT the era. Every caller acts on this — doctor rules `fail`, run refuses to start — and "ccdad could not classify this install" must not fire either of those on a machine that works.

func (Install) String

func (in Install) String() string

String renders the install for a diagnostic line.

type Method

type Method string

Method is how Claude Code got onto this machine, in the terms Claude Code's own installation classifier uses. Its taxonomy is finer — it separates npm-global from npm-local and detects package managers by shelling out to them — and this deliberately is not, because nothing ccdad does turns on the difference. What turns on it is the version, and both npm shapes carry that in the same file.

const (
	// MethodNative is the launcher the native installer writes: a symlink into
	// <data home>/claude/versions/<VERSION> -- or, on Windows, a byte-for-byte
	// COPY of one of the binaries in it, because that installer branches on
	// startsWith("win32") and calls copyFile where every other platform gets
	// symlink. Install.Copied says which of the two a given launcher is.
	MethodNative Method = "native"
	// MethodNPM is any install whose launcher resolves into a node_modules
	// tree holding PackageName — npm global, npm local (~/.claude/local), and
	// the Windows .cmd shim beside such a tree.
	MethodNPM Method = "npm"
	// MethodUnknown is a launcher ccdad found and could not classify.
	MethodUnknown Method = "unknown"
)

type Version

type Version struct{ Major, Minor, Patch int }

Version is a Claude Code release. Claude Code numbers releases MAJOR.MINOR.PATCH with no prerelease component in anything published so far; ParseVersion tolerates one rather than answering "unknown" if that ever changes.

func ParseVersion

func ParseVersion(s string) (Version, bool)

ParseVersion reads MAJOR.MINOR.PATCH.

A `-rc.1`-style prerelease suffix is dropped rather than rejected, and the version is then the release it is a prerelease OF. Semver precedence would order 2.1.113-rc.1 BELOW 2.1.113, which for this package's one question would be the wrong answer: a prerelease of the release that removed the keychain backend does not have the keychain backend.

That cut is also what makes strconv.Atoi safe to lean on here. Atoi accepts a leading sign, so "2.1.-1" would otherwise parse to a negative patch -- but the cut removes everything from the first '-' or '+' onward, so no sign ever reaches it and the component comes back empty instead. A separate digit check was written first and deleted: no input could distinguish it, which made it dead code that read like a guard.

func (Version) AtMost

func (v Version) AtMost(o Version) bool

AtMost reports whether v is o or older.

func (Version) Compare

func (v Version) Compare(o Version) int

Compare orders two versions: -1 if v is older, 0 if equal, 1 if newer.

Component-wise and numeric, which is the whole reason it exists rather than a string comparison: "2.1.99" sorts AFTER "2.1.113" as text, and the boundary this package exists to test sits at a three-digit patch number.

func (Version) NextPatch

func (v Version) NextPatch() Version

NextPatch is the release immediately after v. It exists so the one place LastPreSecureStorageDir is written stays the one place: every message that says "upgrade to 2.1.113 or later" derives that number from the boundary rather than repeating it, which is what stops the two from drifting apart.

func (Version) String

func (v Version) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL