# CF Worker Deploy Token Refresh

## When token expires

Cloudflare API tokens expire. When `npx wrangler deploy` returns `Authentication failed (status: 400) [code: 9106]`:

1. The token in `~/.wrangler/config/default.toml` or `/tmp/cf_token` has expired
2. Generate a new one: https://dash.cloudflare.com/profile/api-tokens → "Edit Cloudflare Workers"
3. Save to `/tmp/cf_token` (53 chars, format `cfut_...`)
4. Or update `~/.wrangler/config/default.toml`

## Python-based deploy pattern (when bash `$()` fails)

The terminal tool's bash has issues with `$()` subshells. Use `execute_code` with Python f-strings:

```python
from hermes_tools import terminal

token = open('/tmp/cf_token').read().strip()
r = terminal(
    command=f"cd /path/to/worker && CLOUDFLARE_API_TOKEN={token} npx wrangler deploy 2>&1",
    timeout=120
)
```

## Deploy all workers

```bash
cd services/addon-config-worker
npx wrangler deploy                      # main worker
npx wrangler deploy --config old-name.toml  # legacy URL
npx wrangler deploy --config auth_wrangler.toml  # auth worker
```
