Prerequisites
Before configuring Claude Code with Bedrock, ensure you have:- An AWS account with Bedrock access enabled
- Access to desired Claude models (for example, Claude Sonnet 4.6) in Bedrock
- AWS CLI installed and configured (optional - only needed if you don’t have another mechanism for getting credentials)
- Appropriate IAM permissions
If you are deploying Claude Code to multiple users, pin your model versions to prevent breakage when Anthropic releases new models.
Setup
1. Submit use case details
First-time users of Anthropic models are required to submit use case details before invoking a model. This is done once per account.- Ensure you have the right IAM permissions (see more on that below)
- Navigate to the Amazon Bedrock console
- Select Chat/Text playground
- Choose any Anthropic model and you will be prompted to fill out the use case form
2. Configure AWS credentials
Claude Code uses the default AWS SDK credential chain. Set up your credentials using one of these methods: Option A: AWS CLI configurationaws login.
Option E: Bedrock API keys
Advanced credential configuration
Claude Code supports automatic credential refresh for AWS SSO and corporate identity providers. Add these settings to your Claude Code settings file (see Settings for file locations). When Claude Code detects that your AWS credentials are expired (either locally based on their timestamp or when Bedrock returns a credential error), it will automatically run your configuredawsAuthRefresh and/or awsCredentialExport commands to obtain new credentials before retrying the request.
Example configuration
Configuration settings explained
awsAuthRefresh: Use this for commands that modify the .aws directory, such as updating credentials, SSO cache, or config files. The command’s output is displayed to the user, but interactive input isn’t supported. This works well for browser-based SSO flows where the CLI displays a URL or code and you complete authentication in the browser.
awsCredentialExport: Only use this if you can’t modify .aws and must directly return credentials. Output is captured silently and not shown to the user. The command must output JSON in this format:
3. Configure Claude Code
Set the following environment variables to enable Bedrock:AWS_REGIONis a required environment variable. Claude Code does not read from the.awsconfig file for this setting.- When using Bedrock, the
/loginand/logoutcommands are disabled since authentication is handled through AWS credentials. - You can use settings files for environment variables like
AWS_PROFILEthat you don’t want to leak to other processes. See Settings for more information.
4. Pin model versions
Set these environment variables to specific Bedrock model IDs:us. prefix). If you use a different region prefix or application inference profiles, adjust accordingly. For current and legacy model IDs, see Models overview. See Model configuration for the full list of environment variables.
Claude Code uses these default models when no pinning variables are set:
| Model type | Default value |
|---|---|
| Primary model | us.anthropic.claude-sonnet-4-5-20250929-v1:0 |
| Small/fast model | us.anthropic.claude-haiku-4-5-20251001-v1:0 |
Prompt caching may not be available in all regions.
Map each model version to an inference profile
TheANTHROPIC_DEFAULT_*_MODEL environment variables configure one inference profile per model family. If your organization needs to expose several versions of the same family in the /model picker, each routed to its own application inference profile ARN, use the modelOverrides setting in your settings file instead.
This example maps three Opus versions to distinct ARNs so users can switch between them without bypassing your organization’s inference profiles:
/model, Claude Code calls Bedrock with the mapped ARN. Versions without an override fall back to the built-in Bedrock model ID or any matching inference profile discovered at startup. See Override model IDs per version for details on how overrides interact with availableModels and other model settings.
IAM configuration
Create an IAM policy with the required permissions for Claude Code:Create a dedicated AWS account for Claude Code to simplify cost tracking and access control.
1M token context window
Claude Opus 4.6 and Sonnet 4.6 support the 1M token context window on Amazon Bedrock. Claude Code automatically enables the extended context window when you select a 1M model variant. To enable the 1M context window for your pinned model, append[1m] to the model ID. See Pin models for third-party deployments for details.
AWS Guardrails
Amazon Bedrock Guardrails let you implement content filtering for Claude Code. Create a Guardrail in the Amazon Bedrock console, publish a version, then add the Guardrail headers to your settings file. Enable Cross-Region inference on your Guardrail if you’re using cross-region inference profiles. Example configuration:Troubleshooting
Authentication loop with SSO and corporate proxies
If browser tabs spawn repeatedly when using AWS SSO, remove theawsAuthRefresh setting from your settings file. This can occur when corporate VPNs or TLS inspection proxies interrupt the SSO browser flow. Claude Code treats the interrupted connection as an authentication failure, re-runs awsAuthRefresh, and loops indefinitely.
If your network environment interferes with automatic browser-based SSO flows, use aws sso login manually before starting Claude Code instead of relying on awsAuthRefresh.
Region issues
If you encounter region issues:- Check model availability:
aws bedrock list-inference-profiles --region your-region - Switch to a supported region:
export AWS_REGION=us-east-1 - Consider using inference profiles for cross-region access
- Specify the model as an inference profile ID