This repository was archived by the owner on May 8, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_auto_sync.ps1
More file actions
77 lines (67 loc) · 2.71 KB
/
setup_auto_sync.ps1
File metadata and controls
77 lines (67 loc) · 2.71 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# Setup Windows Task Scheduler for automatic daily sync
# Run this script as Administrator
$TaskName = "ClaudeUsageAutoSync"
$ScriptPath = "$env:USERPROFILE\claude-usage-tracker\scripts\auto_sync.py"
$PythonPath = (Get-Command python).Source
$LogPath = "$env:USERPROFILE\claude-usage-tracker\logs"
# Create logs directory
New-Item -ItemType Directory -Force -Path $LogPath | Out-Null
Write-Host "=" -ForegroundColor Cyan -NoNewline
Write-Host ("=" * 69) -ForegroundColor Cyan
Write-Host "Setting up automatic daily sync for Claude Usage Tracker" -ForegroundColor Cyan
Write-Host "=" -ForegroundColor Cyan -NoNewline
Write-Host ("=" * 69) -ForegroundColor Cyan
Write-Host ""
# Check if task already exists
$ExistingTask = Get-ScheduledTask -TaskName $TaskName -ErrorAction SilentlyContinue
if ($ExistingTask) {
Write-Host "Task already exists. Removing old task..." -ForegroundColor Yellow
Unregister-ScheduledTask -TaskName $TaskName -Confirm:$false
}
# Create action
$Action = New-ScheduledTaskAction `
-Execute $PythonPath `
-Argument $ScriptPath `
-WorkingDirectory "$env:USERPROFILE\claude-usage-tracker"
# Create trigger (daily at 11:59 PM)
$Trigger = New-ScheduledTaskTrigger -Daily -At "23:59"
# Create settings
$Settings = New-ScheduledTaskSettingsSet `
-AllowStartIfOnBatteries `
-DontStopIfGoingOnBatteries `
-StartWhenAvailable `
-RunOnlyIfNetworkAvailable
# Register task
Register-ScheduledTask `
-TaskName $TaskName `
-Action $Action `
-Trigger $Trigger `
-Settings $Settings `
-Description "Automatically sync Claude usage statistics to Git repository" `
-User $env:USERNAME
Write-Host ""
Write-Host "Task created successfully!" -ForegroundColor Green
Write-Host ""
Write-Host "Task Details:" -ForegroundColor Cyan
Write-Host " Name: $TaskName"
Write-Host " Schedule: Daily at 11:59 PM"
Write-Host " Script: $ScriptPath"
Write-Host " Logs: $LogPath"
Write-Host ""
Write-Host "=" -ForegroundColor Cyan -NoNewline
Write-Host ("=" * 69) -ForegroundColor Cyan
Write-Host ""
Write-Host "You can also run the sync manually with:" -ForegroundColor Yellow
Write-Host " ccusage-auto-sync" -ForegroundColor White
Write-Host ""
Write-Host "To check the task status:" -ForegroundColor Yellow
Write-Host " Get-ScheduledTask -TaskName '$TaskName'" -ForegroundColor White
Write-Host ""
Write-Host "To run the task immediately:" -ForegroundColor Yellow
Write-Host " Start-ScheduledTask -TaskName '$TaskName'" -ForegroundColor White
Write-Host ""
Write-Host "To disable the task:" -ForegroundColor Yellow
Write-Host " Disable-ScheduledTask -TaskName '$TaskName'" -ForegroundColor White
Write-Host ""
Write-Host "=" -ForegroundColor Cyan -NoNewline
Write-Host ("=" * 69) -ForegroundColor Cyan