Skip to content

Commit 4f2002c

Browse files
declan-scaleclaude
andcommitted
fix(cli): drain claude stdin and stop env from shadowing the API key
Round-4 Greptile review: - await proc.stdin.drain() before close() in all three claude-code subprocess helpers (matches the codex helpers; flushes large prompts before EOF). - Stop the manifest env block from setting ANTHROPIC_API_KEY to an empty string, which would shadow the credential mapping / .env value at runtime. The key now comes solely from the credential mapping (deploy) or .env (local). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 378de92 commit 4f2002c

6 files changed

Lines changed: 18 additions & 11 deletions

File tree

src/agentex/lib/cli/templates/default-claude-code/manifest.yaml.j2

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,11 @@ agent:
8989
secret_key: url
9090

9191
# Optional: Set Environment variables for running your agent locally as well
92-
# as for deployment later on
93-
env:
94-
ANTHROPIC_API_KEY: "" # Required by the Claude Code CLI
92+
# as for deployment later on. ANTHROPIC_API_KEY is supplied via the credential
93+
# mapping above (deploy) or your local .env (load_dotenv). Do NOT set it to an
94+
# empty string here — that would shadow the real key at runtime.
95+
env: {}
96+
# ANTHROPIC_API_KEY: "<your-key>" # uncomment only to hardcode for local runs
9597

9698
# Deployment Configuration
9799
# -----------------------

src/agentex/lib/cli/templates/default-claude-code/project/acp.py.j2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ async def _spawn_claude(prompt: str) -> AsyncIterator[str]:
6666
assert proc.stdin is not None
6767

6868
proc.stdin.write(prompt.encode())
69+
await proc.stdin.drain()
6970
proc.stdin.close()
7071

7172
# Drain stderr concurrently. With --verbose, Claude Code can write enough to

src/agentex/lib/cli/templates/sync-claude-code/manifest.yaml.j2

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,11 @@ agent:
8585
secret_key: api-key
8686

8787
# Optional: Set Environment variables for running your agent locally as well
88-
# as for deployment later on
89-
env:
90-
ANTHROPIC_API_KEY: "" # Required by the Claude Code CLI
88+
# as for deployment later on. ANTHROPIC_API_KEY is supplied via the credential
89+
# mapping above (deploy) or your local .env (load_dotenv). Do NOT set it to an
90+
# empty string here — that would shadow the real key at runtime.
91+
env: {}
92+
# ANTHROPIC_API_KEY: "<your-key>" # uncomment only to hardcode for local runs
9193

9294

9395
# Deployment Configuration

src/agentex/lib/cli/templates/sync-claude-code/project/acp.py.j2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ async def _spawn_claude(prompt: str) -> AsyncIterator[str]:
6565
assert proc.stdin is not None
6666

6767
proc.stdin.write(prompt.encode())
68+
await proc.stdin.drain()
6869
proc.stdin.close()
6970

7071
# Drain stderr concurrently. With --verbose, Claude Code can write enough to

src/agentex/lib/cli/templates/temporal-claude-code/manifest.yaml.j2

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,11 @@ agent:
107107
secret_key: api-key
108108

109109
# Optional: Set Environment variables for running your agent locally as well
110-
# as for deployment later on
111-
env:
112-
ANTHROPIC_API_KEY: "" # Required by the Claude Code CLI
113-
# OPENAI_BASE_URL: "<YOUR_OPENAI_BASE_URL_HERE>"
114-
# OPENAI_ORG_ID: "<YOUR_OPENAI_ORG_ID_HERE>"
110+
# as for deployment later on. ANTHROPIC_API_KEY is supplied via the credential
111+
# mapping above (deploy) or your local .env (load_dotenv). Do NOT set it to an
112+
# empty string here — that would shadow the real key at runtime.
113+
env: {}
114+
# ANTHROPIC_API_KEY: "<your-key>" # uncomment only to hardcode for local runs
115115

116116

117117
# Deployment Configuration

src/agentex/lib/cli/templates/temporal-claude-code/project/activities.py.j2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ async def _spawn_claude(prompt: str, session_id: str | None = None) -> AsyncIter
7878
assert proc.stdin is not None
7979

8080
proc.stdin.write(prompt.encode())
81+
await proc.stdin.drain()
8182
proc.stdin.close()
8283

8384
# Drain stderr concurrently. With --verbose, Claude Code can write enough to

0 commit comments

Comments
 (0)