If you've been following the AI space lately, you've likely seen Claude Code. It's Anthropic's agentic coding tool that reads your codebase, edits files, runs commands, and integrates with your development tools. Available in your terminal, IDE, desktop app, and browser. This guide focuses on the CLI experience.
While the default setup uses the Anthropic API directly, those of us in the AWS ecosystem often prefer Amazon Bedrock. It offers better security, compliance, and unified billing. I wanted to put together a guide on how to get this running with the latest frontier models and the newest AWS authentication flows.
Why Bedrock?
- Data Perimeter: Your code and prompts stay within your AWS environment
- IAM Governance: You can use the same roles and policies you use for the rest of your stack
- No Extra Subscriptions: It just shows up on your AWS bill
Step 1: The Prerequisites
Before we touch the cloud configuration, make sure you have the basics on your machine.
- Node.js: You'll need this to install the tool
- AWS CLI: Installed and updated. Version 2.32+ is required for the newest auth features
- Model Access: Good news—AWS has simplified this. Bedrock models are now automatically enabled when you first invoke them in your account. For Anthropic models specifically, first-time users may need to submit use case details before access is granted, but this happens seamlessly during your first invocation. Note:
us-east-1andus-west-2typically have the earliest access to new models and the best availability
Now, install the CLI. You have several options:
Native Install (Recommended - auto-updates)
# macOS/Linux/WSL
curl -fsSL https://claude.ai/install.sh | bash
# Windows PowerShell
irm https://claude.ai/install.ps1 | iex
Package Managers
# Homebrew
brew install --cask claude-code
# WinGet (Windows)
winget install Anthropic.ClaudeCode
NPM Install
npm install -g @anthropic-ai/claude-code
Step 2: Authentication to your AWS account
Claude Code doesn't use a separate login for Bedrock. It uses your AWS authentication. Use the method that fits your workflow.
Option A: The Modern Flow (Easiest for local dev)
The aws login command is the new standard. It opens a browser, you sign in, and it handles the temporary tokens for you.
aws login
Option B: IAM Identity Center (SSO)
If you're in a corporate environment with Single Sign-On:
aws sso login --profile your-profile-name
export AWS_PROFILE=your-profile-name
Option C: Traditional Access Keys
If you rely on long-term keys in your credentials file, Claude Code will pick them up automatically via your default profile.
Option D: Bedrock API Keys (Simplest)
Bedrock API keys provide a simpler authentication method without needing full AWS credentials. Just set the bearer token:
export AWS_BEARER_TOKEN_BEDROCK=your-bedrock-api-key
This is ideal for developers who want Bedrock access without managing AWS IAM credentials. Learn more about Bedrock API keys.
Step 3: Enable Bedrock Mode
This is the critical part. You need to tell Claude Code to stop looking for an Anthropic API key and start talking to Bedrock.
Add this to your .zshrc or .bashrc or set each time before launching Claude Code:
# Enable Bedrock mode
export CLAUDE_CODE_USE_BEDROCK=1
# Optional: Set your region if needed (defaults to your AWS CLI region)
export AWS_REGION=us-east-1
That's it for the required configuration. Claude Code will automatically use sensible model defaults (Sonnet 4.5 for primary work, Haiku for fast operations).
Step 4: Launching the Agent
One point of confusion is the login command. When using Bedrock, you skip claude login. That command is only for Anthropic's managed service.
Since you're authenticated via AWS, navigate to your project folder and just run:
claude
The first time you run it, Claude will ask for permission to access your tools and files. Once you say yes, you're ready to start. You can ask it to "Explain this project," "Run the tests and fix what fails," or "Refactor this component."
What to Expect: Response Times on Bedrock
When using Claude Code through Bedrock, expect slightly higher latency compared to the Anthropic API due to the additional network hops through AWS infrastructure. Typical response times range from 2-5 seconds for simple queries with Sonnet, and 5-15 seconds for complex multi-step operations. The streaming responses help make this feel faster, as you'll see output start to appear within the first second or two.
Step 5: Choosing Your Model (Optional)
Now that you're running Claude Code, you can switch models anytime using the built-in model selector:
/model
This opens an interactive menu where you can choose:
- Default (Sonnet 4.5) - Recommended. The "Goldilocks" model that balances high capability with reasonable cost and latency
- Opus 4.6 - Most capable for complex work. Higher costs and longer response times, but maximum reasoning power
- Opus (1M context) - Opus 4.6 optimized for long sessions with large codebases
- Haiku 4.5 - Fastest for quick answers. Very cheap, but less capable for complex reasoning
- Opus 4.1 - Legacy model (generally not recommended over 4.6)
Your selection persists across sessions, so you only need to set it once.
Advanced: Setting Models via Environment Variables
If you prefer programmatic control (for automation or scripts), you can set models via environment variables:
# Choose your models
export ANTHROPIC_MODEL='us.anthropic.claude-sonnet-4-5-20250929-v1:0'
export ANTHROPIC_SMALL_FAST_MODEL='us.anthropic.claude-haiku-4-5-20251001-v1:0'
# Alternative primary models (uncomment to use):
# export ANTHROPIC_MODEL='us.anthropic.claude-opus-4-5-20251101-v1:0' # Higher capability
# export ANTHROPIC_MODEL='us.anthropic.claude-opus-4-6-v1' # Latest flagship
# Optional: If you need to disable prompt caching for testing
# export DISABLE_PROMPT_CACHING=1
Cost Optimization and Monitoring
Running agentic workflows can rack up token usage quickly, especially during exploratory sessions. Here's how to keep your Bedrock costs predictable.
Understanding Your Token Economics
Pricing varies by region, so check the AWS Bedrock pricing page for exact costs in your region. As a general reference:
- Sonnet (Primary Model): Approximately $3 per million input tokens, $15 per million output tokens
- Haiku (Fast Model): Approximately $0.25 per million input tokens, $1.25 per million output tokens
- Prompt Caching: Can reduce costs by up to 90% on repeated context. Enabled by default, but you can disable it with
DISABLE_PROMPT_CACHING=1if you're troubleshooting
Cost-Saving Strategies
Start with smaller contexts: Don't point Claude at your entire monorepo on day one. Begin with a single module or service. You can always expand the scope once you understand the token patterns.
Use .claudeignore: Similar to .gitignore, this file tells Claude Code which directories to skip. Exclude node_modules, build artifacts, and large data files that aren't relevant to your coding tasks.
Example .claudeignore file:
# Dependencies
node_modules/
vendor/
# Build outputs
dist/
build/
*.pyc
__pycache__/
# Large data files
*.log
*.csv
*.parquet
data/
# Environment and secrets
.env
.env.local
secrets/
# Test coverage
coverage/
.nyc_output/
Monitor with CloudWatch: Set up a CloudWatch dashboard to track your Bedrock invocations. Create alarms for unexpected spikes (this is especially useful if multiple team members are using the same AWS account).
Tracking Your Usage
Check your Bedrock usage in the AWS Console under Billing > Cost Explorer. Filter by service (Amazon Bedrock) and add a dimension for model ID to see which model is driving your costs.
For real-time monitoring during development, you can enable verbose logging:
export CLAUDE_CODE_DEBUG=1
This shows token counts for each request, helping you understand which operations are most expensive.
Troubleshooting Tips
- "Model Not Found" or Access Denied: First, double-check your
AWS_REGIONmatches where you're trying to use the model. If you're a first-time Anthropic model user, you may need to submit use case details through the Bedrock console. AWS will prompt you for this on your first invocation. After submission, access is typically granted within minutes. - Permissions: Ensure your IAM user or role has
bedrock:InvokeModelandbedrock:InvokeModelWithResponseStream. Without the streaming permission, the CLI will feel like it's frozen while it waits for the full response
Conclusion
Going from zero to an agentic coding workflow on AWS is now surprisingly simple. You get the power of Claude 4.5/4.6 with the enterprise-grade security of Bedrock.
Additional Resources
- Claude Code Documentation
- Amazon Bedrock Documentation
- Bedrock Model Access Guide
- AWS CLI v2 Installation
How are you planning to use Claude Code? Let me know in the comments!
Top comments (0)