Poking Around Claude Code
Anthropic released Claude Code, their competitor to Anysphere’s Cursor and Codium’s Windsurf. Claude Code is a tool that uses LLM as an agent to take user commands to complete software engineering tasks. In this blog post, we will try to decompose and better understand how Claude Code works under the hood.
Getting the Source Code
We can download its npm package as a tarball and unzip it to get the source code. Run the following commands:
npm pack @anthropic-ai/claude-code
tar -xzf anthropic-ai-claude-code-0.2.29.tgz
This will create a folder (usually named “package”) containing all the files. From here, we will unzip the tarball to see the JavaScript package. If you’re on Windows and don’t have a built-in tar tool, you can use a utility like 7-Zip to extract the tarball. The main control logic of Claude Code lives in cli.mjs. This file is heavily obfuscated, with lines concatenated, variables changed to non-semantic names, and modules clumped together. It is a single 20MB file. To handle this, we used Claude Code itself to format it. The prettified source code of Claude Code (~200k lines) can be found in the following gist.
Analysis
Claude Code is a local command agent that enhances developer productivity. It leverages the latest Claude Sonnet 3.7 Thinking model and the faster Claude Haiku 3.5 as its brains. It operates from the command line interface (CLI) as a read-eval-print loop (REPL).
Here are some of our findings
System Prompt
After some digging, Claude Code saves its prompts inside the code, sometimes as function returns. Below are its system prompts.
During inference, Claude Code stitches together prompts and formatters as shown below:
zlet [n0, s0, T2, N9] = await Promise.all([fR(), i7(), f6(), Lu([...r1, ...g0])])
In this specific case, fR() is the system prompt, i7() is a function, f6() appears to be the model, and Lu() is the thinking scratchpad. It’s very interesting to see Claude Code asks Claude 3.7 to megathink
and ultrathink
.
Language Specific Keyword Parsing
Claude Code is a coding tool. To help Claude understand the codebase better, it sets up significant amounts of keyword and syntax parsing and highlighting using regular expressions.
Extension via Model Control Protocol (MCP)
One of the key capabilities of large language models (LLMs) or LLM agents is tool use. A tool can be an API, a function, or some resources. Historically, AI engineers and ML engineers would need to get the schema of the tool in JSON format, write descriptions, and create control logic to make API calls. The response would then be fed back to the LLM agent.
This changed in November. Anthropic released the Model Control Protocol, which attempts to standardize the communication channel between the agent and the tool. Now, there are readily available tools via MCP Servers, and all we need is a simple descriptive JSON for the MCP Client (the agent) to consume. Claude Code supports and acts as an MCP Client, allowing us to extend its functionality by providing tools via MCP servers.
Here’s Claude Code’s implementations of its MCP Client.
Claude Code with AWS Bedrock
Claude Code supports both Amazon Bedrock Google Vertex AI. This makes Claude Code enterprise ready, without egress to external vendors, e.g, Anthropic’s API. Unfortunately, the minimalistic documentation provided by Anthropic to setup Claude Code with AWS Bedrock does NOT contain sufficient information. And we got stuck with the same problem with the comment section in Jonathan Evan’s Claude Code Setup Guide.
So, we spent some time digging throught the code base and messaged Jonathan Evans for tips to setup Claude Code to work with AWS Bedrock. The code snippets in Claude Code that involves setting up AWS Bedrock or Vertex AI is as follows for those who are curious.
0. AWS Bedrock Setup
Claude Code needs two models - Claude 3.7 Sonnet
and Claude 3.5 Haiku
. Please request them in us-east-1
, the default region for Claude Code.
1. Inference Profile
For cloud security best practices, create a new policy in AWS Identiy and Access Management (IAM) for inferencing and invocation the models, name it AmazonBedrockInferenceProfile
for clarity. Attach this policy to your AWS key and secret’s user or group.
The policy is as follows.
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"bedrock:CreateInferenceProfile",
"bedrock:GetInferenceProfile",
"bedrock:ListInferenceProfiles",
"bedrock:InvokeModel*"
],
"Resources": "*"
}
]
}
Now we are done on the AWS side. Lets test it out quickly with the following script.
2. Setup Local AWS Config
Ensure that the AWS access key and secret are in the [default]
profiles is stored in your ~/.aws/config/credentials
And, for the config, ensure your [default]
profile sets region to us-east-1
the output to json
, e.g.,
[default]
region = us-east-1
output = json
NOTE:
AWS_REGION
for AWS andCLAUDE_ML_REGION
for GCP are included in the code as either environment variables or settings. We could not get those to work, so we just stick with defaults.
3. Setup Environment Variables
Add the following to your .bashrc
, .zshrc
, .profile
, or config.fish
depending on your shell. Note that
# 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'
# AWS Bedrock does not support prompt caching yet
# Control prompt caching - set to 1 to disable
export DISABLE_PROMPT_CACHING=1
After this, we are all good to go. Let’s claude
from terminal.
Easter Egg
Apparently, you can ask Claude Code for Anthropic or Claude stickers. It will then go through the form-filling control loop and submit a Google Form on your behalf. The prompt is shown below:
Unfortunately, it is no longer available. :(
Trivia Factoids
Claude Code seems to have an internal code name tengu
. It’s a React CLI tool, built using commander and ink. It uses zod for schema validation and type inference checking, and ripgrep for traversiing files and directories.
Control Flow
Below is Claude Code’s control flow diagram from a bird’s-eye view. Note that this excludes many lines of formatting, preprocessing, and CLI user interfacing code. We could have also missed some part of the control flow due to its size and obsfucation.
Mermaid code for the control flow is here:
References
- Claude Code Overview. Anthropic Documentation https://docs.anthropic.com/en/docs/agents-and-tools/claude-code/overview
- Model Control Protocol https://modelcontextprotocol.io/introduction
- Claude Code on Amazon Bedrock: Quick Setup Guide
@article{
leehanchung,
author = {Lee, Hanchung},
title = {Poking Around Claude Code},
year = {2025},
month = {03},
howpublished = {\url{https://leehanchung.github.io}},
url = {https://leehanchung.github.io/blogs/2025/03/07/claude-code/}
}