Skip to content

Conversation

@benny123tw
Copy link

Description

Fixes #949 by handling array values in CLI flags properly, using a different approach from #952.

When users provide multiple values for a flag (e.g., ccr code --settings valueA valueB), minimist parses it as an array. The previous code would JSON.stringify() the entire array, resulting in malformed command construction like:

--settings [valueA,valueB,{"env":{...}}]

This caused errors such as:

Error: Settings file not found: [/Users/user/.claude/settings.json,{"env":{...}}]

Approach

This PR takes a different approach from #952 by keeping the original design intact while adding proper array handling:

  • Fix ccr code flag #952's approach: Simplifies by removing minimist and passing arguments directly
  • This PR's approach: Keeps the existing architecture but adds array detection and expansion

Changes Made

  1. Array flag handling: Detects array values and expands them into separate flag-value pairs

    // Instead of: --settings [value1,value2]
    // Generates: --settings value1 --settings value2
  2. Removed shell-quote dependency: No longer needed with proper array handling

  3. Added @types/minimist: Improved TypeScript support

  4. Type safety improvements: Fixed type annotations for env and settingsFlag

Benefits of This Approach

  • Maintains the original minimist-based argument parsing design
  • Supports both single and multiple values naturally
  • Minimal changes to existing code structure
  • Properly handles edge cases where users intentionally provide multiple flag values

Testing

This fix allows commands like this to work correctly:

ccr code --settings ~/.claude/settings.json --settings ~/.claude/settings2.json

Related


Note: Both this PR and #952 are valid solutions. This approach preserves more of the existing architecture, while #952 simplifies the overall design. The maintainers can choose which approach better fits the project's direction.

Previously, when users provided multiple values for a flag (e.g., --settings valueA valueB),
minimist would parse it as an array, but the code would JSON.stringify the entire array,
resulting in incorrect command construction like:
--settings [valueA,valueB,{"env":{...}}]

This caused errors such as:
"Error: Settings file not found: [/path/to/settings.json,{"env":{...}}]"

Changes:
- Remove shell-quote dependency (no longer needed)
- Add @types/minimist for better type safety
- Handle array values by creating separate flag-value pairs for each item
- Maintain original design while properly supporting multi-flag syntax
- Fix type annotations for env and settingsFlag

This approach keeps the original design intact but adds proper array handling,
allowing users to use multi-flags like: ccr code --settings value1 --settings value2

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Can't set Claude Code CLI settings

1 participant