Skip to content

Conversation

@yanhao98
Copy link

@yanhao98 yanhao98 commented Nov 7, 2025

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.

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.
Copilot AI review requested due to automatic review settings November 7, 2025 13:26
Copy link

Copilot AI left a 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_DIR constant that respects CLAUDE_CODE_ROUTER_DIR environment 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
Copy link

Copilot AI Nov 7, 2025

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:

  1. Updating the volume mapping to match the example: - ~/.claude-code-router:/data
  2. 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.

Suggested change
- ~/.claude-code-router:/root/.claude-code-router
- ~/.claude-code-router:/data

Copilot uses AI. Check for mistakes.
Copy link
Author

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]>
@yanhao98
Copy link
Author

yanhao98 commented Nov 7, 2025

@copilot open a new pull request to apply changes based on the comments in this thread

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