MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / saveCurrentProjectConfig

Function saveCurrentProjectConfig

source code/utils/config.ts:1627–1700  ·  view source on GitHub ↗
(
  updater: (currentConfig: ProjectConfig) => ProjectConfig,
)

Source from the content-addressed store, hash-verified

1625}
1626
1627export function saveCurrentProjectConfig(
1628 updater: (currentConfig: ProjectConfig) => ProjectConfig,
1629): void {
1630 if (process.env.NODE_ENV === 'test') {
1631 const config = updater(TEST_PROJECT_CONFIG_FOR_TESTING)
1632 // Skip if no changes (same reference returned)
1633 if (config === TEST_PROJECT_CONFIG_FOR_TESTING) {
1634 return
1635 }
1636 Object.assign(TEST_PROJECT_CONFIG_FOR_TESTING, config)
1637 return
1638 }
1639 const absolutePath = getProjectPathForConfig()
1640
1641 let written: GlobalConfig | null = null
1642 try {
1643 const didWrite = saveConfigWithLock(
1644 getGlobalClaudeFile(),
1645 createDefaultGlobalConfig,
1646 current => {
1647 const currentProjectConfig =
1648 current.projects?.[absolutePath] ?? DEFAULT_PROJECT_CONFIG
1649 const newProjectConfig = updater(currentProjectConfig)
1650 // Skip if no changes (same reference returned)
1651 if (newProjectConfig === currentProjectConfig) {
1652 return current
1653 }
1654 written = {
1655 ...current,
1656 projects: {
1657 ...current.projects,
1658 [absolutePath]: newProjectConfig,
1659 },
1660 }
1661 return written
1662 },
1663 )
1664 if (didWrite && written) {
1665 writeThroughGlobalConfigCache(written)
1666 }
1667 } catch (error) {
1668 logForDebugging(`Failed to save config with lock: ${error}`, {
1669 level: 'error',
1670 })
1671
1672 // Same race window as saveGlobalConfig's fallback -- refuse to write
1673 // defaults over good cached config. See GH #3117.
1674 const config = getConfig(getGlobalClaudeFile(), createDefaultGlobalConfig)
1675 if (wouldLoseAuthState(config)) {
1676 logForDebugging(
1677 'saveCurrentProjectConfig fallback: re-read config is missing auth that cache has; refusing to write. See GH #3117.',
1678 { level: 'error' },
1679 )
1680 logEvent('tengu_config_auth_loss_prevented', {})
1681 return
1682 }
1683 const currentProjectConfig =
1684 config.projects?.[absolutePath] ?? DEFAULT_PROJECT_CONFIG

Callers 15

saveCurrentSessionCostsFunction · 0.85
TrustDialogFunction · 0.85
exampleCommands.tsFile · 0.85
createWorktreeForSessionFunction · 0.85
keepWorktreeFunction · 0.85
cleanupWorktreeFunction · 0.85
bridgeMainFunction · 0.85
onStdinDataFunction · 0.85
flushFunction · 0.85

Calls 7

saveConfigWithLockFunction · 0.85
logForDebuggingFunction · 0.85
wouldLoseAuthStateFunction · 0.85
logEventFunction · 0.85
saveConfigFunction · 0.85
getConfigFunction · 0.70

Tested by

no test coverage detected