Skip to content

[Feature]: 支援在 .env 檔案配置 openrouter / claude code 環境變數 #325

@bibbychan

Description

@bibbychan

Issue Type

  • feature - New feature (non-breaking change which adds functionality)
  • performance - Performance improvement
  • 🖥️ backend - Backend-related feature
  • 🎨 frontend - Frontend-related feature

Component Scope

Both Frontend and Backend

Problem Statement

目前 claude-code-webui 並未原生支援從 .env 檔案載入 openrouter 或 Claude Code API 相關的環境變數,導致每次環境部署、開發、或切換 API Provider 時,需手動在程式碼或配置中更改,影響自動化與多環境管理效率。

Proposed Solution

希望能實作自動讀取 .env 檔案內容,並把 openrouter/Claude Code 相關(如 OPENROUTER_API_BASE, CLAUDE_CODE_API_KEY 等)環境變數注入到系統,讓專案部署、測試、切換 Provider 時能更彈性且安全管理。

Use Cases

  • 多人協作或 CI/CD 部署自動化時方便切換、保護敏感金鑰
  • 測試、開發不同 API 平台時只需切換 .env 檔案,不需動程式碼
  • 支援多 Provider 或多專案時大幅降低配置複雜度

Alternatives Considered

  • 直接編輯設定檔或硬編碼(安全性低且不易管理)
  • 使用系統環境變數(但部分服務難以跨平台且可見性差)

Priority

Low - Nice to have

Implementation Complexity (if known)

None

Implementation Considerations

  • 建議可用 dotenv 套件讀取 .env
  • 需確認已有的配置讀取邏輯是否衝突,並妥善 fallback
  • 可考慮 error handling,避免遺漏重要環境變數時出錯

Examples or Mockups

.env 檔範例

OPENROUTER_API_BASE=https://api.openrouter.ai/v1
CLAUDE_CODE_API_KEY=your_claude_key_here

Contribution

  • I would be willing to implement this feature myself
  • I would be willing to help test this feature
  • I would be willing to help with documentation
  • I would be willing to provide feedback during development

Additional Context

參考 dotenv 實作與安全配置最佳實踐

Checklist

  • I have searched existing issues and feature requests to make sure this is not a duplicate
  • I have provided a clear problem statement and proposed solution
  • I understand that feature requests are prioritized based on community needs and maintainer capacity

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureNew feature (non-breaking change which adds functionality)

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions