@frugalhq/frugal 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/README.md +21 -11
- package/SECURITY.md +1 -1
- package/dist/cli.js +9 -2
- package/dist/init.js +142 -39
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.1.1 (2026-12-03)
|
|
4
|
+
|
|
5
|
+
- `frugal init` now reads your settings and prints ready-to-run commands instead of snippets to paste: one command merges frugal into `settings.json` (with a backup, keeping an existing status line alongside frugal's), one adds the MCP server. Steps already done are skipped. New `frugal init --settings` prints the merged file. frugal still never writes Claude Code's config itself (S9).
|
|
6
|
+
|
|
3
7
|
## 0.1.0 (2026-12-02)
|
|
4
8
|
|
|
5
9
|
First release. Benchmarks on Claude Code 2.1.334 with Sonnet 5.5 and Opus 5.5 (MCP and Bash A/B, MCPMark, Terminal-Bench 2.1, SWE-bench Verified): [docs/BENCHMARK.md](docs/BENCHMARK.md).
|
package/README.md
CHANGED
|
@@ -21,14 +21,30 @@ Requires **Node 22 or later**. (Node 20 reached end of life in April 2026.)
|
|
|
21
21
|
|
|
22
22
|
```bash
|
|
23
23
|
npm install -g @frugalhq/frugal
|
|
24
|
-
frugal init # prints
|
|
24
|
+
frugal init # prints the exact commands to run; edits nothing itself
|
|
25
25
|
frugal doctor # checks config, permissions, Ollama and your Claude Code setup
|
|
26
26
|
```
|
|
27
27
|
|
|
28
|
-
`frugal init` prints
|
|
28
|
+
`frugal init` reads your Claude Code settings and prints up to two commands to copy and run:
|
|
29
|
+
|
|
30
|
+
```text
|
|
31
|
+
1) Add to ~/.claude/settings.json (a backup goes to settings.json.bak-frugal):
|
|
32
|
+
+ PostToolUse hook (shrinks MCP and Bash output)
|
|
33
|
+
+ UserPromptSubmit hook (drift and context warnings)
|
|
34
|
+
+ status line (spend and context meter)
|
|
35
|
+
|
|
36
|
+
( mkdir -p "$HOME/.claude" && cd "$HOME/.claude" && frugal init --settings > settings.json.frugal-new && cp settings.json settings.json.bak-frugal && mv settings.json.frugal-new settings.json )
|
|
37
|
+
|
|
38
|
+
2) Add the frugal_fetch MCP server (lets Claude get full output back when it needs it):
|
|
39
|
+
|
|
40
|
+
claude mcp add --scope user frugal -- frugal mcp
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
`frugal init --settings` prints your current `settings.json` with frugal's entries merged in. Everything else in the file is kept, and steps that are already done are skipped. If you already have a status line, it is kept and shown next to frugal's. frugal never writes the file itself: you run the command, and the backup lets you undo it.
|
|
44
|
+
|
|
45
|
+
What gets added:
|
|
29
46
|
|
|
30
47
|
```jsonc
|
|
31
|
-
// ~/.claude/settings.json (or $CLAUDE_CONFIG_DIR/settings.json)
|
|
32
48
|
{
|
|
33
49
|
"hooks": {
|
|
34
50
|
"PostToolUse": [
|
|
@@ -42,12 +58,6 @@ frugal doctor # checks config, permissions, Ollama and your Claude Code setup
|
|
|
42
58
|
}
|
|
43
59
|
```
|
|
44
60
|
|
|
45
|
-
```bash
|
|
46
|
-
claude mcp add --scope user frugal -- frugal mcp # provides frugal_fetch
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
If you already have a status line, `frugal init` prints a one-line `sh -c` command that runs both.
|
|
50
|
-
|
|
51
61
|
## How it works
|
|
52
62
|
|
|
53
63
|
### MCP output compression (`frugal hook tool-output`)
|
|
@@ -139,7 +149,7 @@ frugal handoff --session <id>
|
|
|
139
149
|
|---|---|
|
|
140
150
|
| `frugal report [--days 30]` | Spend per day, and bytes saved per MCP tool |
|
|
141
151
|
| `frugal doctor` | Read-only checks: Node version, config, permissions, Ollama, hooks/status line/MCP registration, managed-settings locks, Vertex/Bedrock |
|
|
142
|
-
| `frugal init` | Prints
|
|
152
|
+
| `frugal init` | Prints ready-to-run setup commands (`--settings`: your settings.json with frugal merged in) |
|
|
143
153
|
| `frugal purge --yes` | Deletes all frugal data |
|
|
144
154
|
|
|
145
155
|
## Using frugal behind a company wrapper
|
|
@@ -148,7 +158,7 @@ Many companies launch Claude Code through a wrapper that injects settings and cr
|
|
|
148
158
|
|
|
149
159
|
- **`CLAUDE_CONFIG_DIR`**: if the wrapper moves Claude Code's config, run `frugal init` and `frugal doctor` *inside a wrapper session* so they look at the right directory. frugal reads transcript paths from Claude Code's hook input and never guesses them.
|
|
150
160
|
- **Managed settings** (`allowManagedHooksOnly`, `disableAllHooks`, `allowedMcpServers`, `managed-mcp.json`): if your admins lock these, ask them to allow frugal's hooks or the `frugal` MCP server. Compression keeps working even if `frugal_fetch` is blocked.
|
|
151
|
-
- **The wrapper's own `--settings` file** can't be inspected by frugal. If the wrapper sets a `statusLine`,
|
|
161
|
+
- **The wrapper's own `--settings` file** can't be inspected by frugal. If the wrapper sets a `statusLine`, chain it with frugal's (see `CHAIN` in `src/init.ts`).
|
|
152
162
|
- **Pricing on Vertex**: Claude Code's cost figure is a list-price estimate. Set `costSource: "transcript"` and your rate card in `prices`.
|
|
153
163
|
- **Other agents** (opencode, Codex CLI, …) on the same key are not counted. The meter shows Claude Code spend only.
|
|
154
164
|
|
package/SECURITY.md
CHANGED
|
@@ -28,7 +28,7 @@ frugal's release-blocking requirements (from the v0.1 spec, §7):
|
|
|
28
28
|
| S6 | Supply chain | Zero runtime dependencies. Exact-pinned dev dependencies, committed lockfile, `npm ci --ignore-scripts`, `npm audit --audit-level=high` in CI, GitHub Actions pinned by commit SHA. |
|
|
29
29
|
| S7 | Release integrity | Built in GitHub Actions from the tag behind an approval-gated `release` environment. Published with npm trusted publishing (OIDC, no long-lived npm token) and provenance. CycloneDX SBOM and SHA256SUMS attached to the release. |
|
|
30
30
|
| S8 | No telemetry, analytics or update checks | Code review plus the S1 controls. |
|
|
31
|
-
| S9 | Never modifies Claude Code config or repo files | `init` only
|
|
31
|
+
| S9 | Never modifies Claude Code config or repo files | `init` only reads and prints, including the merged settings it suggests; the user runs the printed commands. `doctor` only reads (tested). All writes stay inside frugal's data dir. |
|
|
32
32
|
|
|
33
33
|
## Threat notes
|
|
34
34
|
|
package/dist/cli.js
CHANGED
|
@@ -16,7 +16,8 @@ Usage:
|
|
|
16
16
|
frugal handoff [--session <id>] [--transcript <path>]
|
|
17
17
|
frugal report [--days 30]
|
|
18
18
|
frugal doctor check config, Ollama, permissions, Claude Code setup
|
|
19
|
-
frugal init print
|
|
19
|
+
frugal init print ready-to-run setup commands (never edits files)
|
|
20
|
+
frugal init --settings print your settings.json with frugal added (stdout only)
|
|
20
21
|
frugal purge --yes delete all frugal data (${"$"}XDG_DATA_HOME/frugal)
|
|
21
22
|
frugal --version
|
|
22
23
|
`;
|
|
@@ -81,7 +82,13 @@ async function main(argv) {
|
|
|
81
82
|
return r.ok ? 0 : 1;
|
|
82
83
|
}
|
|
83
84
|
case "init": {
|
|
84
|
-
const {
|
|
85
|
+
const { values } = parseArgs({ args: rest, options: { settings: { type: "boolean", default: false } } });
|
|
86
|
+
const { initText, mergedSettingsText } = await import("./init.js");
|
|
87
|
+
if (values.settings) {
|
|
88
|
+
const r = mergedSettingsText();
|
|
89
|
+
(r.ok ? process.stdout : process.stderr).write(r.text + "\n");
|
|
90
|
+
return r.ok ? 0 : 1;
|
|
91
|
+
}
|
|
85
92
|
process.stdout.write(initText() + "\n");
|
|
86
93
|
return 0;
|
|
87
94
|
}
|
package/dist/init.js
CHANGED
|
@@ -1,43 +1,146 @@
|
|
|
1
|
-
// `frugal init`:
|
|
2
|
-
|
|
1
|
+
// `frugal init`: reads your Claude Code settings and prints ready-to-run commands.
|
|
2
|
+
// frugal itself never edits any file (S9): you run the commands, so you see every change.
|
|
3
|
+
import * as fs from "node:fs";
|
|
4
|
+
import * as os from "node:os";
|
|
3
5
|
import * as path from "node:path";
|
|
6
|
+
import { claudeConfigDir, configPath } from "./paths.js";
|
|
7
|
+
const TOOL_CMD = "frugal hook tool-output";
|
|
8
|
+
const PROMPT_CMD = "frugal hook prompt";
|
|
9
|
+
const STATUS_CMD = "frugal statusline";
|
|
4
10
|
export const CHAIN = "sh -c 'in=$(cat); a=$(printf %s \"$in\" | YOUR_EXISTING_COMMAND); b=$(printf %s \"$in\" | frugal statusline); printf \"%s %s\\n\" \"$a\" \"$b\"'";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
/** POSIX single-quote a string for a shell command line. */
|
|
12
|
+
export function shq(s) {
|
|
13
|
+
return "'" + s.replace(/'/g, "'\\''") + "'";
|
|
14
|
+
}
|
|
15
|
+
/** A status line that runs `existing` and frugal on the same stdin, side by side. */
|
|
16
|
+
export function chainStatus(existing) {
|
|
17
|
+
// `existing` lands inside sh -c '...': escape its single quotes for that layer.
|
|
18
|
+
const inner = `( ${existing} )`.replace(/'/g, "'\\''");
|
|
19
|
+
return CHAIN.replace("YOUR_EXISTING_COMMAND", inner);
|
|
20
|
+
}
|
|
21
|
+
function hookCommands(settings, event) {
|
|
22
|
+
const groups = settings.hooks?.[event];
|
|
23
|
+
if (!Array.isArray(groups))
|
|
24
|
+
return [];
|
|
25
|
+
const out = [];
|
|
26
|
+
for (const g of groups) {
|
|
27
|
+
const hs = g?.hooks;
|
|
28
|
+
if (Array.isArray(hs))
|
|
29
|
+
for (const h of hs)
|
|
30
|
+
if (typeof h?.command === "string")
|
|
31
|
+
out.push(h.command);
|
|
32
|
+
}
|
|
33
|
+
return out;
|
|
34
|
+
}
|
|
35
|
+
/** Add frugal's hooks and status line to a settings object. Keeps everything else as it was. */
|
|
36
|
+
export function mergeSettings(input) {
|
|
37
|
+
const s = structuredClone(input);
|
|
38
|
+
const changes = [];
|
|
39
|
+
const addHook = (event, group, cmd, label) => {
|
|
40
|
+
if (hookCommands(s, event).some((c) => c.includes("frugal") && c.includes(cmd.slice("frugal ".length))))
|
|
41
|
+
return;
|
|
42
|
+
const hooks = (typeof s.hooks === "object" && s.hooks !== null && !Array.isArray(s.hooks) ? s.hooks : (s.hooks = {}));
|
|
43
|
+
const list = Array.isArray(hooks[event]) ? hooks[event] : (hooks[event] = []);
|
|
44
|
+
list.push(group);
|
|
45
|
+
changes.push(label);
|
|
12
46
|
};
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
""
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
""
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
""
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
47
|
+
addHook("PostToolUse", { matcher: "mcp__.*|Bash", hooks: [{ type: "command", command: TOOL_CMD, timeout: 30 }] }, TOOL_CMD, "PostToolUse hook (shrinks MCP and Bash output)");
|
|
48
|
+
addHook("UserPromptSubmit", { hooks: [{ type: "command", command: PROMPT_CMD, timeout: 5 }] }, PROMPT_CMD, "UserPromptSubmit hook (drift and context warnings)");
|
|
49
|
+
const sl = s.statusLine;
|
|
50
|
+
const cur = typeof sl?.command === "string" ? sl.command.trim() : "";
|
|
51
|
+
if (!cur) {
|
|
52
|
+
s.statusLine = { type: "command", command: STATUS_CMD, padding: 0 };
|
|
53
|
+
changes.push("status line (spend and context meter)");
|
|
54
|
+
}
|
|
55
|
+
else if (!cur.includes("frugal")) {
|
|
56
|
+
s.statusLine = { ...sl, type: "command", command: chainStatus(cur) };
|
|
57
|
+
changes.push("status line: your existing one and frugal's, side by side");
|
|
58
|
+
}
|
|
59
|
+
return { settings: s, changes };
|
|
60
|
+
}
|
|
61
|
+
/** A directory for the printed command: "$HOME/..." when under home and safe to double-quote, else single-quoted. */
|
|
62
|
+
function shellDir(dir) {
|
|
63
|
+
const home = os.homedir();
|
|
64
|
+
if ((dir === home || dir.startsWith(home + path.sep)) && !/["$`\\!]/.test(dir))
|
|
65
|
+
return `"$HOME${dir.slice(home.length)}"`;
|
|
66
|
+
return shq(dir);
|
|
67
|
+
}
|
|
68
|
+
function tilde(p) {
|
|
69
|
+
const home = os.homedir();
|
|
70
|
+
return p.startsWith(home + path.sep) ? "~" + p.slice(home.length) : p;
|
|
71
|
+
}
|
|
72
|
+
function settingsTarget() {
|
|
73
|
+
let file = path.join(claudeConfigDir(), "settings.json");
|
|
74
|
+
try {
|
|
75
|
+
if (fs.lstatSync(file).isSymbolicLink())
|
|
76
|
+
file = fs.realpathSync(file); // edit the real file, keep the link
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
return { file, exists: false, settings: {} };
|
|
80
|
+
}
|
|
81
|
+
try {
|
|
82
|
+
const v = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
83
|
+
if (typeof v !== "object" || v === null || Array.isArray(v))
|
|
84
|
+
return { file, exists: true, error: "is not a JSON object" };
|
|
85
|
+
return { file, exists: true, settings: v };
|
|
86
|
+
}
|
|
87
|
+
catch (e) {
|
|
88
|
+
return { file, exists: true, error: `could not be read as JSON (${e.message})` };
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
function mcpConfigured() {
|
|
92
|
+
try {
|
|
93
|
+
const p = path.join(process.env.CLAUDE_CONFIG_DIR ?? os.homedir(), ".claude.json");
|
|
94
|
+
const v = JSON.parse(fs.readFileSync(p, "utf8"));
|
|
95
|
+
return !!v.mcpServers?.frugal;
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
/** `frugal init --settings`: the merged settings.json on stdout (used by the printed command). */
|
|
102
|
+
export function mergedSettingsText() {
|
|
103
|
+
const t = settingsTarget();
|
|
104
|
+
if (!t.settings)
|
|
105
|
+
return { text: `frugal: ${t.file} ${t.error ?? "could not be read"}; not printing a merged copy`, ok: false };
|
|
106
|
+
return { text: JSON.stringify(mergeSettings(t.settings).settings, null, 2), ok: true };
|
|
107
|
+
}
|
|
108
|
+
export function initText() {
|
|
109
|
+
const t = settingsTarget();
|
|
110
|
+
const out = ["frugal init: copy and run the commands below. frugal never edits your files itself.", ""];
|
|
111
|
+
let step = 0;
|
|
112
|
+
if (!t.settings) {
|
|
113
|
+
out.push(`${++step}) ${t.file} ${t.error}. Fix it, then run \`frugal init\` again. Or add this by hand:`, "");
|
|
114
|
+
out.push(JSON.stringify(mergeSettings({}).settings, null, 2), "");
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
const { changes } = mergeSettings(t.settings);
|
|
118
|
+
if (changes.length === 0)
|
|
119
|
+
out.push(`✓ hooks and status line already set in ${tilde(t.file)}`, "");
|
|
120
|
+
else {
|
|
121
|
+
const dir = shellDir(path.dirname(t.file));
|
|
122
|
+
const base = path.basename(t.file); // "settings.json", or a symlink's target name
|
|
123
|
+
const q = (x) => (/^[\w.@%+=:,-]+$/.test(x) ? x : shq(x));
|
|
124
|
+
const cmd = [
|
|
125
|
+
`mkdir -p ${dir}`,
|
|
126
|
+
`cd ${dir}`,
|
|
127
|
+
// pin the config dir so the command reads the same file even outside a wrapper session
|
|
128
|
+
`${process.env.CLAUDE_CONFIG_DIR ? `CLAUDE_CONFIG_DIR=${shellDir(process.env.CLAUDE_CONFIG_DIR)} ` : ""}frugal init --settings > ${q(base + ".frugal-new")}`,
|
|
129
|
+
...(t.exists ? [`cp ${q(base)} ${q(base + ".bak-frugal")}`] : []),
|
|
130
|
+
`mv ${q(base + ".frugal-new")} ${q(base)}`
|
|
131
|
+
].join(" && ");
|
|
132
|
+
// in a subshell, so the `cd` does not move the user's shell
|
|
133
|
+
out.push(`${++step}) Add to ${tilde(t.file)}${t.exists ? " (a backup goes to settings.json.bak-frugal)" : ""}:`);
|
|
134
|
+
for (const c of changes)
|
|
135
|
+
out.push(` + ${c}`);
|
|
136
|
+
out.push("", ` ( ${cmd} )`, "");
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
if (mcpConfigured())
|
|
140
|
+
out.push("✓ frugal MCP server already added", "");
|
|
141
|
+
else
|
|
142
|
+
out.push(`${++step}) Add the frugal_fetch MCP server (lets Claude get full output back when it needs it):`, "", " claude mcp add --scope user frugal -- frugal mcp", "");
|
|
143
|
+
out.push(step ? `${step + 1}) Restart Claude Code, then check: frugal doctor` : "All set. Check anytime with: frugal doctor", "");
|
|
144
|
+
out.push(`Optional: set your company's prices and a monthly cap in ${tilde(configPath())}`, ` ${JSON.stringify({ monthlyCap: 250, prices: { default: { inputPerMTok: 0, outputPerMTok: 0, cacheReadPerMTok: 0, cacheWritePerMTok: 0 } } })}`, "Using a company wrapper that sets CLAUDE_CONFIG_DIR? Run `frugal init` inside a wrapper session so the paths above are right.");
|
|
145
|
+
return out.join("\n");
|
|
43
146
|
}
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "0.1.
|
|
1
|
+
export const VERSION = "0.1.1";
|
package/package.json
CHANGED