()
| 121 | } |
| 122 | |
| 123 | func mcpConfigureClaudeCode() *serpent.Command { |
| 124 | var ( |
| 125 | claudeAPIKey string |
| 126 | claudeConfigPath string |
| 127 | claudeMDPath string |
| 128 | systemPrompt string |
| 129 | coderPrompt string |
| 130 | appStatusSlug string |
| 131 | testBinaryName string |
| 132 | aiAgentAPIURL url.URL |
| 133 | claudeUseBedrock string |
| 134 | |
| 135 | deprecatedCoderMCPClaudeAPIKey string |
| 136 | ) |
| 137 | cmd := &serpent.Command{ |
| 138 | Use: "claude-code <project-directory>", |
| 139 | Short: "Configure the Claude Code server. You will need to run this command for each project you want to use. Specify the project directory as the first argument.", |
| 140 | Handler: func(inv *serpent.Invocation) error { |
| 141 | if len(inv.Args) == 0 { |
| 142 | return xerrors.Errorf("project directory is required") |
| 143 | } |
| 144 | projectDirectory := inv.Args[0] |
| 145 | fs := afero.NewOsFs() |
| 146 | binPath, err := os.Executable() |
| 147 | if err != nil { |
| 148 | return xerrors.Errorf("failed to get executable path: %w", err) |
| 149 | } |
| 150 | if testBinaryName != "" { |
| 151 | binPath = testBinaryName |
| 152 | } |
| 153 | configureClaudeEnv := map[string]string{} |
| 154 | |
| 155 | if deprecatedCoderMCPClaudeAPIKey != "" { |
| 156 | cliui.Warnf(inv.Stderr, "CODER_MCP_CLAUDE_API_KEY is deprecated, use CLAUDE_API_KEY instead") |
| 157 | claudeAPIKey = deprecatedCoderMCPClaudeAPIKey |
| 158 | } |
| 159 | if claudeAPIKey == "" && claudeUseBedrock != "1" { |
| 160 | cliui.Warnf(inv.Stderr, "CLAUDE_API_KEY is not set.") |
| 161 | } |
| 162 | |
| 163 | if appStatusSlug != "" { |
| 164 | configureClaudeEnv[envAppStatusSlug] = appStatusSlug |
| 165 | } |
| 166 | if aiAgentAPIURL.String() != "" { |
| 167 | configureClaudeEnv[envAIAgentAPIURL] = aiAgentAPIURL.String() |
| 168 | } |
| 169 | if deprecatedSystemPromptEnv, ok := os.LookupEnv("SYSTEM_PROMPT"); ok { |
| 170 | cliui.Warnf(inv.Stderr, "SYSTEM_PROMPT is deprecated, use CODER_MCP_CLAUDE_SYSTEM_PROMPT instead") |
| 171 | systemPrompt = deprecatedSystemPromptEnv |
| 172 | } |
| 173 | |
| 174 | if err := configureClaude(fs, ClaudeConfig{ |
| 175 | // TODO: will this always be stable? |
| 176 | AllowedTools: []string{`mcp__coder__coder_report_task`}, |
| 177 | APIKey: claudeAPIKey, |
| 178 | ConfigPath: claudeConfigPath, |
| 179 | ProjectDirectory: projectDirectory, |
| 180 | MCPServers: map[string]ClaudeConfigMCP{ |
no test coverage detected