Skip to content

Claude Code ignores AWS_REGION when using Bedrock #48371

Description

@chuckgit123

Reproduction steps

When using "External Agent: Claude Code" with AWS Bedrock, the AWS_REGION environment variable is not being passed to the Bedrock API calls, resulting in an empty region in the ARN and authorization failures.

Error Message:

User: arn:aws:sts::092106541079:assumed-role/role/user@example.com is not authorized to perform: bedrock:InvokeModelWithResponseStream on resource:arn:aws:bedrock:::foundation-model/anthropic.claude-sonnet-4-5-20250929-v1:0 because no identity-based policy allows the bedrock:InvokeModelWithResponseStream action

Note the empty region in arn:aws:bedrock:::foundation-model/... - it should be arn:aws:bedrock:us-east-1::foundation-model/...`

IAM Policy: Our AWS policy allows Bedrock access only for us-* regions:

{
"Action": ["bedrock:InvokeModelWithResponseStream", "bedrock:InvokeModel"],
"Effect": "Allow",
"Resource": ["arn:aws:bedrock:us-*::foundation-model/anthropic.claude-*", ...]
}

What I've tried (all gives the same error):

  1. Zed agent_servers env config:
{
	"agent_servers": {
	  "claude": {
		"env": {
		  "CLAUDE_CODE_USE_BEDROCK": "1",
		  "AWS_REGION": "us-east-1",
		  "AWS_PROFILE": "p",
		  "ANTHROPIC_MODEL": "us.anthropic.claude-opus-4-5-20251101-v1:0"
		}
	  }
	}
}
  1. Starting Zed from terminal with env vars:
    CLAUDE_CODE_USE_BEDROCK=1 AWS_REGION=us-east-1 AWS_PROFILE=p /Applications/Zed.app/Contents/MacOS/zed

  2. Claude Code settings.json (~/.claude/settings.json):

{
	"env": {
	  "CLAUDE_CODE_USE_BEDROCK": "1",
	  "AWS_REGION": "us-east-1",
	  "AWS_PROFILE": "p",
	  "ANTHROPIC_MODEL": "us.anthropic.claude-opus-4-5-20251101-v1:0"
	}
}
  1. Wrapper script with CLAUDE_CODE_EXECUTABLE:
#!/bin/bash
export CLAUDE_CODE_USE_BEDROCK=1
export AWS_REGION=us-east-1
export AWS_PROFILE=p
export ANTHROPIC_MODEL="us.anthropic.claude-opus-4-5-20251101-v1:0"
exec claude "$@"

with Zed config:

{
	"agent_servers": {
	  "claude": {
		"env": {
		  "CLAUDE_CODE_EXECUTABLE": "/Users/user/.local/bin/claude-bedrock"
		}
	  }
	}
}

The wrapper script IS being called (confirmed via debug logging), but the error persists with empty region.

  1. AWS profile with region set:
[profile p]
region = us-east-1

Important observation:

  • Running claude directly from terminal with these env vars works correctly
  • The wrapper script works correctly when called directly
  • It fails only when invoked through Zed's External Agent integration
  • The error also shows claude-sonnet-4-5 even though ANTHROPIC_MODEL is set to claude-opus-4-5, suggesting env vars are completely ignored

Debug log from wrapper script shows Zed's invocation:

ARGS: --output-format stream-json --verbose --input-format stream-json --permission-prompt-tool stdio --allowedTools
mcp__acp__Read,mcp__acp__BashOutput,mcp__acp__KillShell --disallowedTools AskUserQuestion,Read,Write,Edit,Bash,BashOutput,KillShell --tools default --mcp-config
{"mcpServers":{"acp":{"type":"sdk","name":"acp"}}} --setting-sources user,project,local --permission-mode default --allow-dangerously-skip-permissions
--include-partial-messages --session-id ...

Current vs. Expected behavior

Expected behavior:

Environment variables (AWS_REGION, ANTHROPIC_MODEL, etc.) should be respected when Claude Code is invoked as an External Agent.

Actual behavior:

Environment variables are ignored. The region is empty in API calls and the wrong model is used.

Zed version and system specs

  • Zed Version: 0.221.5
  • OS: macOS (Darwin 25.2.0)
  • Claude Code: /opt/homebrew/bin/claude (installed via Homebrew)

Attach Zed log file

Zed.log

Relevant Zed settings

settings.json

Relevant Keymap

keymap.json

(for AI issues) Model provider details

No response

If you are using WSL on Windows, what flavor of Linux are you using?

None

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:ai/bedrockAI feedback for Amazon's Bedrockarea:integrations/environmentEnvironment variables, direnv, asdf, etcreach:many usersBugs that happen for at least a third of the users across all platforms and kinds of usage

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions