Claude Code's remote environments pile up. There's no UI to clear them, no CLI command, no claude env rm. They just sit there.
The list endpoint exists. The archive endpoint exists. Neither is publicly documented, and neither is wired into the official tooling. So here's the small bash script I wrote to hit them directly.
The script
#!/usr/bin/env bash
set -e
TOKEN=$(jq -r '.claudeAiOauth.accessToken' ~/.claude/.credentials.json)
HDRS=(
-H "Authorization: Bearer $TOKEN"
-H "anthropic-version: 2023-06-01"
-H "anthropic-beta: environments-2025-11-01"
-H "Content-Type: application/json"
)
case "$1" in
list)
echo "Trying /v1/environments ..."
curl -sS "${HDRS[@]}" https://api.anthropic.com/v1/environments | jq
echo "---"
echo "Trying /v1/environments/bridge ..."
curl -sS "${HDRS[@]}" https://api.anthropic.com/v1/environments/bridge | jq
;;
archive)
if [ -z "$2" ]; then echo "need env id"; exit 1; fi
curl -sS -X DELETE "${HDRS[@]}" \
"https://api.anthropic.com/v1/environments/bridge/$2" | jq
echo "Done: $2"
;;
*)
echo "Usage:"
echo " $0 list # list environments"
echo " $0 archive <env_id> # archive one environment"
;;
esac
Download: claude-envs.sh. Drop it on your $PATH, chmod +x, then:
claude-envs list # see what you've got
claude-envs archive env_abc123 # archive one
The three things that make this work
1. The OAuth token lives in ~/.claude/.credentials.json.
When you sign in to Claude Code, it stores the access token at ~/.claude/.credentials.json under claudeAiOauth.accessToken. That's a real bearer token you can use against api.anthropic.com. No API key required.
2. The right beta header is environments-2025-11-01.
The endpoints exist on the public API surface but won't respond without the beta flag. Call them with a normal anthropic-version header alone and you get a 404 back. Add anthropic-beta: environments-2025-11-01 and they light up.
3. There are two list endpoints, and the one that holds your stuff is /bridge.
/v1/environments returns one shape. /v1/environments/bridge returns another, and the latter is the one the desktop app actually populates. The script hits both because I haven't found docs explaining the split, and it's faster to print both than to guess. Each entry has an id; pass it to archive.
Caveats
The endpoint, the header, the credentials path. Any of those can change without warning, because none of them are documented. If something stops working, re-run list first and see what shape the response takes now.
Works as of May 2026, on Claude Code 1.x. If Anthropic ships a real claude env subcommand, throw this script away.