Select your cookie preferences

We use essential cookies and similar tools that are necessary to provide our site and services. We use performance cookies to collect anonymous statistics, so we can understand how customers use our site and make improvements. Essential cookies cannot be deactivated, but you can choose “Customize” or “Decline” to decline performance cookies.

If you agree, AWS and approved third parties will also use cookies to provide useful site features, remember your preferences, and display relevant content, including relevant advertising. To accept or decline all non-essential cookies, choose “Accept” or “Decline.” To make more detailed choices, choose “Customize.”

AWS Logo
Menu
Claude Code on Amazon Bedrock: Quick Setup Guide

Claude Code on Amazon Bedrock: Quick Setup Guide

Configure Anthropic's AI Coding Assistant with AWS Bedrock

Jonathan Evans
Amazon Employee
Published Feb 25, 2025
Last Modified Mar 31, 2025
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 3.7 Sonnet model. Claude Code integrates into your terminal, understands your codebase, and assists with coding tasks through natural language commands.

What is Claude Code?

Claude Code is a powerful terminal-based coding assistant that:
  • Edits files and fixes bugs across your codebase
  • Answers questions about code architecture and logic
  • Executes and fixes tests, resolves merge conflicts, and more
  • Works directly from your terminal with your local environment

Claude Code Models

Claude Code requires access to both Claude 3.7 Sonnet and Claude 3.5 Haiku models:
  • Claude 3.7 Sonnet: The primary model that handles complex code understanding, generation, and reasoning tasks
  • Claude 3.5 Haiku: A lightweight model used for specific functions within Claude Code:
    • Faster response times for simpler queries
    • More efficient token usage for routine operations
    • Handling background tasks and file indexing
    • Preprocessing and filtering code before sending to the more powerful Sonnet model
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 Claude 3.7 Sonnet and Claude 3.5 Haiku models in your AWS Bedrock Model Access settings for the region you're using. Failure to enable either model will result in 403 Forbidden errors when using Claude Code. 🔑 🚫
See the AWS Bedrock Getting Started Guide for instructions on enabling model access.

About Claude 3.7 Sonnet

Claude 3.7 Sonnet is Anthropic's latest model optimized for software development tasks:
  • Superior code comprehension and generation capabilities
  • Enhanced reasoning for debugging complex issues
  • Improved context handling for navigating large codebases
  • Better understanding of programming concepts and patterns
  • Optimized for terminal-based interactions in Claude Code
This powerful model brings significant improvements to coding assistance while maintaining a balance between performance and cost.

Benefits of Using Claude Code with Amazon Bedrock

  • Leverage your existing AWS Bedrock allocation and billing
  • Access to Claude 3.7 Sonnet's advanced coding capabilities
  • Keep your code interactions within your AWS infrastructure
  • Potentially access higher rate limits when properly configured
  • Maintain consistent security and compliance standards
  • Use prompt caching (if available) for cost optimization

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

Quick AWS Credential Setup:

  1. 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.
  2. Manual Configuration:
    • Create credential files in ~/.aws/credentials and ~/.aws/config
Remember, your IAM role/user must have permissions to access Amazon Bedrock and specifically the Claude 3.7 Sonnet and Claude 3.5 Haiku models you're trying to use.

Setting up Claude Code with Amazon Bedrock

You can easily connect Claude Code to Amazon Bedrock with just a few commands:
1
2
3
4
5
6
7
8
9
10
11
12
# Install Claude Code
npm install -g @anthropic-ai/claude-code

# Configure for Bedrock with Claude 3.7 Sonnet
export CLAUDE_CODE_USE_BEDROCK=1
export ANTHROPIC_MODEL='us.anthropic.claude-3-7-sonnet-20250219-v1:0'

# Control prompt caching - set to 1 to disable (see note below)
export DISABLE_PROMPT_CACHING=1

# Launch Claude Code
claude

Important: Prompt Caching & Cost Management

⚠️ Token Usage Warning: Claude Code can be very token-intensive and therefore potentially expensive to use, especially without prompt caching enabled.

About Prompt Caching:

  • What it does: Significantly reduces token usage and costs by caching prompts
  • Availability: Available to select Bedrock customers in preview (coming to Bedrock GA in the future)
  • How to control: Use the DISABLE_PROMPT_CACHING environment variable:
    • To disable caching: export DISABLE_PROMPT_CACHING=true
    • To enable caching (if you have access): unset DISABLE_PROMPT_CACHING (remove the variable altogether)

Recommendations:

  • If you have access to prompt caching (preview or GA): Definitely use it! Just omit the DISABLE_PROMPT_CACHING variable.
  • If you don't have prompt caching: Be mindful of usage as costs can accumulate quickly.
    • Monitor your usage with the /cost command within Claude Code
    • Consider using /compact and /clear commands regularly to manage context size

Project Initialization with /init

Claude Code provides a helpful command to get started with a new project: /init

What /init Does:

  • Generates a comprehensive CLAUDE.md guide 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:

  1. Start Claude Code in your project directory with claude
  2. Type /init in the interactive REPL
  3. Claude will analyze your codebase and generate the guide
  4. Review the generated CLAUDE.md file
  5. 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

  1. Carefully examine suggested changes before approving them
  2. Understand what the code does - ask Claude to explain if needed
  3. Check for edge cases that might not have been considered
  4. Verify security implications of any code that handles sensitive data
  5. Test the changes after they're applied to ensure they work as expected
⚠️ IMPORTANT ⚠️: You should always use the Yes option and avoid using "Yes, don't ask again" to ensure that all code, file changes, and commands generated by Claude are strictly reviewed by a human. This human-in-the-loop review process is critical for maintaining security and code quality. 👁️ 🔒

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 /cost command 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:
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 currently in beta as a research preview. Usage costs will depend on your Amazon Bedrock pricing for Claude models. Remember to monitor token usage closely, especially if you don't have prompt caching enabled.
 

Any opinions in this post are those of the individual author and may not reflect the opinions of AWS.

14 Comments

Log in to comment