Skip to content

ccc removes user-defined env field from ~/.claude/settings.json on every run #74

@istarwyh

Description

@istarwyh

Bug Description

When running ccc, the entire env field in ~/.claude/settings.json gets removed, including user-defined environment variables that are not related to any provider.

Steps to Reproduce

  1. Create or edit ~/.claude/settings.json with custom env variables:
{
  "permissions": {
    "defaultMode": "bypassPermissions"
  },
  "env": {
    "MY_CUSTOM_VAR": "some_value",
    "ANTHROPIC_AUTH_TOKEN": "should_be_removed"
  }
}
  1. Run ccc (any provider)
  2. Check ~/.claude/settings.json again
  3. Observe that the entire env field is missing

Expected Behavior

Only provider-related environment variables should be removed:

  • ANTHROPIC_* prefixed variables
  • CLAUDE_* prefixed variables
  • Provider-specific env keys

User-defined environment variables like MY_CUSTOM_VAR should be preserved.

Actual Behavior

The entire env object is deleted from settings.json.

Root Cause Analysis

The issue is in internal/provider/provider.go:81:

// Remove env from settings before saving (provider env is passed via command line)
delete(settingsWithHook, "env")

This line removes the entire env field after CleanEnvInSettings() has already done the proper cleanup of provider-specific variables.

The code should preserve the result of CleanEnvInSettings() instead of deleting the entire env object.

Impact

  • User custom environment variables are lost every time ccc runs
  • Users cannot persist custom configuration in settings.json.env
  • This breaks workflows that rely on custom environment variables

Suggested Fix

Remove line 81 in internal/provider/provider.go:

// Remove env from settings before saving (provider env is passed via command line)
delete(settingsWithHook, "env")  // <- DELETE THIS LINE

The CleanEnvInSettings() function on line 65 already properly removes provider-related environment variables while preserving user-defined ones.

Test Case Update

The test in internal/provider/provider_test.go:99-102 should also be updated to expect that non-provider env variables are preserved.

Environment

  • OS: macOS
  • ccc version: current
  • Go version: [if applicable]

Additional Context

The design intention to avoid persisting provider credentials to settings.json is good for security, but the current implementation is too aggressive and removes user configuration as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions