
Claude Code on Amazon Bedrock: Quick Setup Guide
Configure Anthropic's AI Coding Assistant with AWS Bedrock
Series: Claude Code on Amazon Bedrock (1 article)
- 1Claude Code on Amazon Bedrock: Quick Setup Guide This article
Hello AWS Community!
I'm excited to share how you can use Claude Code—Anthropic's agentic coding tool—directly with Amazon Bedrock, powered by the new Claude 4 series of models. Claude Code integrates into your terminal, understands your codebase, and assists with coding tasks through natural language commands.
What is Claude Code?
What is Claude Code? Claude Code is a powerful AI coding assistant that works both in your terminal and directly integrated with popular IDEs:
- IDE Integration: Seamlessly integrates with VS Code, Cursor, Windsurf, and JetBrains IDEs (PyCharm, WebStorm, IntelliJ, GoLand)
- Quick Access: Launch with Cmd+Esc (Mac) or Ctrl+Esc (Windows/Linux) directly from your editor
- Smart Context: Automatically shares your current selection, open tabs, and diagnostic errors with Claude
- Visual Diffs: View and apply code changes directly in your IDE's diff viewer
- Core Capabilities: Edits files, fixes bugs, answers architecture questions, executes tests, resolves merge conflicts, and more
For detailed VS Code setup instructions, see Setting up Claude Code in VS Code .
Claude Code Models
Claude Code requires access to both a primary model and Claude 3.5 Haiku:
- Primary model: Any Claude 3.7+ or Claude 4 model (Sonnet or Opus) that handles complex code understanding, generation, and reasoning tasks
- Claude 3.7 Sonnet or higher recommended for optimal performance
- Claude 4 models provide enhanced capabilities
- Opus models offer the most powerful processing for complex challenges
- Claude 3.5 Haiku: A lightweight model used for background functionality within Claude Code:
- Generates small creative messages that appear while you type
- Powers conversation summarization for the
claude --resumefeature - Handles various background processes with minimal token usage
- Typically consumes under $0.04 per session for these background tasks
This dual-model approach optimizes both performance and cost - using the lightweight Haiku model where appropriate helps reduce overall token consumption while maintaining responsiveness.
⚠️ IMPORTANT ⚠️: You must explicitly enable access to both model types in your AWS Bedrock Model Access settings for the region you're using: (1) Primary model - Any Claude 3.7+ or Claude 4 model (Sonnet or Opus), and (2) Claude 3.5 Haiku - Required for background functionality. Failure to enable both a primary model AND Haiku will result in 403 Forbidden errors when using Claude Code. 🔑 🚫
See the AWS Bedrock Getting Started Guide for instructions on enabling model access.
Benefits of Using Claude Code with Amazon Bedrock
- Leverage your existing AWS Bedrock allocation and billing
- Access to Claude 4 Opus and Sonnet's advanced coding capabilities
- Keep your code interactions within your AWS infrastructure
- Maintain consistent security and compliance standards
- Use of prompt caching for cost optimization (learn more about Claude Code prompt caching on Bedrock )
Before you begin
Check system requirements
- Operating Systems: macOS 10.15+, Ubuntu 20.04+/Debian 10+, or Windows via WSL
- Hardware: 4GB RAM minimum
- Software:
- Node.js 18+
- git 2.23+ (optional)
- GitHub or GitLab CLI for PR workflows (optional)
- ripgrep (rg) for enhanced file search (optional)
- Network: Internet connection required for authentication and AI processing
AWS Credentials Setup
Before getting started, ensure that your AWS credentials are properly configured. Claude Code will use these credentials to access Amazon Bedrock.
For detailed instructions on configuring AWS credentials, see:
https://docs.aws.amazon.com/cli/v1/userguide/cli-chap-configure.html
https://docs.aws.amazon.com/cli/v1/userguide/cli-chap-configure.html
Quick AWS Credential Setup:
- Using AWS CLI (easiest method):
- Run
aws configure - Enter your access key, secret key, default region (ensure you have Bedrock access in that region), and set output to json.
- Run
- Manual Configuration:
- Create credential files in
~/.aws/credentialsand~/.aws/config
- Create credential files in
Remember, your IAM role/user must have permissions to access Amazon Bedrock and specifically the Claude models you're trying to use (your chosen Claude 3.7+ or Claude 4 primary model and Claude 3.5 Haiku).
Setting up Claude Code with Amazon Bedrock
Install Claude Code
1
npm install -g @anthropic-ai/claude-codeConfigure for Bedrock
1
export CLAUDE_CODE_USE_BEDROCK=1Choose your primary model (pick ONE):
Option 1: Claude Opus 4 (most powerful - best for complex challenges)
1
export ANTHROPIC_MODEL='us.anthropic.claude-opus-4-20250514-v1:0'Option 2: Claude Sonnet 4 (recommended - great balance of speed and capability)
1
export ANTHROPIC_MODEL='us.anthropic.claude-sonnet-4-20250514-v1:0'Option 3: Claude Sonnet 3.7 (previous generation)
1
export ANTHROPIC_MODEL='us.anthropic.claude-3-7-sonnet-20250219-v1:0'Launch Claude Code
1
bashHelp! I'm Getting Throttled with Only One Claude Code User when using the Claude 4 models!
If you're using Claude Code with Amazon Bedrock and seeing 429 errors even though you're the only user, or are seeing excessive throttling among a group of users using the same AWS account, this section explains why and how to fix it.
The Hidden Default Problem
Claude Code's default
max_tokens setting can be as high as 32,000-64,000 tokens. Combined with Claude 4's 5x output token burndown rate , this creates an immediate quota crisis:Default Scenario: Claude Code with default settings
- Default max_tokens: ~32,000
- Quota reserved: 32,000 × 5 = 160,000 tokens
- With 200k TPM limit: 80% of your quota locked for ONE request
- Result: Immediate throttling for any concurrent users
Recommended Configuration
Set these environment variables before running Claude Code:
1
2
3
# Recommended starting point for Claude 4 models on Bedrock
export CLAUDE_CODE_MAX_OUTPUT_TOKENS=4096
export MAX_THINKING_TOKENS=1024Real-World Example
Here's what happens with and without configuration:
Without Configuration (Default):
1
2
3
4
5
6
7
8
# Running Claude Code normally
claude "Fix the bug in my authentication system"
# Behind the scenes:
# - Max tokens: 32,000 (default)
# - Quota reserved: 160,000 tokens
# - Your 200k quota: Nearly exhausted
# - Other team members: Get 429 errorsWith Configuration:
1
2
3
4
5
6
7
8
9
10
11
# Set the environment variable first
export CLAUDE_CODE_MAX_OUTPUT_TOKENS=4096
# Now run Claude Code
claude "Fix the bug in my authentication system"
# Behind the scenes:
# - Max tokens: 4,096 (configured)
# - Quota reserved: 20,480 tokens
# - Your 200k quota: 90% still available
# - Other team members: Can work concurrentlyManaging Extended Thinking
Claude 4 models support extended thinking, which can consume significant tokens. Control this with:
1
2
# Limit thinking tokens to prevent runaway quota usage
export MAX_THINKING_TOKENS=1024This ensures that even with complex reasoning tasks, your quota usage remains predictable.
Why This Matters
Based on benchmarking data, Claude Code's average output is only ~300 tokens for typical software engineering tasks. The high default
max_tokens value reserves quota you'll never use, blocking your entire team unnecessarily.Quick Math:
- Typical Claude Code output: ~300 tokens
- Quota actually consumed: 300 × 5 = 1,500 tokens
- Quota unnecessarily reserved with defaults: 160,000 - 1,500 = 158,500 tokens wasted
By setting
CLAUDE_CODE_MAX_OUTPUT_TOKENS=4096, you're still giving Claude Code plenty of room (13x the average usage) while keeping 90% of your quota available for concurrent requests.Implementation Tips
- For Individual Users: Add the export commands to your
~/.bashrcor~/.zshrc - For GitHub Actions: Add to your workflow's env section
- Start Conservative: Begin with 4096 and only increase if you consistently see truncated responses
Remember: You can always increase these values if needed, but starting high causes immediate problems that are hard to diagnose.
Project Initialization with /init
Claude Code provides a helpful command to get started with a new project:
/initWhat /init Does:
- Generates a comprehensive
CLAUDE.mdguide for your project - Creates documentation tailored to your specific codebase
- Helps new team members understand the project structure
- Provides a reference for working with Claude Code in your project
How to Use /init:
- Start Claude Code in your project directory with
claude - Type
/initin the interactive REPL - Claude will analyze your codebase and generate the guide
- Review the generated
CLAUDE.mdfile - Optionally commit the file to your repository with
claude commit
The generated guide serves as a living document that explains your project's architecture, key components, and workflows - making it easier for anyone to understand and contribute to your codebase.
Accepting and Reviewing Code Additions from Claude Code
When Claude Code suggests code changes or additions, it's important to carefully review them before accepting:
Permission System
- Claude Code uses a human in the loop permission system for safety
- File modifications require explicit approval by default
- You'll be prompted to confirm before changes are made
Best Practices for Code Review
- Carefully examine suggested changes before approving them
- Understand what the code does - ask Claude to explain if needed
- Check for edge cases that might not have been considered
- Verify security implications of any code that handles sensitive data
- Test the changes after they're applied to ensure they work as expected
Managing Context with the /compact Command
The
/compact command is a powerful tool for managing context and maintaining efficient conversations with Claude Code:- What it does: Summarizes your conversation history into a concise format
- Benefits: Preserves essential information while reducing token count
- When to use: After completing major tasks, when responses slow down, or before starting new subtasks
- Token savings: Significantly reduces token usage, helping manage costs even with prompt caching
Using
/compact regularly is a best practice for maintaining coherent and efficient interactions with Claude Code, especially for complex coding tasks that require extended conversations.Monitoring Your Costs with Claude Code
Claude Code provides several ways to track your token usage and associated costs:
- During a session: Use the
/costcommand to see current token usage and estimated costs - Session summary: View a cost summary automatically displayed when exiting Claude Code
- Set spend limits: Configure spending thresholds through your account settings
Remember that costs can vary significantly based on codebase size, query complexity, number of files being analyzed, and conversation length.
Next Steps
Once configured, try a simple command like
summarize this project to test your setup. You can also generate a project guide with the /init command.For more advanced workflows, check out the Claude Code documentation .
Additional Resources and Continued Learning
Thank you for exploring how to set up Claude Code with Amazon Bedrock! To see these concepts in action through a practical example, I encourage you to check out our follow-up tutorial:
Building a Calculator Web App with Claude Code: A Step-by-Step Tutorial
In this hands-on tutorial, we'll:
- Build a complete calculator web application from scratch
- Demonstrate Claude Code's capabilities for code generation and enhancement
- Show how to add scientific calculator functions to an existing project
- Explore best practices for working with AI coding assistants
- Provide practical examples of context management with
/compact
The tutorial includes all the commands and explanations you need to follow along, whether you prefer working directly in your terminal or through the accompanying Jupyter notebook in our GitHub repository.
This practical walkthrough complements the setup guide you've just read and will help you develop an intuitive understanding of how Claude Code can enhance your development workflow with Amazon Bedrock.
Happy coding!
Note: Claude Code is now generally available. Usage costs will depend on your Amazon Bedrock pricing for Claude models. Remember to monitor token usage closely
Series: Claude Code on Amazon Bedrock (1 article)
- 1Claude Code on Amazon Bedrock: Quick Setup Guide This article
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article