feat(remote): Tailscale/SSH source for Claude usage logs (library only, wiring follow-up)#1015
feat(remote): Tailscale/SSH source for Claude usage logs (library only, wiring follow-up)#1015Nicolas0315 wants to merge 1 commit into
Conversation
Library-level support for fetching ~/.claude/projects from Unix-like
remote hosts over SSH and aggregating their usage alongside local logs.
- apps/ccusage/src/remote/types.ts: shared types for host specs and
materialized roots.
- apps/ccusage/src/remote/ssh.ts: host validation, BatchMode SSH fetch
pipeline (ssh | tar -xz), and command builders. Whitelists host/user
characters to block option spoofing and shell-metacharacter escapes.
- apps/ccusage/src/remote/tailscale.ts: parser for `tailscale status
--json` that emits active Unix-like peers and skips offline ones.
- apps/ccusage/src/remote/index.ts: materialize roots into a temp
directory, augment CLAUDE_CONFIG_DIR for the wrapped run, and clean
up via async dispose plus a `process.once('exit')` sync fallback.
- apps/ccusage/src/shared-args.ts: define --remote-host,
--remote-tailscale, and --remote-tmp on the shared CLI arg set.
Only ~/.claude/projects is fetched; credential files such as
.credentials.json are never transferred. Includes in-source vitest for
host parsing, SSH command building, Tailscale status parsing, and the
withRemoteClaudeRoots passthrough path.
Wiring these flags into the daily/weekly/monthly/session/blocks
commands is intentionally left for a follow-up commit.
🤖 Co-authored by Claude Code
Co-Authored-By: Claude <noreply@anthropic.com>
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
This PR was auto-closed. Only contributors approved with Maintainers review auto-closed issues and reopen worthwhile ones. Issues that do not meet the quality bar in CONTRIBUTING.md may not be reopened or receive a reply. If a maintainer replies See CONTRIBUTING.md. |
Summary
Adds library-level support for fetching Claude usage logs from Tailscale-connected or SSH-reachable Unix-like hosts and aggregating them alongside local logs. CLI flags are defined but not yet wired into the report commands — that wiring is intended as a follow-up so this PR stays small and reviewable.
What's in this PR
apps/ccusage/src/remote/types.ts—RemoteHostSpec,RemoteOptions,MaterializedRemoteClaudeRoots.ssh.ts— host whitelist validator,buildSSHFetchCommand(ssh -o BatchMode=yes -o ConnectTimeout=10 <host> 'tar -czf - -C "$HOME" .claude/projects'), andfetchClaudeProjectsViaSSHthat pipes ssh stdout intotar -xz.tailscale.ts—parseTailscaleStatusfortailscale status --json, returns activemacOS/linux/*bsdpeers.index.ts—materializeRemoteClaudeRoots,withRemoteClaudeRoots(augmentsCLAUDE_CONFIG_DIR, restores on finally, cleans up tmp via asyncrmplus aprocess.once('exit', rmSync)fallback forprocess.exit(0)paths).apps/ccusage/src/shared-args.ts)--remote-host <host[,host,...]>--remote-tailscale--remote-tmp <path>parseHostSpec,buildSSHFetchCommand,parseTailscaleStatus,parseRemoteHostsArg,shouldUseRemote,withRemoteClaudeRootspassthrough.Out of scope (deliberate)
withRemoteClaudeRootsintodaily/weekly/monthly/session/blocks— this PR is library-only. CLI flags will surface as no-ops until wired.$HOMEand assumes Unix-like remote shell).--per-hostoutput mode.CLAUDE.md: "Do not proactively create documentation files unless explicitly requested").Security notes
~/.claude/projectsis transferred.~/.claude/.credentials.jsonand other sibling files are never read.^\w[\w.-]*$) to block ssh option spoofing (-oProxyCommand=...) and shell metacharacter escapes.ssh -o BatchMode=yesdisables interactive prompts; agent/key auth only.child_process.spawnwithshell: false.os.tmpdir()withmkdtempand removed on dispose (async) or interpreter exit (sync fallback).Test plan
pnpm typecheck— greenpnpm run format— greenpnpm run test— new module 19 tests all pass; remaining 24 failures matchmainbaseline on Windows (paths.tstest asserts POSIX root,cli.tsbun path test) and are not introduced by this PR.ccusage daily --remote-host ca-20036826 --offlineFollow-ups
withRemoteClaudeRootsinto report commands so the flags become end-user usable.--per-hostfor row-level breakdown usingagentmetadata.ccusage.config.jsonremoteHostsentry.🤖 Generated with Claude Code
Summary by cubic
Adds library support to fetch Claude usage logs from SSH and Tailscale-reachable Unix-like hosts and merge them with local data. CLI flags are defined but not yet wired into report commands.
~/.claude/projectsover SSH from explicit hosts and from active Tailscale peers discovered viatailscale status --json.CLAUDE_CONFIG_DIRso reports can aggregate remote and local logs.--remote-host,--remote-tailscale,--remote-tmp(no-op until follow-up wiring).~/.claude/projects, enforces strict host/user validation, usesssh -o BatchMode=yeswithshell: false, and cleans up temp dirs on exit.Written for commit fdca3ea. Summary will update on new commits. Review in cubic