Class: EasyAI::Command::Claude
- Inherits:
-
AIToolBase
- Object
- CLAide::Command
- EasyAI::Command
- AIToolBase
- EasyAI::Command::Claude
- Defined in:
- lib/easyai/command/claude.rb
Constant Summary collapse
- DEFAULT_ENV =
Claude Code 默认禁用遥测与非必要流量;用户可在 config.json 的 env 中显式覆盖
{ 'DISABLE_TELEMETRY' => '1', 'CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC' => '1' }.freeze
Constants inherited from AIToolBase
AIToolBase::PROTECTED_ENV_KEYS
Constants inherited from EasyAI::Command
DEFAULT_OPTIONS, DEFAULT_ROOT_OPTIONS
Instance Attribute Summary
Attributes inherited from EasyAI::Command
Instance Method Summary collapse
- #default_env ⇒ Object
- #exec_command ⇒ Object
- #install_hint ⇒ Object
-
#pre_exec ⇒ Object
启动 claude 之前把 Claude Code 状态强制对齐到“纯 token 模式”,避免 OAuth 残留影响: 1.
- #tool_name ⇒ Object
Methods inherited from AIToolBase
#initialize, options, #run, #validate!
Methods inherited from EasyAI::Command
#initialize, options, run, #validate!
Constructor Details
This class inherits a constructor from EasyAI::Command::AIToolBase
Instance Method Details
#default_env ⇒ Object
46 47 48 |
# File 'lib/easyai/command/claude.rb', line 46 def default_env DEFAULT_ENV end |
#exec_command ⇒ Object
38 39 40 |
# File 'lib/easyai/command/claude.rb', line 38 def exec_command 'claude' end |
#install_hint ⇒ Object
42 43 44 |
# File 'lib/easyai/command/claude.rb', line 42 def install_hint '未找到 claude CLI。请安装:npm install -g @anthropic-ai/claude-code' end |
#pre_exec ⇒ Object
启动 claude 之前把 Claude Code 状态强制对齐到“纯 token 模式”,避免 OAuth 残留影响:
1. ~/.claude.json: hasCompletedOnboarding=true(跳过 onboarding)
2. ~/.claude.json: 删除 oauthAccount 字段(OAuth 账户元数据残留)
3. macOS Keychain: 删除 "Claude Code-credentials" 条目(OAuth token 残留)
三步全部幂等:已是目标状态则不操作;任意 IO/JSON/Keychain 异常降级为 warning,不阻塞 exec。
副作用提醒:如果用户直接跑 ‘claude`(不通过 easyai)走过 OAuth 登录,下一次跑 `easyai claude` 会清掉 OAuth 状态。EasyAI 设计前提是统一走 ANTHROPIC_AUTH_TOKEN 环境变量路径,OAuth 登录态由 `easyai backup claude` / `easyai restore claude` 显式管理。
59 60 61 62 |
# File 'lib/easyai/command/claude.rb', line 59 def pre_exec reset_claude_state_to_token_mode delete_keychain_credential(KEYCHAIN_LABEL) end |
#tool_name ⇒ Object
34 35 36 |
# File 'lib/easyai/command/claude.rb', line 34 def tool_name 'claude' end |