fix(dispatch): load user settings so API-key auth works in --local · Entire
fix(dispatch): load user settings so API-key auth works in --local
f457d27→main·
alishakawaguchi·yesterday·2 files·+48 added/-1 removed
`entire dispatch --local` shells out to the claude CLI with `--setting-sources ""`, which tells claude to load none of the user, project, or local setting sources. API-billing users configure auth in their user settings (apiKeyHelper, or the ANTHROPIC_API_KEY approval in customApiKeyResponses), so dropping all sources dropped their auth and claude reported "Not logged in · Please run /login" — even though their plain `claude -p` worked.
Switch to `--setting-sources user`, which loads the user's ~/.claude/settings.json (restoring auth) while still excluding project and local settings. The subprocess already runs in os.TempDir(), so project/local isolation is preserved regardless. Subscription and raw ANTHROPIC_API_KEY env-var users were unaffected either way.
Co-Authored-By: Claude Opus 4.8 (1M context) noreply@anthropic.com Claude-Session: https://claude.ai/code/session_012QYA1kFFwDTbR8cZQQkb8N
Changes
2
cmd/entire/cli/agent/claudecode
Mclaude_test.go+35
Mgenerate.go+13/-1
55 unmodified lines
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
55 unmodified lines
\t}
}\n
func TestGenerateText_LoadsUserSettingsForAuth(t *testing.T) {
\tt.Parallel()
\tvar gotArgs []string
\tag := &ClaudeCodeAgent{
\t\tCommandRunner: func(ctx context.Context, _ string, args ...string) *exec.Cmd {
\t\t\tgotArgs = args
\t\t\treturn exec.CommandContext(ctx, "sh", "-c", `printf '%s' '{"type":"result","result":"ok"}'`)
\t\t},
\t}
\tif _, err := ag.GenerateText(context.Background(), "prompt", ""); err != nil {
\t\tt.Fatalf("unexpected error: %v", err)
\t}
\t// The subprocess must load user settings so API-billing auth (apiKeyHelper /
\t// ANTHROPIC_API_KEY approval in ~/.claude/settings.json) is available.
\t// Loading no sources ("") made claude report "Not logged in" for those users.
\t// See generate.go for the full rationale.
\tvar settingSources string
\tfound := false
\tfor i, a := range gotArgs {
\t\tif a == "--setting-sources" && i+1 < len(gotArgs) {
\t\t\tsettingSources = gotArgs[i+1]
\t\t\tfound = true
\t\t\tbreak
\t\t}
\t}
\tif !found {
\t\tt.Fatalf("--setting-sources flag missing from args: %v", gotArgs)
\t}
\tif settingSources != settingSourcesUser {
\t\tt.Fatalf("--setting-sources = %q, want %q (empty drops user auth settings)", settingSources, settingSourcesUser)
\t}
}
func TestGenerateText_ArrayResponse(t *testing.T) {
\tt.Parallel()
\tag := &ClaudeCodeAgent{
Mcmd/entire/cli/agent/claudecode/claude_test.go+35
11 unmodified lines
12
13
14
15
16
17
18
19
20
21
17 unmodified lines
39
40
41
42
43
44
45
46
47
48
49
50
51
40
52
53
54
55
11 unmodified lines
\t"github.com/entireio/cli/cmd/entire/cli/agent"
// settingSourcesUser tells the claude CLI to load only the user's
// ~/.claude/settings.json (see the rationale in GenerateText).
const settingSourcesUser = "user"
// GenerateText sends a prompt to the Claude CLI and returns the raw text response.
// Implements the agent.TextGenerator interface.
// The model parameter hints which model to use (e.g., "haiku", "sonnet").
17 unmodified lines
\t\tcommandRunner = exec.CommandContext
\t}
\t// --setting-sources user loads the user's ~/.claude/settings.json (where
\t// API-billing auth lives: apiKeyHelper and ANTHROPIC_API_KEY approval)
\t// while still excluding project and local settings. Passing "" here loaded
\t// no sources at all, which dropped that auth config and made claude report
\t// "Not logged in" for users authenticating via user settings — even though
\t// their plain `claude -p` worked. Project/local isolation is already
\t// guaranteed by cmd.Dir = os.TempDir() below, so "user" restores auth
\t// without reintroducing repo-scoped settings.
\tcmd := commandRunner(ctx, claudePath,
\t\t"--print", "--output-format", "json",
\t\t"--model", model, "--setting-sources", "")
\t\t"--model", model, "--setting-sources", settingSourcesUser)
\t// Isolate from the user's git repo to prevent recursive hook triggers
\t// and index pollution (matches agent.RunIsolatedTextGeneratorCLI behavior).