Skip to content

consult: workspace .env silently overrides the Claude lane's credentials (no log line); surfaces as 'org monthly usage limit' with no review #1754

Closed

Description

@waleedkadous

Problem

consult -m claude --type integration --issue N failed 4 of 4 times in an adopter workspace. Right after [CLAUDE] model: claude-opus-5 the only output was You have hit your org monthly usage limit, and no review text was produced. Yet on the same machine and login, all of these worked: plain claude -p, a raw Agent SDK query() (including an 83 KB prompt, maxBudgetUsd, bypassPermissions, tools), and a node one-liner importing runClaudeConsultation() from dist/commands/consult/index.js with the identical prompt, role, workspaceRoot and model choice.

Root cause

The CLI entry (runConsultation, packages/codev/src/commands/consult/index.ts:2396) calls loadDotenv(workspaceRoot), which copies every key from <workspaceRoot>/.env into process.env when the shell does not already define it. The direct import, claude -p and raw query() never read that file.

The adopter's .env defines CLAUDE_CODE_OAUTH_TOKEN and ANTHROPIC_API_KEY. Once the OAuth token is injected, buildClaudeConsultEnv (issue #985 behaviour) strips the API key, and the SDK subprocess authenticates as the org that token belongs to, which had exhausted its monthly usage. The keychain login that every other path uses was fine. Nothing is logged about the .env load or which credential the lane will use, so the failure is indistinguishable from a real account limit.

Verified by reading .env key names in the affected workspace (values not inspected).

Fix (prescribed)

  1. Before dispatching the claude lane, log the credential source on stderr in the same style as the model line, e.g. [CLAUDE] auth: CLAUDE_CODE_OAUTH_TOKEN (from .env) / (from shell) / keychain login. Mirror for the codex lane if it reads .env keys too.
  2. When the assistant text of a consultation matches a usage-limit / out-of-usage reply and no review body follows, exit non-zero and do not write the output file. Today the run "succeeds" with the limit message as its output.
  3. Consider whether loadDotenv should inject credential variables at all. At minimum, document in the consult skill that <workspace>/.env credentials take effect for consult and override the keychain login.

Protocol: BUGFIX. Keep .env loading for non-credential keys unchanged unless the builder finds no consumer.

Testing

  • Unit: loadDotenv + buildClaudeConsultEnv with a fixture .env containing CLAUDE_CODE_OAUTH_TOKEN; assert the auth log line names .env as the origin.
  • Unit: a stubbed SDK stream whose only assistant text is an out-of-usage message yields exit 1 and no output file.
  • Manual: in a workspace whose .env carries an OAuth token for an exhausted org, consult -m claude must name the credential source and fail loudly instead of printing the limit text as a review.

Activity

  1. added
    area/consult
    on Sep 29, 2026
  2. waleedkadous commented on Sep 29, 2026

    @waleedkadous
    ContributorAuthor

    On it! Working on a fix now.

  3. added 6 commits that reference this issue on Sep 29, 2026
    aed7475
    86331e4
    1fda5d9
    3843517
    c8441cf
    a2bddf8
  4. added a commit that references this issue on Oct 1, 2026
    1caf6ce
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/consult

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions