
Build a Calculator App with Claude Code on AWS Bedrock
Learn to build a calculator web app using Claude Code on AWS Bedrock. Follow best practices for AI-assisted development, cost management, and security.
Following Along with this Tutorial
Project Initialization with /init
Understanding the /init Command in Action
Building the Calculator Web Application
Accepting and Reviewing Code Additions from Claude Code
Best Practices for Code Review
Testing Our Calculator Web Application
Managing Context with the /compact Command
Enhancing Projects with Claude Code: Adding Scientific Calculator Functions
Testing Your Enhanced Calculator
Monitoring Your Costs with Claude Code
Claude Code Pricing on Amazon Bedrock
Strategies to Reduce Token Usage:
Conclusion: Unleashing the Power of Claude Code with Amazon Bedrock
- Using the Jupyter Notebook: Access the complete notebook with code examples on the AWS Samples Anthropic on AWS GitHub repository. The notebook contains the same steps we'll cover here, with additional code cells you can execute.
- Following this Community Post: All steps are documented here in this post, and you can apply them directly in your terminal with Claude Code.
1
2
3
# Create a project directory
mkdir sandbox
cd sandbox
calculator.md
with the following basic requirements:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# Calculator Web Application Requirements
## Functionality
- Basic arithmetic operations (addition, subtraction, multiplication, division)
- Clear button to reset calculations
- Delete button to remove the last entered digit
- Responsive design for mobile and desktop use
## Optional Features
- Scientific calculator functions (sin, cos, tan, log, etc.)
- Calculation history
- Theme switching (light/dark mode)
- Support for brackets and complex expressions
## Technical Requirements
- Vanilla JavaScript (no external libraries)
- CSS for styling
- HTML for structure
- Mobile-responsive design
/init
command to analyze our project and create helpful documentation:1
2
# Launch Claude Code in your project directory
claude
1
/init
- Scan your repository structure
- Examine existing documentation (like our calculator.md file)
- Look for configurations, patterns, and project organization
- Generate a comprehensive CLAUDE.md guide for your project
/init
command performs a comprehensive analysis of your codebase to create helpful documentation. When executed:- It scans your repository structure, identifying files and their relationships
- It examines existing documentation (like the calculator.md file we've created)
- It looks for configuration files, coding patterns, and project organization
- It checks for existing guidelines (like Cursor rules or Copilot instructions)
- Practical build and run commands tailored to your project
- Code style guidelines specific to your technology stack
- Architecture recommendations that match your existing patterns
- Documentation standards to maintain consistency
1
Now create the site! Please implement the calculator web application based on the requirements in calculator.md and following the guidelines in CLAUDE.md. We'll need HTML, CSS, and JavaScript components to create a functional calculator. Name the HTML file calculator.html
- An HTML file for the calculator structure
- CSS for styling and responsive design
- JavaScript for calculator functionality
- 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, unless you've accepted the file modification 'don't ask again' prompt
- 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
- Yes: Approve this specific action once
- Yes, don't ask again: Approve this type of action for the remainder of the session
- No: Reject the suggested change
⚠️ 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. 👁️ 🔒
- Navigate to the
sandbox
directory where the calculator files were created - Open the
calculator.html
file in your web browser- You can do this by double-clicking the file or right-clicking and selecting "Open with" your preferred browser
- Basic arithmetic operations (addition, subtraction, multiplication, division)
- Clear functionality (C button)
- Delete functionality (DEL button)
- Test the responsive design by resizing your browser window
- Scientific calculator functions
- Calculation history
- Theme switching
- Bracket support for complex expressions
/compact
command is a powerful tool for managing context and maintaining efficient conversations with Claude Code.- Summarizes your conversation history into a concise format
- Preserves the essential information while reducing token count
- Maintains context awareness without the full conversation history
- Executed directly in the Claude Code terminal with the command
/compact
- Maintains Coherence: Unlike
/clear
, preserves the important parts of your conversation history - Enhances Temporal Coherence: Helps Claude better understand the timeline and sequence of your interactions
- Improves Context Referencing: Makes it easier for Claude to accurately reference and recall information from earlier in the conversation
- Reduces Token Usage: Significantly lowers the number of tokens consumed, helping manage costs
- Improves Performance: With less context to process, Claude can respond more quickly
- Extends Conversation Length: Allows you to have longer, more productive sessions without hitting context limits
- With Prompt Caching: When prompt caching is enabled in Bedrock, the cost benefits of
/compact
are less significant since you're not charged for repeated prompts - Primary Benefit Shift: With prompt caching,
/compact
becomes more valuable for maintaining conversation coherence rather than cost management - Still Recommended: Even with prompt caching enabled, using
/compact
regularly helps Claude maintain a clearer understanding of your conversation flow and project context
- After completing a major task or milestone
- When you notice Claude's responses slowing down
- Before starting a new, related subtask
- When Claude seems to be confusing the order of past events or instructions
- When transitioning between different aspects of your project
- Periodically during long coding sessions (regardless of prompt caching status)
/compact
command in your Claude Code terminal now to summarize our conversation about the calculator project:1
/compact
/compact
command to optimize our conversation context, let's see how Claude Code can help us enhance our calculator application with new functionality:1
Add optional scientific calculator functions to our application. We should include sin, cos, tan, log, sqrt, and power functions.
- Open the
calculator.html
file in your web browser - Try out the basic arithmetic operations (addition, subtraction, multiplication, division)
- Test the newly added scientific functions (sin, cos, tan, log, etc.)
- Verify that all calculations produce the expected results
- Check that the UI displays correctly on your device
- 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
1
/cost
- Compact conversations: Use
/compact
when your context gets large - Write specific queries: Avoid vague requests that trigger unnecessary file scanning
- Break down complex tasks: Split large tasks into focused interactions
- Clear history between tasks: Use
/clear
to reset context when switching topics
- Understand and navigate complex codebases
- Generate, edit, and debug code across multiple files
- Answer detailed questions about architecture and implementation
- Execute commands and perform real actions in your development environment
- Maintain context awareness throughout extended coding sessions
- Enterprise Security: Keep your code interactions within your AWS infrastructure
- Cost Management: Track and optimize token usage with built-in tools
- Seamless Integration: Leverage your existing AWS Bedrock allocation and billing
- Developer Experience: Work directly from your terminal with minimal setup
- Context Management: Maintain productive sessions with
/compact
and other commands
- Start Small: Begin with focused tasks to build familiarity with Claude Code
- Establish Workflows: Develop patterns for effective collaboration with the AI
- Monitor Usage: Keep an eye on costs and optimize with
/compact
and other strategies - Share Knowledge: Document effective prompts and approaches with your team
- Stay Updated: Claude Code is actively developing with regular improvements
Any opinions in this post are those of the individual author and may not reflect the opinions of AWS.