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

Function getExtraBodyParams

src/services/api/claude.ts:272–331  ·  view source on GitHub ↗
(betaHeaders?: string[])

Source from the content-addressed store, hash-verified

270 * @returns A JSON object representing the extra body parameters.
271 */
272export function getExtraBodyParams(betaHeaders?: string[]): JsonObject {
273 // Parse user's extra body parameters first
274 const extraBodyStr = process.env.CLAUDE_CODE_EXTRA_BODY
275 let result: JsonObject = {}
276
277 if (extraBodyStr) {
278 try {
279 // Parse as JSON, which can be null, boolean, number, string, array or object
280 const parsed = safeParseJSON(extraBodyStr)
281 // We expect an object with key-value pairs to spread into API parameters
282 if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
283 // Shallow clone — safeParseJSON is LRU-cached and returns the same
284 // object reference for the same string. Mutating `result` below
285 // would poison the cache, causing stale values to persist.
286 result = { ...(parsed as JsonObject) }
287 } else {
288 logForDebugging(
289 `CLAUDE_CODE_EXTRA_BODY env var must be a JSON object, but was given ${extraBodyStr}`,
290 { level: 'error' },
291 )
292 }
293 } catch (error) {
294 logForDebugging(
295 `Error parsing CLAUDE_CODE_EXTRA_BODY: ${errorMessage(error)}`,
296 { level: 'error' },
297 )
298 }
299 }
300
301 // Anti-distillation: send fake_tools opt-in for 1P CLI only
302 if (
303 feature('ANTI_DISTILLATION_CC')
304 ? process.env.CLAUDE_CODE_ENTRYPOINT === 'cli' &&
305 shouldIncludeFirstPartyOnlyBetas() &&
306 getFeatureValue_CACHED_MAY_BE_STALE(
307 'tengu_anti_distill_fake_tool_injection',
308 false,
309 )
310 : false
311 ) {
312 result.anti_distillation = ['fake_tools']
313 }
314
315 // Handle beta headers if provided
316 if (betaHeaders && betaHeaders.length > 0) {
317 if (result.anthropic_beta && Array.isArray(result.anthropic_beta)) {
318 // Add to existing array, avoiding duplicates
319 const existingHeaders = result.anthropic_beta as string[]
320 const newHeaders = betaHeaders.filter(
321 header => !existingHeaders.includes(header),
322 )
323 result.anthropic_beta = [...existingHeaders, ...newHeaders]
324 } else {
325 // Create new array with the beta headers
326 result.anthropic_beta = betaHeaders
327 }
328 }
329

Callers 4

verifyApiKeyFunction · 0.85
queryModelFunction · 0.85
paramsFromContextFunction · 0.85

Calls 5

logForDebuggingFunction · 0.85
featureFunction · 0.85
errorMessageFunction · 0.50

Tested by

no test coverage detected