File size: 719 Bytes
1bf9e0c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import fs from 'fs';
import path from 'path';
import os from 'os';

/**
 * 从 ~/.claude/settings.json 中读取配置
 */
export function getGlobalConfig() {
  // 1. 定位路径: /home/yuki/.claude/settings.json
  // 使用 os.homedir() 保证跨平台兼容性
  const configPath = path.join(os.homedir(), '.claude', 'settings.json');

  try {
    // 2. 读取文件内容
    const fileContent = fs.readFileSync(configPath, 'utf-8');
    
    // 3. 解析 JSON
    const config = JSON.parse(fileContent);
    
    // 4. 返回 env 对象中的 JINA_API_KEY
    return config?.env?.JINA_API_KEY || null;
  } catch (error) {
    console.error(`无法读取配置文件: ${configPath}`, error);
    return null;
  }
}