MCPcopy Index your code
hub / github.com/claude-code-best/claude-code / saveCurrentProjectConfig

Function saveCurrentProjectConfig

src/utils/config.ts:1633–1706  ·  view source on GitHub ↗
(
  updater: (currentConfig: ProjectConfig) => ProjectConfig,
)

Source from the content-addressed store, hash-verified

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

Callers 15

saveCurrentSessionCostsFunction · 0.85
onChangeFunction · 0.85
exampleCommands.tsFile · 0.85
createWorktreeForSessionFunction · 0.85
keepWorktreeFunction · 0.85
cleanupWorktreeFunction · 0.85
bridgeMainFunction · 0.85
onStdinDataFunction · 0.85
callOnboardingFunction · 0.85

Calls 7

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

Tested by

no test coverage detected