Skip to content

feat: add provider-specific terminal button - #452

Merged
farion1231 merged 7 commits into
farion1231:mainfrom
tianrking:main
Jan 12, 2026
Merged

feat: add provider-specific terminal button#452
farion1231 merged 7 commits into
farion1231:mainfrom
tianrking:main

Conversation

@tianrking

Copy link
Copy Markdown
Contributor

Add a terminal button next to each provider card that opens a new terminal window with that provider's specific API configuration. This allows using different providers independently without changing the global setting.

Changes:

  • Backend: Add open_provider_terminal command that extracts provider config and creates a temporary claude settings file
  • Frontend: Add terminal button to provider cards with proper callback propagation through component hierarchy
  • Support macOS (Terminal.app), Linux (gnome-terminal, konsole, etc.), and Windows (cmd)

Each provider gets a unique config file named claude_<providerId>_<pid>.json in the temp directory, containing the provider's API configuration.

🤖 Generated with Claude Code

Screenshot from 2025-12-23 17-04-29

Add a terminal button next to each provider card that opens a new terminal
window with that provider's specific API configuration. This allows using
different providers independently without changing the global setting.

Changes:
- Backend: Add `open_provider_terminal` command that extracts provider
  config and creates a temporary claude settings file
- Frontend: Add terminal button to provider cards with proper callback
  propagation through component hierarchy
- Support macOS (Terminal.app), Linux (gnome-terminal, konsole, etc.),
  and Windows (cmd)

Each provider gets a unique config file named `claude_<providerId>_<pid>.json`
in the temp directory, containing the provider's API configuration.

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

Co-Authored-By: Claude <noreply@anthropic.com>
@tianrking

Copy link
Copy Markdown
Contributor Author

ping @farion1231 :)

@farion1231
farion1231 self-requested a review December 27, 2025 15:16

@farion1231 farion1231 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感谢您的贡献,review 了一下存在一些问题,另外还有格式化和未使用变量问题,请修复一下

Comment thread src-tauri/src/commands/misc.rs
Comment thread src-tauri/src/commands/misc.rs Outdated
Comment thread src-tauri/src/commands/misc.rs Outdated
@tianrking

Copy link
Copy Markdown
Contributor Author

好滴 我来修改 😊

tianrking and others added 3 commits December 29, 2025 09:14
Resolved conflicts in src-tauri/src/lib.rs:
- Kept both: open_provider_terminal (my feature) and universal provider commands (upstream)

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

Co-Authored-By: Claude <noreply@anthropic.com>
…loses

在 open_provider_terminal 功能中添加了临时配置文件的自动清理逻辑,
确保在用户关闭终端窗口时自动删除创建的临时配置文件。

修改内容:
- Linux: 使用 bash -c 嵌套包装脚本,通过 trap EXIT 信号在 shell 退出时清理配置文件
- macOS: 同样使用嵌套 bash + trap 机制来处理清理
- Windows: 保持原有的批处理文件自删除逻辑(del 命令)

技术细节:
- 之前使用 sh -c "...; exec $SHELL" 会导致 trap 失效
- 现在使用 bash -c 'trap ... EXIT; ...; exec bash --norc --noprofile'
- exec 会替换进程但保留 trap 信号处理器
- 当用户关闭终端时,EXIT 信号触发清理操作

影响范围:
- src-tauri/src/commands/misc.rs (launch_terminal_with_env 函数)

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

Co-Authored-By: Claude <noreply@anthropic.com>
open_provider_terminal 功能仅支持 Claude Code,因此只在 Claude 应用中显示终端按钮。

修改内容:
- 在 ProviderList 组件调用时,根据 activeApp 条件传递 onOpenTerminal
- 仅当 activeApp === "claude" 时传递 handleOpenTerminal 回调
- Codex 和 Gemini 不会显示终端按钮(onOpenTerminal 为 undefined)

影响范围:
- src/App.tsx

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

Co-Authored-By: Claude <noreply@anthropic.com>
@tianrking
tianrking requested a review from farion1231 December 29, 2025 02:12
@tianrking

tianrking commented Dec 29, 2025

Copy link
Copy Markdown
Contributor Author
  1. 已在前端添加条件判断,open_provider_terminal 功能仅对 Claude Code 显示
    在 src/App.tsx 中:onOpenTerminal={activeApp === "claude" ? handleOpenTerminal : undefined}
    Codex 和 Gemini 不会显示终端按钮,避免了混淆
  2. 关于"GEMINI_API_KEY"环境变量名
    已修复 但是 现在没有用
  3. 关于"缺少清理逻辑"
    已实现自动清理:使用 trap 机制在终端关闭时删除临时配置文件
    macOS/Linux: trap "rm -f /tmp/config.json" EXIT
    Windows: 批处理文件执行完毕后自动删除配置文件和自身
    配置文件命名:claude_{providerId}_{pid}.json,使用进程 ID 确保唯一性

tianrking and others added 2 commits December 29, 2025 23:47
…v vars

重构 open_provider_terminal 相关代码,提升可维护性和可读性。

主要改进:
- 将 launch_terminal_with_env 拆分为多个职责单一的小函数
  * write_claude_config: 写入配置文件
  * escape_shell_path: 转义 shell 路径
  * generate_wrapper_script: 生成包装脚本
  * launch_macos_terminal / launch_linux_terminal / launch_windows_terminal: 平台特定启动逻辑
- 使用 let Some else 提前返回模式,减少嵌套
- 修复 Gemini 环境变量名为 GEMINI_API_KEY(而非 GOOGLE_API_KEY)
- 完善临时文件清理逻辑:
  * macOS/Linux: 使用 trap EXIT 自动清理
  * Windows: 批处理文件自删除
- 代码格式化和 import 排序优化

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

Co-Authored-By: Claude <noreply@anthropic.com>
Resolved conflict in src-tauri/src/commands/misc.rs by combining imports from both sides.

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

Co-Authored-By: Claude <noreply@anthropic.com>
@tianrking

Copy link
Copy Markdown
Contributor Author

ping @farion1231

@farion1231
farion1231 merged commit c56523c into farion1231:main Jan 12, 2026
@farion1231

Copy link
Copy Markdown
Owner

非常感谢您的贡献!

@alingse

alingse commented Jan 16, 2026

Copy link
Copy Markdown

这个 release 新版本了吗?话说有没有预览的版本呀,一旦构建成功,尝鲜用户可以直接用 master 功能呢

hpsoar pushed a commit to hpsoar/cc-switch that referenced this pull request Jan 30, 2026
Merged PR farion1231#452 which adds:
- Terminal button for Claude providers to launch with provider-specific config
- Cross-platform support (macOS/Linux/Windows)
- Auto-cleanup of temporary config files
dfbb pushed a commit to dfbb/cc-switch that referenced this pull request May 20, 2026
Merged PR farion1231#452 which adds:
- Terminal button for Claude providers to launch with provider-specific config
- Cross-platform support (macOS/Linux/Windows)
- Auto-cleanup of temporary config files
delta-lo pushed a commit to delta-lo/cc-switch-mod that referenced this pull request May 31, 2026
Merged PR farion1231#452 which adds:
- Terminal button for Claude providers to launch with provider-specific config
- Cross-platform support (macOS/Linux/Windows)
- Auto-cleanup of temporary config files
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.

3 participants