opencode-bedrock-sso
v0.1.0
Published
OpenCode plugin that runs aws sso login before Bedrock requests when the AWS session has expired.
Maintainers
Readme
opencode-bedrock-sso
OpenCode plugin that checks AWS credentials before Amazon Bedrock requests and runs aws sso login when the current AWS SSO session has expired.
Why
Without this plugin, the annoying flow is:
- Send an OpenCode message.
- Wait for Bedrock to fail because the AWS session expired.
- Leave OpenCode and run
aws sso login. - Restart or resume OpenCode.
This plugin moves the check before the Bedrock request.
Install
Add the plugin to opencode.json:
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"amazon-bedrock": {
"options": {
"profile": "bedrock",
"region": "us-east-1"
}
}
},
"plugin": [
["opencode-bedrock-sso@latest", { "profile": "bedrock", "region": "us-east-1" }]
]
}Restart OpenCode after changing plugin config.
Requirements
- OpenCode with Amazon Bedrock configured as a provider.
- AWS CLI v2 available on
PATHasaws, unlessawsCommandis configured. - An AWS SSO profile configured in
~/.aws/config.
Options
type Options = {
providerID?: string
profile?: string
region?: string
awsCommand?: string
checkCommand?: string[]
loginCommand?: string[]
loginTimeoutMs?: number
checkTimeoutMs?: number
minCheckIntervalMs?: number
loginStdio?: "pipe" | "inherit"
force?: boolean
}Defaults:
providerID:amazon-bedrockawsCommand:awsregion:us-east-1checkCommand:sts get-caller-identity --profile <profile> --output jsonloginCommand:sso login --profile <profile>loginStdio:pipecheckTimeoutMs:30000loginTimeoutMs:600000minCheckIntervalMs:300000
Profile resolution order:
- Plugin option
profile provider.amazon-bedrock.options.profileAWS_PROFILE
Region resolution order:
- Plugin option
region provider.amazon-bedrock.options.regionAWS_REGIONus-east-1
Behavior
For each Bedrock chat request, the plugin runs aws sts get-caller-identity unless the same profile/region already passed a check within minCheckIntervalMs. Concurrent requests for the same profile/region share one in-flight check or login attempt.
When the check fails, it runs aws sso login with piped output so AWS CLI messages do not corrupt the OpenCode TUI. After login, it verifies credentials again before allowing the Bedrock request through.
If your environment does not open the browser automatically and you need to see AWS CLI's device-code URL in the terminal, opt into inherited output:
{
"plugin": [
["opencode-bedrock-sso@latest", { "profile": "bedrock", "loginStdio": "inherit" }]
]
}The plugin shows temporary OpenCode TUI toasts for login state changes:
- AWS session expired and login is starting. This toast lasts for
loginTimeoutMsso the waiting state stays visible. - Bedrock request is paused while waiting for AWS SSO login to complete. This toast also lasts for
loginTimeoutMs. - AWS session refreshed and the Bedrock request is continuing
- Login/check failed
Healthy preflight checks stay silent.
The plugin intentionally no-ops when these non-SSO credential sources are present:
AWS_BEARER_TOKEN_BEDROCKAWS_ACCESS_KEY_IDandAWS_SECRET_ACCESS_KEY- ECS container credential environment variables
- Web identity environment variables
Limitations
aws sso loginruns inside the OpenCode process. By default its output is captured to avoid disturbing the TUI.- A profile is required for the default login command. Set plugin option
profile, Bedrock provider optionprofile, orAWS_PROFILE. - This is a preflight plugin, not a provider retry plugin. If Bedrock fails for non-auth reasons, OpenCode still surfaces the provider error.
Local Development
Build the plugin locally:
npm install
npm run buildThen load the local build from opencode.json:
{
"plugin": [
["/path/to/opencode-bedrock-sso/dist/index.js", { "profile": "bedrock" }]
]
}