MCPcopy Create free account
hub / github.com/diillson/chatcli / syncClaudeCodeCreds

Function syncClaudeCodeCreds

auth/cli_sync.go:33–75  ·  view source on GitHub ↗

syncClaudeCodeCreds syncs credentials from Claude Code (~/.claude/).

(logger *zap.Logger)

Source from the content-addressed store, hash-verified

31
32// syncClaudeCodeCreds syncs credentials from Claude Code (~/.claude/).
33func syncClaudeCodeCreds(logger *zap.Logger) bool {
34 home, err := os.UserHomeDir()
35 if err != nil {
36 return false
37 }
38
39 // Try multiple known locations
40 paths := []string{
41 filepath.Join(home, ".claude", "credentials.json"),
42 filepath.Join(home, ".claude.json"),
43 }
44
45 for _, path := range paths {
46 data, err := os.ReadFile(path) //#nosec G304 -- path supplied by user/agent through validated tool surface (boundary check upstream)
47 if err != nil {
48 continue
49 }
50
51 cred := parseClaudeCredentials(data, logger)
52 if cred == nil {
53 continue
54 }
55
56 // Check if we already have fresher credentials
57 store := LoadStore(logger)
58 existing := store.Profiles["anthropic-oauth-sync"]
59 if existing != nil && existing.Expires > cred.Expires {
60 logger.Debug(i18n.T("auth.sync.anthropic_newer"))
61 return false
62 }
63
64 if err := UpsertProfile("anthropic-oauth-sync", cred, logger); err != nil {
65 logger.Warn(i18n.T("auth.sync.anthropic_save_failed"), zap.Error(err))
66 return false
67 }
68
69 logger.Info(i18n.T("auth.sync.anthropic_synced"),
70 zap.String("source", path))
71 return true
72 }
73
74 return false
75}
76
77// syncCodexCliCreds syncs credentials from OpenAI Codex CLI (~/.codex/).
78func syncCodexCliCreds(logger *zap.Logger) bool {

Callers 1

SyncExternalCliCredsFunction · 0.85

Calls 8

TFunction · 0.92
parseClaudeCredentialsFunction · 0.85
LoadStoreFunction · 0.85
UpsertProfileFunction · 0.85
WarnMethod · 0.80
ErrorMethod · 0.65
InfoMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected