Skip to main content

sync_auth/providers/
claude.rs

1//! Claude Code auth provider.
2
3use crate::{AuthProvider, CredentialFile, ValidationResult};
4use std::path::PathBuf;
5
6/// Provider for Claude Code credentials.
7///
8/// Syncs `~/.claude/` directory and `~/.claude.json` config file.
9#[derive(Debug, Clone, Default)]
10pub struct ClaudeProvider;
11
12#[async_trait::async_trait]
13impl AuthProvider for ClaudeProvider {
14    fn name(&self) -> &str {
15        "claude"
16    }
17
18    fn display_name(&self) -> &str {
19        "Claude Code"
20    }
21
22    fn credential_files(&self) -> Vec<CredentialFile> {
23        let home = dirs::home_dir().unwrap_or_else(|| PathBuf::from("~"));
24        vec![
25            CredentialFile {
26                relative_path: "claude/dot-claude".to_string(),
27                local_path: home.join(".claude"),
28                is_dir: true,
29            },
30            CredentialFile {
31                relative_path: "claude/claude.json".to_string(),
32                local_path: home.join(".claude.json"),
33                is_dir: false,
34            },
35        ]
36    }
37
38    async fn validate(&self) -> ValidationResult {
39        let home = dirs::home_dir().unwrap_or_else(|| PathBuf::from("~"));
40        let config = home.join(".claude.json");
41        if config.exists() {
42            ValidationResult::Valid
43        } else {
44            ValidationResult::Missing
45        }
46    }
47}