cc-aws-keepalive

devops-infra MCP Server

Keep Claude Code sessions alive through AWS credential expiry

Verified
devops-infradevops-infraaws
6 views1 stars0 forksv0.5.0GPL-3.0

Why This Matters

Discovered via github-topic:mcp and last synced 3mo ago.

Verified
Source
github-topic:mcp
Stars
1
Last synced
3mo ago
Install
Check source

Install

Install instructions not detected yet

Check the source repository for the latest setup steps.

View source instructions
33
Tools
0
Resources
0
Prompts
Standard I/O
Transport

Available Tools (33)

autoLoginMinutes

Auto-run `autoLoginCmd` when session has fewer than this many minutes left (0 = disabled). Requires `expirationField`. Rate-limited to once per 5 minutes

awsmyid

`awsmyid_session_expiration`

Script

Purpose

Cause

Fix

profile

AWS profile name in `~/.aws/credentials`

autoLoginCmd

Command for fully automated re-authentication. Must work without a TTY — see [Auto-login setup](#auto-login-setup) below

gimme-aws-creds

`x_security_token_expires`

timerWarnMinutes

Minutes before expiry to turn the statusline timer red

Variable

Description

aws-google-auth

`x_security_token_expires`

expirationField

Field storing session expiration as unix timestamp. Leave empty to fall back to `aws sts get-caller-identity` (slower, can only detect expired vs. valid — not time remaining)

statusLineCmd

Existing status line command to compose with (leave empty for standalone)

Provider

`expirationField` value

syncTimeoutSeconds

Timeout per sync operation in seconds (default: 15). Uses seconds (not minutes) because sync operations complete in seconds, unlike session lifetimes

remotePath

Remote credentials file path (default: `~/.aws/credentials`)

method

HTTP method (default: `POST`)

command

Shell command to execute (required)

statusLine

### How it works **Before expiry (proactive):** 1. You submit a prompt in Claude Code 2. The `UserPromptSubmit` hook checks credential expiration 3. If nearing expiry and `autoLoginCmd` is configured: fires it in the background (you get a notification, approve MFA, session renews silently) 4. If nearing expiry without `autoLoginCmd`: inline warning with re-auth command 5. If expired: warns inline — the prompt proceeds and `awsAuthRefresh` handles recovery **After expiry (reactive):** 1. Claude Code hits a Bedrock 403 2. `awsAuthRefresh` runs — checks if you already re-authed in another terminal 3. If still expired and `autoLoginCmd` is configured, runs it synchronously (waits up to 3 minutes for password + MFA) 4. `awsCredentialExport` reads fresh creds from disk (bypassing SDK memory cache) 5. Claude Code retries the API call — session continues without restart ### The key insight Claude Code's AWS SDK caches credentials in memory and doesn't re-read `~/.aws/credentials` after expiry ([known issue](https://github.com/anthropics/claude-code/issues/41064)). The `awsCredentialExport` setting forces Claude Code to call our script instead, which always reads the latest credentials from disk. ## Install Requires Node.js (ships with Claude Code). ### Option A: As a Claude Code plugin (recommended) ```bash # Add the marketplace to your settings.json: # "extraKnownMarketplaces": { # "cc-aws-keepalive": { # "source": { "source": "git", "url": "https://github.com/GeiserX/cc-aws-keepalive.git" } # } # } # # Then enable the plugin: # "enabledPlugins": { "cc-aws-keepalive@cc-aws-keepalive": true } ``` The plugin auto-registers the `UserPromptSubmit` hook. You still need to add `awsCredentialExport` and `awsAuthRefresh` to `~/.claude/settings.json` — point them at the cached plugin path: ```json { "awsCredentialExport": "node ~/.claude/plugins/cache/cc-aws-keepalive/cc-aws-keepalive/<version>/aws-cred-export.mjs", "awsAuthRefresh": "node ~/.claude/plugins/cache/cc-aws-keepalive/cc-aws-keepalive/<version>/aws-auth-refresh.mjs" } ``` Replace `<version>` with the installed version (e.g., `0.3.0`). Then create and edit your config: ```bash cp config.example.json ~/.config/cc-aws-keepalive/config.json ``` ### Option B: Manual (no plugin system) ```bash git clone https://github.com/GeiserX/cc-aws-keepalive.git cd cc-aws-keepalive node install.mjs ``` The installer creates a config and prints all settings to add to `~/.claude/settings.json`. ### Upgrading After upgrading, re-run the installer to update paths: - **Plugin**: `node ~/.claude/plugins/cache/cc-aws-keepalive/cc-aws-keepalive/<version>/install.mjs` - **Manual**: `git pull && node install.mjs` The installer automatically: 1. **OMC HUD wrapper**: Cleans up any legacy timer patch from `omc-hud.mjs` and updates the `aws-hud-wrapper.mjs` with the current path 2. **settings.json paths**: Updates `awsCredentialExport` and `awsAuthRefresh` to point to the new version directory (preserves any custom wrapper commands) ## Configure Edit `~/.config/cc-aws-keepalive/config.json`: ```json { "profile": "my-bedrock-profile", "expirationField": "x_security_token_expires", "loginCmd": "saml2aws login --profile my-bedrock-profile", "autoLoginCmd": "", "autoLoginMinutes": 30, "warnMinutes": 30, "timerWarnMinutes": 60, "statusLineCmd": "" } ```

loginCmd

Command to re-authenticate (shown in warnings so you can copy-paste it)

warnMinutes

Minutes before expiry to start showing warnings

CC_KEEPALIVE_PROFILE

Overrides `profile` from config. Useful for multi-account setups where different terminals use different AWS accounts

saml2aws

`x_security_token_expires`

Success

Logged in} { puts "Auto-login succeeded" } eof {} timeout { puts stderr "auto-login timed out after 180s" exit 1 } } set result [wait] exit [lindex $result 3] ``` Save it to `~/.config/cc-aws-keepalive/auto-login.exp` and make it executable: ```bash chmod +x ~/.config/cc-aws-keepalive/auto-login.exp ``` **Test it manually first:** ```bash # This should complete the full login without any manual input expect ~/.config/cc-aws-keepalive/auto-login.exp my-profile ``` If it hangs, run with `log_user 1` (change line 4) to see what the tool is outputting — often it's an unexpected prompt or ANSI escape codes breaking the pattern match. ### Step 3: Configure cc-aws-keepalive Update your `~/.config/cc-aws-keepalive/config.json`: ```json { "profile": "my-bedrock-profile", "expirationField": "x_security_token_expires", "loginCmd": "saml2aws login --profile my-bedrock-profile", "autoLoginCmd": "expect ~/.config/cc-aws-keepalive/auto-login.exp my-bedrock-profile", "autoLoginMinutes": 30, "warnMinutes": 30, "timerWarnMinutes": 60, "statusLineCmd": "" } ``` Key points: - `autoLoginCmd` is the full command — it must work when run as `sh -c "your command"` with no TTY - `autoLoginMinutes` controls how early the proactive trigger fires (30 = re-auth when 30 minutes remain) - `loginCmd` is still shown in manual warnings as a fallback — it's never run automatically ### Common pitfalls

Field

Description

syncTargets

Array of sync targets (empty = disabled)

syncCooldownSeconds

Minimum seconds between syncs (default: 60)

host

Remote hostname (required)

user

SSH username (optional — uses SSH config default)

remoteProfile

Profile name in the JSON payload (default: same as local `profile`)

sshArgs

Additional SSH arguments as a string or array (optional). Use array form for paths with spaces: `["-i", "/path/to/key"]`

sshPassword

Password for `sshpass` auth (optional — prefer key-based auth)

url

HTTPS endpoint (required — HTTP refused)

headers

Custom headers; supports `${ENV_VAR}` interpolation (optional)