Vectrum
Sign In

evals: -claude-code-auth, for a machine with only a Claude Code login

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Jjonicommitted 1 parent 56bb510commit219352e

Showing 1 changed file with 19 additions and 1 deletion.

+19−1evals/runner.goView File
@@ -21,6 +21,7 @@ import (
2121
2222 "github.com/johannSo/codey/internal/agent"
2323 "github.com/johannSo/codey/internal/approval"
24+ "github.com/johannSo/codey/internal/claudecode"
2425 "github.com/johannSo/codey/internal/llm"
2526 "github.com/johannSo/codey/internal/metrics"
2627 "github.com/johannSo/codey/internal/tools"
@@ -78,6 +79,7 @@ func run() error {
7879 tasksDir := flag.String("dir", "evals/tasks", "directory of task definitions")
7980 outDir := flag.String("out", "evals/runs", "where to persist transcripts")
8081 keep := flag.Bool("keep", false, "keep the temporary work directories")
82+ claudeCodeAuth := flag.Bool("claude-code-auth", false, "with no API key set, borrow the OAuth login in ~/"+claudecode.Filename+" — your own machine only; it is issued to Claude Code")
8183 flag.Parse()
8284
8385 tasks, err := loadTasks(*tasksDir, *only)
@@ -88,8 +90,23 @@ func run() error {
8890 return fmt.Errorf("no tasks found in %s", *tasksDir)
8991 }
9092 client := llm.New(llm.WithModel(*model))
93+ // The identity block an OAuth request from Claude Code's login must carry,
94+ // set only when that is the credential in use; see cmd/codey.
95+ var systemPrefix string
96+ if *claudeCodeAuth && !client.HasCredentials() && client.IsDefaultEndpoint() {
97+ home, err := os.UserHomeDir()
98+ if err != nil {
99+ return err
100+ }
101+ creds, err := claudecode.Load(home)
102+ if err != nil {
103+ return fmt.Errorf("-claude-code-auth: %w", err)
104+ }
105+ client = llm.New(llm.WithModel(*model), llm.WithTokenSource(claudecode.NewSource(creds, nil, home).Token))
106+ systemPrefix = agent.ClaudeCodeIdentity
107+ }
91108 if !client.HasCredentials() {
92- return fmt.Errorf("no credentials: set ANTHROPIC_API_KEY")
109+ return fmt.Errorf("no credentials: set ANTHROPIC_API_KEY, or pass -claude-code-auth")
93110 }
94111
95112 stamp := time.Now().UTC().Format("20060102T150405Z")
@@ -129,6 +146,7 @@ func run() error {
129146 ContextWindow: *contextWindow,
130147 NoCache: *noCache,
131148 Stream: !*noStream,
149+ SystemPrefix: systemPrefix,
132150 }, *timeout, *keep)
133151 mu.Lock()
134152 results = append(results, res)