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

Function parseShellRC

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

Source from the content-addressed store, hash-verified

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