π File detail
utils/cachePaths.ts
π― Use case
This file lives under βutils/β, which covers cross-cutting helpers (shell, tempfiles, settings, messages, process input, β¦). On the API surface it exposes CACHE_PATHS β mainly types, interfaces, or factory objects. Dependencies touch env-paths and Node path helpers. It composes internal code from fsOperations and hash (relative imports). What the file header says: Local sanitizePath using djb2Hash β NOT the shared version from sessionStoragePortable.ts which uses Bun.hash (wyhash) when available. Cache directory names must remain stable across upgrades so existing cache data (error logs, MCP logs) is not orphaned.
Generated from folder role, exports, dependency roots, and inline comments β not hand-reviewed for every path.
π§ Inline summary
Local sanitizePath using djb2Hash β NOT the shared version from sessionStoragePortable.ts which uses Bun.hash (wyhash) when available. Cache directory names must remain stable across upgrades so existing cache data (error logs, MCP logs) is not orphaned.
π€ Exports (heuristic)
CACHE_PATHS
π External import roots
Package roots from from "β¦" (relative paths omitted).
env-pathspath
π₯οΈ Source preview
import envPaths from 'env-paths'
import { join } from 'path'
import { getFsImplementation } from './fsOperations.js'
import { djb2Hash } from './hash.js'
const paths = envPaths('claude-cli')
// Local sanitizePath using djb2Hash β NOT the shared version from
// sessionStoragePortable.ts which uses Bun.hash (wyhash) when available.
// Cache directory names must remain stable across upgrades so existing cache
// data (error logs, MCP logs) is not orphaned.
const MAX_SANITIZED_LENGTH = 200
function sanitizePath(name: string): string {
const sanitized = name.replace(/[^a-zA-Z0-9]/g, '-')
if (sanitized.length <= MAX_SANITIZED_LENGTH) {
return sanitized
}
return `${sanitized.slice(0, MAX_SANITIZED_LENGTH)}-${Math.abs(djb2Hash(name)).toString(36)}`
}
function getProjectDir(cwd: string): string {
return sanitizePath(cwd)
}
export const CACHE_PATHS = {
baseLogs: () => join(paths.cache, getProjectDir(getFsImplementation().cwd())),
errors: () =>
join(paths.cache, getProjectDir(getFsImplementation().cwd()), 'errors'),
messages: () =>
join(paths.cache, getProjectDir(getFsImplementation().cwd()), 'messages'),
mcpLogs: (serverName: string) =>
join(
paths.cache,
getProjectDir(getFsImplementation().cwd()),
// Sanitize server name for Windows compatibility (colons are reserved for drive letters)
`mcp-logs-${sanitizePath(serverName)}`,
),
}