Skip to content

armgit / ruflo

Public Imported from GitHub
0

🌊 The original agent harness. Deploy intelligent multi-player swarms, coordinate autonomous workflows, and build conversational AI systems. Features adaptive memory, self-learning intelligence, federation, vector RAG integration, and native Claude Code / Codex / Hermes and many more Integrated

feat(statusline): configurable cost symbol and hide toggle (#2220)

Wietzeb8a49cfb82ff
diff --git a/.claude/helpers/statusline.cjs b/.claude/helpers/statusline.cjs
index 5eb2beee8e..1228bb6d2f 100644
--- a/.claude/helpers/statusline.cjs
+++ b/.claude/helpers/statusline.cjs
@@ -28,6 +28,15 @@ const os = require('os');
// Configuration
const CONFIG = {
maxAgents: 15,
+ // Session-cost display. Claude Code's cost.total_cost_usd is a client-side
+ // estimate that "may differ from your actual bill" and reads as misleading on
+ // subscription plans, where token usage is not billed per dollar. These let
+ // each user pick what the segment means to them without changing the default.
+ // RUFLO_STATUSLINE_COST_SYMBOL override the leading '$' (e.g. ⚑, €, 🌱);
+ // set to an empty string for the number alone.
+ // RUFLO_STATUSLINE_HIDE_COST 1/true/yes/on removes the segment entirely.
+ costSymbol: process.env.RUFLO_STATUSLINE_COST_SYMBOL ?? '$',
+ hideCost: /^(1|true|yes|on)$/i.test(process.env.RUFLO_STATUSLINE_HIDE_COST || ''),
};
const CWD = process.cwd();
@@ -420,8 +429,8 @@ function generateStatusline() {
const ctxColor = ctxInfo.usedPct >= 90 ? c.brightRed : ctxInfo.usedPct >= 70 ? c.brightYellow : c.brightGreen;
header += ' ' + c.dim + 'β”‚' + c.reset + ' ' + ctxColor + '● ' + ctxInfo.usedPct + '% ctx' + c.reset;
}
- if (costInfo && costInfo.costUsd > 0) {
- header += ' ' + c.dim + 'β”‚' + c.reset + ' ' + c.brightYellow + '$' + costInfo.costUsd.toFixed(2) + c.reset;
+ if (!CONFIG.hideCost && costInfo && costInfo.costUsd > 0) {
+ header += ' ' + c.dim + 'β”‚' + c.reset + ' ' + c.brightYellow + CONFIG.costSymbol + costInfo.costUsd.toFixed(2) + c.reset;
}
lines.push(header);
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ae2780dc0b..f64ad511ea 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,14 @@ All notable changes to the Ruflo project (formerly Claude Flow) are documented h
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
+## [Unreleased]
+
+### Added
+
+- Configurable statusline cost segment via two environment variables (defaults unchanged):
+ - `RUFLO_STATUSLINE_COST_SYMBOL` β€” override the leading `$` (e.g. `⚑`, `€`, `🌱`); empty string shows the number alone.
+ - `RUFLO_STATUSLINE_HIDE_COST` β€” `1`/`true`/`yes`/`on` hides the segment. `cost.total_cost_usd` is a client-side estimate that may differ from the actual bill and is misleading on subscription plans.
+
## [3.5.0] - 2026-02-27
### Ruflo v3.5 β€” First Major Stable Release
diff --git a/docs/USERGUIDE.md b/docs/USERGUIDE.md
index 2e8db95945..e7593323f1 100644
--- a/docs/USERGUIDE.md
+++ b/docs/USERGUIDE.md
@@ -2586,6 +2586,30 @@ Claude Code pipes JSON session data via **stdin** to the statusline script after
| `🧠 15%` | Intelligence score | Pattern count from AgentDB |
| `πŸ“¦ AgentDB ●1.2K` | AgentDB vector count | File size estimate (`size / 2KB`) |
+**Customizing the cost segment:**
+
+`cost.total_cost_usd` is a client-side estimate from Claude Code that *may differ from your actual bill* and, on subscription plans, does not reflect out-of-pocket spend. Two environment variables let you relabel or remove the segment (the default is unchanged):
+
+| Variable | Effect | Example |
+|----------|--------|---------|
+| `RUFLO_STATUSLINE_COST_SYMBOL` | Overrides the leading `$`. Set to an empty string to show the number alone. | `RUFLO_STATUSLINE_COST_SYMBOL=⚑` β†’ `⚑1.30` |
+| `RUFLO_STATUSLINE_HIDE_COST` | `1`/`true`/`yes`/`on` removes the segment entirely. | `RUFLO_STATUSLINE_HIDE_COST=1` |
+
+Set them in the `env` block of `.claude/settings.json` β€” Claude Code applies it to every session and to the statusline subprocess, and unlike hand-editing the helper it survives `npx ruflo@latest init --update`:
+
+```json
+{
+ "statusLine": { "type": "command", "command": "node .claude/helpers/statusline.cjs" },
+ "env": { "RUFLO_STATUSLINE_COST_SYMBOL": "⚑" }
+}
+```
+
+Or export them in your shell profile before launching Claude Code:
+
+```bash
+export RUFLO_STATUSLINE_COST_SYMBOL=⚑ # or: export RUFLO_STATUSLINE_HIDE_COST=1
+```
+
**Setup (Automatic):**
Run `npx ruflo@latest init` β€” this generates `.claude/settings.json` with the correct statusline config and creates the helper script at `.claude/helpers/statusline.cjs`.
diff --git a/v3/@claude-flow/cli/__tests__/statusline-cost-display.test.ts b/v3/@claude-flow/cli/__tests__/statusline-cost-display.test.ts
new file mode 100644
index 0000000000..67887486e2
--- /dev/null
+++ b/v3/@claude-flow/cli/__tests__/statusline-cost-display.test.ts
@@ -0,0 +1,116 @@
+/**
+ * Statusline session-cost display configuration.
+ *
+ * Claude Code's `cost.total_cost_usd` is documented as a client-side estimate
+ * that "may differ from your actual bill", and on subscription plans it reads as
+ * misleading (token usage is not billed per dollar). The statusline therefore
+ * lets each user relabel or hide the cost segment without changing the default:
+ *
+ * RUFLO_STATUSLINE_COST_SYMBOL override the leading '$' ('' => number alone)
+ * RUFLO_STATUSLINE_HIDE_COST 1/true/yes/on => omit the segment
+ *
+ * These tests cover three layers:
+ * 1. Generator contract β€” the emitted script wires the env vars and keeps '$'
+ * as the default, so the customization can never silently regress.
+ * 2. Runtime behavior β€” the generated script renders the right thing for each
+ * configuration when fed a Claude Code stdin payload.
+ * 3. Drift guard β€” the committed `.claude/helpers/statusline.cjs` artifact stays
+ * byte-identical to the generator output for the default options.
+ */
+
+import { describe, it, expect } from 'vitest';
+import { execFileSync } from 'child_process';
+import { mkdtempSync, writeFileSync, readFileSync, existsSync, rmSync } from 'fs';
+import { tmpdir } from 'os';
+import path from 'path';
+import { fileURLToPath } from 'url';
+
+import { generateStatuslineScript } from '../src/init/statusline-generator.js';
+import { DEFAULT_INIT_OPTIONS } from '../src/init/types.js';
+
+const SCRIPT = generateStatuslineScript(DEFAULT_INIT_OPTIONS);
+
+const stripAnsi = (s: string): string =>
+ // eslint-disable-next-line no-control-regex
+ s.replace(/\x1b\[[0-9;]*m/g, '');
+
+/**
+ * Run the generated statusline against a Claude Code stdin payload. PATH is
+ * neutered so the script's `npx`/`git` probes fail instantly and fall back to
+ * local data β€” the cost segment comes purely from stdin, so this stays offline
+ * and deterministic. Returns the first (header) line with ANSI stripped.
+ */
+function renderHeader(env: Record<string, string> = {}): string {
+ const dir = mkdtempSync(path.join(tmpdir(), 'ruflo-statusline-'));
+ const scriptPath = path.join(dir, 'statusline.cjs');
+ writeFileSync(scriptPath, SCRIPT, 'utf-8');
+ const payload = JSON.stringify({
+ model: { display_name: 'Opus 4.8' },
+ context_window: { used_percentage: 34 },
+ cost: { total_cost_usd: 1.3, total_duration_ms: 376000 },
+ });
+ try {
+ const out = execFileSync(process.execPath, [scriptPath], {
+ input: payload,
+ encoding: 'utf-8',
+ env: { PATH: '/nonexistent', HOME: dir, ...env },
+ timeout: 15000,
+ });
+ return stripAnsi(out).split('\n')[0];
+ } finally {
+ rmSync(dir, { recursive: true, force: true });
+ }
+}
+
+describe('statusline cost display β€” generator contract', () => {
+ it('reads both env vars and keeps "$" as the default', () => {
+ expect(SCRIPT).toContain('RUFLO_STATUSLINE_COST_SYMBOL');
+ expect(SCRIPT).toContain('RUFLO_STATUSLINE_HIDE_COST');
+ // Default must be the dollar sign (?? '$') so existing setups are unchanged.
+ expect(SCRIPT).toContain("process.env.RUFLO_STATUSLINE_COST_SYMBOL ?? '$'");
+ });
+
+ it('renders the cost via the configurable symbol, not a hardcoded "$"', () => {
+ expect(SCRIPT).toContain('CONFIG.costSymbol + costInfo.costUsd.toFixed(2)');
+ // The literal `'$' + costInfo.costUsd` render must be gone.
+ expect(SCRIPT).not.toContain("'$' + costInfo.costUsd.toFixed(2)");
+ });
+
+ it('guards the cost segment with the hide toggle', () => {
+ expect(SCRIPT).toContain('!CONFIG.hideCost && costInfo && costInfo.costUsd > 0');
+ });
+});
+
+describe('statusline cost display β€” runtime behavior', () => {
+ it('shows "$1.30" by default (backward compatible)', () => {
+ expect(renderHeader()).toContain('$1.30');
+ });
+
+ it('replaces the symbol when RUFLO_STATUSLINE_COST_SYMBOL is set', () => {
+ const header = renderHeader({ RUFLO_STATUSLINE_COST_SYMBOL: '⚑' });
+ expect(header).toContain('⚑1.30');
+ expect(header).not.toContain('$1.30');
+ });
+
+ it('omits the segment when RUFLO_STATUSLINE_HIDE_COST is truthy', () => {
+ const header = renderHeader({ RUFLO_STATUSLINE_HIDE_COST: '1' });
+ expect(header).not.toContain('1.30');
+ });
+
+ it('shows the number alone when the symbol is an empty string', () => {
+ const header = renderHeader({ RUFLO_STATUSLINE_COST_SYMBOL: '' });
+ expect(header).toContain('1.30');
+ expect(header).not.toContain('$1.30');
+ });
+});
+
+describe('statusline cost display β€” committed artifact drift guard', () => {
+ it('matches the generator output for default options', () => {
+ const artifact = path.resolve(
+ path.dirname(fileURLToPath(import.meta.url)),
+ '../../../../.claude/helpers/statusline.cjs',
+ );
+ if (!existsSync(artifact)) return; // package tested in isolation; nothing to guard
+ expect(readFileSync(artifact, 'utf-8')).toBe(SCRIPT);
+ });
+});
diff --git a/v3/@claude-flow/cli/src/init/statusline-generator.ts b/v3/@claude-flow/cli/src/init/statusline-generator.ts
index 977fa2e420..129371c964 100644
--- a/v3/@claude-flow/cli/src/init/statusline-generator.ts
+++ b/v3/@claude-flow/cli/src/init/statusline-generator.ts
@@ -55,6 +55,15 @@ const os = require('os');
// Configuration
const CONFIG = {
maxAgents: ${maxAgents},
+ // Session-cost display. Claude Code's cost.total_cost_usd is a client-side
+ // estimate that "may differ from your actual bill" and reads as misleading on
+ // subscription plans, where token usage is not billed per dollar. These let
+ // each user pick what the segment means to them without changing the default.
+ // RUFLO_STATUSLINE_COST_SYMBOL override the leading '$' (e.g. ⚑, €, 🌱);
+ // set to an empty string for the number alone.
+ // RUFLO_STATUSLINE_HIDE_COST 1/true/yes/on removes the segment entirely.
+ costSymbol: process.env.RUFLO_STATUSLINE_COST_SYMBOL ?? '$',
+ hideCost: /^(1|true|yes|on)$/i.test(process.env.RUFLO_STATUSLINE_HIDE_COST || ''),
};
const CWD = process.cwd();
@@ -447,8 +456,8 @@ function generateStatusline() {
const ctxColor = ctxInfo.usedPct >= 90 ? c.brightRed : ctxInfo.usedPct >= 70 ? c.brightYellow : c.brightGreen;
header += ' ' + c.dim + 'β”‚' + c.reset + ' ' + ctxColor + '● ' + ctxInfo.usedPct + '% ctx' + c.reset;
}
- if (costInfo && costInfo.costUsd > 0) {
- header += ' ' + c.dim + 'β”‚' + c.reset + ' ' + c.brightYellow + '$' + costInfo.costUsd.toFixed(2) + c.reset;
+ if (!CONFIG.hideCost && costInfo && costInfo.costUsd > 0) {
+ header += ' ' + c.dim + 'β”‚' + c.reset + ' ' + c.brightYellow + CONFIG.costSymbol + costInfo.costUsd.toFixed(2) + c.reset;
}
lines.push(header);