MCPcopy
hub / github.com/codeaashu/claude-code / fetchSession

Function fetchSession

src/utils/teleport/api.ts:289–327  ·  view source on GitHub ↗
(
  sessionId: string,
)

Source from the content-addressed store, hash-verified

287 * @returns The session resource
288 */
289export async function fetchSession(
290 sessionId: string,
291): Promise<SessionResource> {
292 const { accessToken, orgUUID } = await prepareApiRequest()
293
294 const url = `${getOauthConfig().BASE_API_URL}/v1/sessions/${sessionId}`
295 const headers = {
296 ...getOAuthHeaders(accessToken),
297 'anthropic-beta': 'ccr-byoc-2025-07-29',
298 'x-organization-uuid': orgUUID,
299 }
300
301 const response = await axios.get<SessionResource>(url, {
302 headers,
303 timeout: 15000,
304 validateStatus: status => status < 500,
305 })
306
307 if (response.status !== 200) {
308 // Extract error message from response if available
309 const errorData = response.data as { error?: { message?: string } }
310 const apiMessage = errorData?.error?.message
311
312 if (response.status === 404) {
313 throw new Error(`Session not found: ${sessionId}`)
314 }
315
316 if (response.status === 401) {
317 throw new Error('Session expired. Please run /login to sign in again.')
318 }
319
320 throw new Error(
321 apiMessage ||
322 `Failed to fetch session: ${response.status} ${response.statusText}`,
323 )
324 }
325
326 return response.data
327}
328
329/**
330 * Extracts the first branch name from a session's git repository outcomes

Callers 4

runFunction · 0.85
pollRemoteSessionEventsFunction · 0.85

Calls 3

prepareApiRequestFunction · 0.85
getOauthConfigFunction · 0.85
getOAuthHeadersFunction · 0.85

Tested by

no test coverage detected