π File detail
utils/tempfile.ts
π§© .tsπ 32 linesπΎ 1,170 bytesπ text
β Back to All Filesπ― Use case
This file lives under βutils/β, which covers cross-cutting helpers (shell, tempfiles, settings, messages, process input, β¦). On the API surface it exposes generateTempFilePath β mainly functions, hooks, or classes. Dependencies touch crypto, Node OS/process metadata, and Node path helpers.
Generated from folder role, exports, dependency roots, and inline comments β not hand-reviewed for every path.
π§ Inline summary
import { createHash, randomUUID } from 'crypto' import { tmpdir } from 'os' import { join } from 'path' /**
π€ Exports (heuristic)
generateTempFilePath
π External import roots
Package roots from from "β¦" (relative paths omitted).
cryptoospath
π₯οΈ Source preview
import { createHash, randomUUID } from 'crypto'
import { tmpdir } from 'os'
import { join } from 'path'
/**
* Generate a temporary file path.
*
* @param prefix Optional prefix for the temp file name
* @param extension Optional file extension (defaults to '.md')
* @param options.contentHash When provided, the identifier is derived from a
* SHA-256 hash of this string (first 16 hex chars). This produces a path
* that is stable across process boundaries β any process with the same
* content will get the same path. Use this when the path ends up in content
* sent to the Anthropic API (e.g., sandbox deny lists in tool descriptions),
* because a random UUID would change on every subprocess spawn and
* invalidate the prompt cache prefix.
* @returns Temp file path
*/
export function generateTempFilePath(
prefix: string = 'claude-prompt',
extension: string = '.md',
options?: { contentHash?: string },
): string {
const id = options?.contentHash
? createHash('sha256')
.update(options.contentHash)
.digest('hex')
.slice(0, 16)
: randomUUID()
return join(tmpdir(), `${prefix}-${id}${extension}`)
}