An OpenCode plugin that automatically detects AWS authentication errors and refreshes credentials via aws sso login.
Add to your opencode.json:
{
"plugin": ["@devtheops/opencode-plugin-aws-auth-refresh"]
}Place in .opencode/plugins/aws-auth-refresh.ts or ~/.config/opencode/plugins/.
OpenCode plugin entries can be either a string or a [pluginName, options] tuple. To pass options to this plugin, use the tuple form:
{
"plugin": [
[
"@devtheops/opencode-plugin-aws-auth-refresh",
{
"profile": "my-aws-profile",
"maxRetries": 1,
"ssoLoginCommand": {
"command": "aws",
"args": ["sso", "login", "--profile", "my-aws-profile", "--no-browser"]
}
}
]
]
}If you do not need any plugin-specific options, use the string form instead:
{
"plugin": ["@devtheops/opencode-plugin-aws-auth-refresh"]
}If you prefer not to set profile in config, the plugin falls back to AWS_PROFILE, then to default.
| Option | Type | Default | Description |
|---|---|---|---|
profile |
string |
AWS_PROFILE env or "default" |
AWS profile to use |
maxRetries |
number |
1 |
Maximum number of credential refresh attempts |
ssoLoginCommand |
{ "command": string, "args"?: string[] } |
{ "command": "aws", "args": ["sso", "login", "--profile", "<profile>"] } |
Structured custom SSO login command |
autoRetrywas removed because current OpenCode server plugin hooks do not expose a supported retry API. After credentials refresh, rerun the failed AWS command if needed.- Raw string
ssoLoginCommandvalues are no longer supported. Use the structuredcommandandargsform so command arguments remain data rather than a precomposed shell string. - Diagnostics are written through
client.app.logfor troubleshooting and are not presented as clickable or session-visible UI notifications.
- Hooks into the official
tool.execute.after(input, output)server plugin hook forbashandtasktools - Detects AWS authentication error patterns:
ExpiredTokenTokenRefreshRequiredThe security token included in the request is expiredUnable to locate credentials- And more...
- Reads the hook result from
output.output - Runs
aws sso loginwith your configured profile, or the configured structured command and args - Logs diagnostics through
client.app.log; rerun the failed command manually if needed
ExpiredTokenTokenRefreshRequiredThe security token included in the request is expiredcredentials expiredUnable to locate credentialsMissing credentialscredentials could not be foundError retrieving credentialsEC2MetadataServiceErrorRequestId:
- AWS CLI v2 installed
- Valid SSO configuration in
~/.aws/config
These messages are written through client.app.log for diagnostics. They are not shown as clickable or session-visible UI notifications.
[aws-auth-refresh] AWS credentials expired, running: aws sso login --profile default
[aws-auth-refresh] AWS credentials refreshed successfully