Lines 1-27javascript
2 * shell-integration.ts — automatic shell wiring so users never have to type
3 * `tokenpincher wrap -- claude` by hand.
5 * Installs a tiny POSIX-sh function named `claude` into
6 * ~/.tokenpincher/shell.sh (regenerated on every install, so upgrades always
7 * pick up the current invocation), and sources it from the user's rc file
8 * (~/.zshrc or ~/.bashrc) via an idempotent marked block. The function
9 * transparently routes `claude` through the local proxy, and guards against
10 * re-wrapping nested/child invocations via TOKENPINCHER_WRAPPED.
12import { existsSync, mkdirSync, readFileSync, writeFileSync, unlinkSync } from "node:fs";
13import { homedir } from "node:os";
14import { join } from "node:path";
15import { resolveInvocation } from "./invocation.js";
16const TOKENPINCHER_DIR = join(homedir(), ".tokenpincher");
17export const SNIPPET_PATH = join(TOKENPINCHER_DIR, "shell.sh");
MediumInstall Persistence
Source writes installer persistence such as shell profile or service configuration.
dist/shell-integration.jsView on unpkg · L7 18const ZSHRC_PATH = join(homedir(), ".zshrc");
19const BASHRC_PATH = join(homedir(), ".bashrc");
20const MARKER_START = "# >>> tokenpincher >>>";
21const MARKER_END = "# <<< tokenpincher <<<";
22/** Generate shell.sh's content for the current invocation. */
23function buildSnippet() {
24 const invoke = resolveInvocation();
25 return `# tokenpincher shell integration — makes \`claude\` and \`codex\` run through the local proxy
27 if [ -n "$TOKENPINCHER_WRAPPED" ]; then command claude "$@"; return $?; fi