npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

grok-auth-cli

v1.0.11

Published

Manage, inspect, and switch Grok CLI authentication accounts.

Readme

grok-auth

English

一个使用纯 Node.js 编写的 Grok 多账号认证管理命令行工具。它按照邮箱地址保存完整的 auth.json 快照,支持查看、切换和删除账号,并通过 Grok CLI 的 Billing 接口查询用量。Token 永远不会输出到终端。

在查询用量或切换账号前,CLI 会检查 expires_at;如果该字段缺失,则回退检查 JWT 的 exp 声明。认证将在过期前 5 分钟通过 OIDC refresh_token 流程自动刷新。轮换后的 access token、refresh token 和过期时间会以原子方式保存。如果 refresh token 已经失效,则必须重新登录 Grok。

用量查询结果会按账号缓存在 .grok/usage-cache.json 中,有效期为 120 秒。只有 HTTP 401 会触发强制认证刷新,HTTP 403 不会刷新认证。如果刷新后的 Token 仍然收到 HTTP 401,该账号的认证刷新将暂停 10 分钟,以避免 refresh token 被反复轮换。

交互式 switch 菜单中的 EXP 列显示 access token 的实际过期时间,并包含本地 UTC 偏移;它不再显示认证文件的修改时间。

安装

需要 Node.js 18.17 或更高版本。网络请求遵循标准的 HTTP_PROXY、HTTPS_PROXY 和 NO_PROXY 环境变量。

npm install --global grok-auth-cli

也可以不进行全局安装,直接运行:

npx --package grok-auth-cli grok-auth list

命令

grok-auth save
grok-auth list
grok-auth current
grok-auth usage [邮箱或序号]
grok-auth switch [邮箱或序号]
grok-auth remove <邮箱或序号> [--force]
grok-auth version

默认情况下,CLI 读取当前用户主目录下的 .grok/auth.json,并将账号快照保存在 .grok/accounts/。使用 --grok-home <路径> 可以指定其他目录:

grok-auth list --grok-home D:\\profiles\\grok

不带参数运行时,当前账号会以绿色突出显示。不指定账号运行 switch 时,将打开交互式菜单并突出显示活动账号。设置 NO_COLOR 环境变量可以禁用颜色。在替换当前 auth.json 前,工具会自动保存当前认证。切换成功后只输出 Done.。

认证刷新行为

  • Token 距离过期不足 5 分钟时,自动执行 OIDC 刷新。
  • Token 尚未临近过期时,查询用量不会发送认证刷新请求。
  • Billing 返回 HTTP 401 时,强制刷新一次认证并重试查询。
  • Billing 返回 HTTP 403 时,直接报告权限错误,不刷新认证。
  • 刷新后仍返回 HTTP 401 时,暂停认证刷新 10 分钟。
  • 刷新成功后,更新对应认证文件中的 key、expires_at 和 create_time。
  • Token 接口返回新的 refresh_token 时保存新值;未返回时保留旧值。

本地缓存

成功取得的用量配置会保存到 .grok/usage-cache.json,并缓存 120 秒。在缓存有效期内重复运行 usage 或打开 switch 菜单时,会直接使用缓存,不再发送 Billing 查询请求。缓存文件不包含 access token 或 refresh token。

本地开发与打包

npm install
npm test
npm pack

本包使用 Undici 发送 HTTP 请求,并支持标准代理环境变量。

许可证

本项目采用 MIT License 开源。