[BUG] Claude Code does not handle expiry of short term IAM credentials (security tokens)
Environment
- Platform (select one):
- [ ] Anthropic API
- [x] AWS Bedrock
- [ ] Google Vertex AI
- [ ] Other: <!-- specify -->
- Claude CLI version: 1.0.29 (Claude Code)
- Operating System: Windows 11
- Terminal: cmd
Bug Description
When using CLAUDE_CODE_USE_BEDROCK=1, if your IAM credentials expire, Claude Code does not pick up new credentials if they are refreshed.
Steps to Reproduce
- log into AWS via CLI and export AWS_PROFILE of relevant profile (using short-term STS token)
- start Claude Code
- wait for credentials to expire
- refresh AWS credentials (in another window)
- it will no longer be possible to run any commands in Claude Code
Expected Behaviour
I expect Claude Code to check for refreshed credentials when receiving 403s (API Error: 403 The security token included in the request is expired) from AWS API calls.
Actual Behaviour
API Error: 403 The security token included in the request is expired is returned continually.
To work around you can quit and restart with claude --continue but if using many Claude Code sessions this is problematic.
Additional Context
It is common for enterprises to not use long lived IAM access keys but rather short lived STS tokens, for example via saml2aws/oktacli if using Okta. These credentials typically only last for hours or a day.
If you have many different Claude Code sessions open all sharing the same base IAM profile you will need to re-open all of them to pick up new credentials.
13 Comments
Hmm - this works for me when using a stable profile (e.g.
CLAUDE_CODE_USE_BEDROCK=1 AWS_PROFILE=<stable-profile-id>andaws sso login --profile=<stable-profile-id>).Are your profile IDs dynamic? Are you also setting other vars like
AWS_ACCESS_KEY_IDfor the Claude process?Hi team, I totally faced the same issue.
My situation is using Azure SSO to get and update AWS credentials.
My campany allows only 1 hour expiration.
After the credentails expire, claude code sends ``
API Error: 403 The security token included in the request`` error.is expired
I open the new terminal and refresh the credentails, but sill show the same error.
@Yukitada-Ri can you share how you're specifying the credentials to Claude Code - are you passing
AWS_PROFILE, orAWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY/AWS_SESSION_TOKEN?We're working on a long-term solution to this, and want to make sure it covers a breadth of auth approaches.
@ant-kurt
Thank you for your replay.
I use aws-azure-login.
This refreshs and creates new
aws_access_key_id,aws_secret_access_keyandaws_session_token.I believe I use
AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY/ AWS_SESSION_TOKENinstead ofAWS_PROFILE.You can see the profile is the same.
It is still
[default].But the
aws_access_key_id,aws_secret_access_keyandaws_session_tokenare updated with the new expiration.Hmm - as a workaround, Claude Code should auto-detect those values if you perform your command (writing to ~/.aws/credentials) in another tab.
We're also looking into options on allowing a "hook" to auto-refresh these values - I'll have an update on this in a week or so.
Update: right now we're tentatively looking to add an AWS-specific setting similar to
apiKeyHelper, which will run a command when Bedrock indicates credentials are expired. This will likely surface stdout directly to the user, since some configurations require user-facing verification codes.We're also open to offering a setting to return
AWS_ACCESS_KEY_IDetc, if that's a configuration that folks need (can't modify.awsfor some reason?)Was researching and just bumped into this myself.
👍 Many people have .aws configs on their machines managed by their employer. So might not be always editable (or hassle to maintain if updated). Sometimes those have multiple aws-profiles and bedrock might work only on one of them. (ie have to pass AWS_PROFILE to Claude for it to work)
We have a wrapper around Claude Code that passes in bedrock related environment variables.
This wrapper however, doesn't affect Claude Code controlled by the IDE's (VSCode).
So, if you ask VSCode to fix a problem for you - it starts Claude which is unable to authenticate. It can be closed and restarted via wrapper with
--continuebut still a bit annoying.So, some sort of
awsAuthHelperthat allows:Would be great.
Thank you.
This was released in v1.0.52. See https://docs.anthropic.com/en/docs/claude-code/amazon-bedrock#advanced-credential-configuration
Running on macos v1.0.52, I'm getting an "Found invalid settings files" message on launch and "Unrecognized field" response in /doctor when trying to use this setting.
Sorry about that, this is actually in 1.0.53!
Opened an issue about the new feature. Not working well for me, for whatever reason #3823
@ant-kurt
Hi, I set
awsAuthRefreshbut it still can not use the updated aws credentials...I setup
awsAuthRefreshto./claude/settings.local.jsonlike the below.I added the command(
aws-azure-login --no-prompt) which refresh and create a newaws_access_key_id,aws_secret_access_keyandaws_session_tokenwith 1 hour expiration.In claude code, when the session expire, it run the command (
aws-azure-login --no-prompt).I checked
~/.aws/credentialsand can see the newaws_access_key_id,aws_secret_access_keyandaws_session_tokenare created.But the claude code does not use the new created
aws_access_key_id,aws_secret_access_keyandaws_session_tokenand shows the error like this.This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.