Skip to content

Conversation

@yimsk
Copy link
Contributor

@yimsk yimsk commented Jan 12, 2026

Summary

  • Add -c, --config CLI flag for custom config path
  • Add CLAWS_CONFIG env var support
  • Precedence: CLI flag > env var > default

Changes

  • SetConfigPath(), GetConfigPath(), expandTilde() in config/file.go
  • Tilde expansion (~/) support
  • File existence validation before use

Closes #106

yimsk added 3 commits January 12, 2026 01:31
- Add -c/--config flag for custom config path
- Add CLAWS_CONFIG env var support
- Precedence: CLI flag > env var > default
- Validate file exists before loading
- Autosave writes to specified path
SetConfigPath now expands ~/path to full home directory path,
allowing `claws -c ~/.my-config.yaml` to work as expected.
- expandTilde now returns error on UserHomeDir failure
- use apperrors.Wrap instead of fmt.Errorf
@claude

This comment was marked as resolved.

@claude
Copy link

claude bot commented Jan 12, 2026

PR Review: Custom Config File Path Support

Summary

This PR adds support for custom config file paths via CLI flag (-c/--config) and environment variable (CLAWS_CONFIG). The implementation is well-structured and includes comprehensive tests.

✅ Strengths

  1. Excellent Test Coverage: The PR includes thorough unit tests covering:

    • Valid/invalid paths
    • Tilde expansion
    • Config loading with custom paths
    • Integration with existing config system
  2. Good Documentation: Clear documentation in docs/configuration.md with examples and use cases

  3. Consistent Error Handling: Uses the project's apperrors.Wrap pattern consistently

  4. Thread-Safe Implementation: Proper use of sync.RWMutex for concurrent access to config path

  5. Precedence Logic: Clear and well-documented precedence (CLI flag > env var > default)

🐛 Potential Issues

Critical: Race Condition in Global State

Location: internal/config/file.go:72-95 (ConfigDir, ConfigPath)

The current implementation has a potential race condition. The mutex is unlocked before returning, but the value could change between ConfigPath() and Load(). This is likely fine since SetConfigPath() is called early in main() before concurrent operations, but consider using sync.Once for stronger guarantees.

Minor Issues

  1. Tilde handling: Only handles ~/ prefix, not standalone ~
  2. Error message: Line 36 in main.go could be more specific: "Error loading config file: %v"
  3. Test gap: Missing test for GetConfigPath() with no custom path set

🔒 Security Considerations

No security issues identified:

  • File existence is validated before use
  • No path traversal vulnerabilities
  • Proper error handling prevents information disclosure

⚡ Performance Considerations

No performance concerns:

  • Mutex usage is appropriate and minimal
  • Config path is set once at startup

🎯 Overall Assessment

Verdict: ✅ Approve with minor suggestions

This is a well-implemented feature with good test coverage. The code is production-ready with the understanding that SetConfigPath() is called early in main() before any concurrent access to config.

Recommendation: Merge after considering the sync.Once pattern for the race condition concern.

@yimsk yimsk merged commit 926e6e2 into develop Jan 12, 2026
6 checks passed
@yimsk yimsk deleted the feature/custom-config-path branch January 12, 2026 02:29
@yimsk yimsk mentioned this pull request Jan 12, 2026
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.

1 participant