-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat: Allow configuring HOME_DIR via environment variable #982
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
This change allows users to customize the application's home directory by setting the CLAUDE_CODE_ROUTER_DIR environment variable. - Modified `src/constants.ts` to use `path.resolve` with the CLAUDE_CODE_ROUTER_DIR environment variable, falling back to the default `~/.claude-code-router` if not set. - Refactored `src/cli.ts`, `src/server.ts`, `src/index.ts`, `src/utils/index.ts`, and `src/utils/modelSelector.ts` to use the centralized `HOME_DIR` constant, removing hardcoded paths. - Updated `README.md`, `README_zh.md`, and `CLAUDE.md` to document this new feature and provide generic examples. - Added a comment to `docker-compose.yml` to show how to use the environment variable. - Updated `ui/config.example.json` to use a generic placeholder path.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds support for customizable configuration directories by introducing the CLAUDE_CODE_ROUTER_DIR environment variable. This allows users to override the default ~/.claude-code-router location, providing more flexibility for deployments in Docker, CI/CD environments, or custom setups.
- Centralized configuration path logic by introducing
HOME_DIRconstant that respectsCLAUDE_CODE_ROUTER_DIRenvironment variable - Replaced hardcoded path constructions throughout the codebase with centralized constants from
src/constants.ts - Updated documentation across README files to explain the new environment variable and its usage
Reviewed Changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/constants.ts | Added support for CLAUDE_CODE_ROUTER_DIR environment variable to customize the configuration directory location |
| src/server.ts | Replaced hardcoded path constructions with HOME_DIR constant for log directory paths |
| src/index.ts | Replaced hardcoded path constructions with HOME_DIR constant for log file path |
| src/cli.ts | Added CONFIG_FILE import and used it in console messages for consistency |
| src/utils/index.ts | Updated console message to use CONFIG_FILE constant instead of hardcoded path |
| src/utils/modelSelector.ts | Added HOME_DIR import and simplified config path construction |
| ui/config.example.json | Updated example path to be more generic instead of showing a specific user path |
| docker-compose.yml | Added commented example showing how to use CLAUDE_CODE_ROUTER_DIR environment variable |
| README.md | Added documentation about the new environment variable and updated path references to be relative to the configuration directory |
| README_zh.md | Added Chinese documentation about the new environment variable and updated path references |
| CLAUDE.md | Updated project overview to mention the configurable directory feature |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # environment: | ||
| # - CLAUDE_CODE_ROUTER_DIR=/data | ||
| volumes: | ||
| - ~/.claude-code-router:/root/.claude-code-router |
Copilot
AI
Nov 7, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The example shows setting CLAUDE_CODE_ROUTER_DIR=/data but the volumes mapping is still hardcoded to ~/.claude-code-router:/root/.claude-code-router. If a user sets the environment variable as suggested, there will be a mismatch between where the application looks for config (/data inside the container) and where the volume is mounted (/root/.claude-code-router).
Consider either:
- Updating the volume mapping to match the example:
- ~/.claude-code-router:/data - Or changing the environment variable example to match the current volume:
- CLAUDE_CODE_ROUTER_DIR=/root/.claude-code-router
Option 2 is simpler as it requires no volume changes, but option 1 provides a cleaner separation of data.
| - ~/.claude-code-router:/root/.claude-code-router | |
| - ~/.claude-code-router:/data |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CLAUDE_CODE_ROUTER_DIR=/root/.claude-code-router
Co-authored-by: Copilot <[email protected]>
|
@copilot open a new pull request to apply changes based on the comments in this thread |
This change allows users to customize the application's home directory by setting the CLAUDE_CODE_ROUTER_DIR environment variable.
src/constants.tsto usepath.resolvewith the CLAUDE_CODE_ROUTER_DIR environment variable, falling back to the default~/.claude-code-routerif not set.src/cli.ts,src/server.ts,src/index.ts,src/utils/index.ts, andsrc/utils/modelSelector.tsto use the centralizedHOME_DIRconstant, removing hardcoded paths.README.md,README_zh.md, andCLAUDE.mdto document this new feature and provide generic examples.docker-compose.ymlto show how to use the environment variable.ui/config.example.jsonto use a generic placeholder path.