scorpiox-bot-plugin-claudecode-login
←README.mdmarkdown
126 lines · 5 KBHEAD
BlameDownload

plugin_claudecode_login

Claude Code Login - a SCORPIOX BOT open-source plugin that manages the Claude

Code OAuth PKCE session on your node: start a login, submit the authorization

code, watch the token expiry, list named accounts, and refresh the token on

demand.

One clean-room C99 binary, zero dependencies, no OAuth client secret, and no

token ever leaves the node - or even leaves the child process that fetched it.

--meta                              {"name":"claude","desc":"Claude login"}
?action=status                      session state, expiry, accounts (JSON)
?action=start                       begin the PKCE flow -> auth_url
?action=finish&code=<code|url>      exchange the pasted code
?action=cancel                      drop the pending flow
?action=refresh                     refresh the token now
?format=json                        same as action=status
GET (no action)                     responsive dark/light HTML UI

Design: the plugin drives the CLI, it never speaks TLS

A Claude Code PKCE exchange is an HTTPS POST that carries a client identity. A

public clean-room repository can never carry an OAuth client secret, so this

plugin does not open a socket at all.

Instead it drives the login tools that ship with SCORPIOX CODE through their

machine mode - the documented, non-interactive contract for callers that

cannot hold a TTY:

child process arguments purpose
scorpiox-claudecode-login --status, --start, --finish <code>, --cancel the PKCE flow
scorpiox-claudecode-refreshtoken --credentials-file <path> --force the refresh-token grant

Both print human progress on stdout and then exactly one JSON line, so the

plugin takes the last line that starts with `{` and ignores the rest. The

refresh CLI's payload is read into a buffer and then discarded: the response is

built from a re-read of the credential file, never from what the CLI printed.

The plugin reads only these files, and only metadata out of them:

~/.claude/.credentials.json                      claudeAiOauth block
~/.claude/accounts/<name>.json                   named accounts (same schema)
~/.claude/.login-pending/claudecode-<n>.json     pending PKCE state
~/.claude/scorpiox-env/claude_code.txt           PROVIDER / MODEL profile

accessToken and refreshToken are read into a small presence-only buffer

and thrown away. No response contains a token value, a token prefix, or the key

name accessToken. tests/run.sh pins that with fixtures built from realistic

token strings.

Environment overrides (all optional, all used by the test suite)

variable default meaning
CLAUDE_CREDS_PATH ~/.claude/.credentials.json credentials file; also anchors the sibling paths
CLAUDE_ACCOUNTS_DIR ~/.claude/accounts named account directory
CLAUDE_PENDING_DIR ~/.claude/.login-pending pending-flow directory
CLAUDE_ENV_DIR ~/.claude/scorpiox-env profile directory
CLAUDE_LOGIN_BIN scorpiox-claudecode-login login CLI
CLAUDE_REFRESH_BIN scorpiox-claudecode-refreshtoken refresh CLI

A relocated CLAUDE_CREDS_PATH implies a relocated ~/.claude tree: the same

CLI writes all four files into one directory, so reading one from the override

and the rest from $HOME reports an empty state for a live session.

Auth

The node API on :8150 must never be open to the LAN. --meta stays

unauthenticated so discovery works; every other route requires

X-Bot-Password, Authorization: Bearer <pwd>, or ?pwd= when the node has

BOT_PASSWORD set.

curl -s -o /dev/null -w '%{http_code}\n' http://127.0.0.1:8150/plugin_claudecode_login
# 401

Build

make              # native  -> ./plugin_claudecode_login
make musl         # static musl x86_64   (universal Linux artifact)
make arm64        # static aarch64       (Raspberry Pi 5 / ARM64 servers)
make win64        # MinGW-w64 static PE
make macos        # Apple clang (run on macOS)
make test         # build + tests/run.sh
make ui           # regenerate src/ui_html.h from src/ui.html

make ui is required after editing src/ui.html: tools/gen_ui.py turns the

page into a C string with two control-byte placeholders (0x01 = the bot theme

prepaint + token block, 0x02 = the theme handoff script). Keep the palette in

src/bot_theme_plugin.h only - it is a trimmed copy of the bot's own theme, so

the plugin looks like part of the bot in dark and light, in a modal, in the Chat

floating window and in its own tab.

Install on a node

make install      # ~/.scorpiox/plugins, or /workspace/.scorpiox/plugins

or let the marketplace do it - https://bot.scorpiox.net/settings?sec=plugins

installs a prebuilt binary, ?mode=source clones this repo and compiles it on

the node.

Security notes

  • Every child-process argument is single-quoted for popen (shell_quote_into),

and an authorization code is validated against a strict alphabet first, so a

pasted $(...) or ; payload is refused before it can reach a shell.

  • A pasted redirect URL is accepted: code= is extracted before validation, so a

real paste (which always carries &state=) is not rejected.

  • No Content-Length header is ever emitted (Caddy 502 rule).
  • The page loads no CDN, no <script src=, no external asset; CSP is

default-src 'none' with inline script/style only.

  • No emoji anywhere in the source, the page or the JSON.

License

MIT License. Copyright (c) 2026 SCORPIOX INC.