MCPcopy Create free account
hub / github.com/alibaba/open-code-review / parseShellRC

Function parseShellRC

internal/llm/resolver.go:798–842  ·  view source on GitHub ↗
(path, modelOverride string)

Source from the content-addressed store, hash-verified

796}
797
798func parseShellRC(path, modelOverride string) (ResolvedEndpoint, bool, error) {
799 data, err := os.ReadFile(path)
800 if err != nil {
801 return ResolvedEndpoint{}, false, nil
802 }
803
804 var baseURL, token, model string
805 for _, line := range strings.Split(string(data), "\n") {
806 line = strings.TrimSpace(line)
807 matches := exportRe.FindStringSubmatch(line)
808 if matches == nil {
809 continue
810 }
811 key := matches[1]
812 value := matches[2]
813 if value == "" {
814 value = matches[3]
815 }
816 if value == "" {
817 value = matches[4]
818 }
819 value = strings.TrimSpace(value)
820
821 switch key {
822 case "ANTHROPIC_BASE_URL":
823 baseURL = value
824 case "ANTHROPIC_AUTH_TOKEN":
825 token = value
826 case "ANTHROPIC_MODEL":
827 model = value
828 }
829 }
830 if modelOverride != "" {
831 model = modelOverride
832 }
833
834 if baseURL == "" || token == "" || model == "" {
835 return ResolvedEndpoint{}, false, nil
836 }
837
838 url := ensureMessagesSuffix(baseURL)
839
840 // Claude Code shell rc tokens are OAuth/Bearer-style credentials.
841 return ResolvedEndpoint{URL: url, Token: token, Model: model, Protocol: ProtocolAnthropic, AuthHeader: "authorization", Source: "Shell rc file"}, true, nil
842}
843
844func defaultAuthHeader(protocol string) string {
845 // auth_header is Anthropic-only; OpenAI-compatible clients keep API key auth.

Callers 5

TestParseShellRCFunction · 0.85
tryShellRCFunction · 0.85

Calls 1

ensureMessagesSuffixFunction · 0.85

Tested by 4

TestParseShellRCFunction · 0.68