spacehub

surshar / claude-code

Claude Code is an agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster by executing routine tasks, explaining complex code, and handling git workflows - all through natural language commands.

Built by Anthropic · github.com/anthropics

claude-code / mods / telemetry / hooks / context / remote-hash-of / remote-hash-of.ts
24 lines · 812 BRaw
1import { hexOf } from './hex-of'
2import { normalizedRemoteOf } from './normalized-remote-of'
3import { REMOTE_HASH_LENGTH } from './remote-hash-length'
4
5/**
6 * The rows' `rh`: the first hex digits of the SHA-256 of the session's
7 * normalized origin remote, the key the CLI's own rows join a repository by.
8 *
9 * @param remote the origin remote as `$.session.repo()` answers it
10 * @returns the hash, or undefined outside a recognized remote
11 */
12export async function remoteHashOf(
13 remote: string | null | undefined,
14): Promise<string | undefined> {
15 const normalized = remote ? normalizedRemoteOf(remote) : undefined
16
17 if (normalized === undefined) {
18 return undefined
19 }
20
21 return hexOf(
22 await crypto.subtle.digest('SHA-256', new TextEncoder().encode(normalized)),
23 ).slice(0, REMOTE_HASH_LENGTH)
24}