From 64d00f4ab22ff9b5c7df6728e75dbfa12fb72ba1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BB=96=E4=BB=AC=E9=83=BD=E4=B8=8D=E7=8E=A9=E4=BA=86?= Date: Sat, 17 Oct 2026 23:35:41 +0800 Subject: [PATCH] fix(cli): honor no-color before rendering help and version (#4248) Co-authored-by: shuaiyafei <16618929+shuaiyafei@users.noreply.github.com> --- v3/@claude-flow/cli/__tests__/cli.test.ts | 17 ++++++++++++++--- v3/@claude-flow/cli/src/index.ts | 8 ++++---- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/v3/@claude-flow/cli/__tests__/cli.test.ts b/v3/@claude-flow/cli/__tests__/cli.test.ts index 87c21943f7..3b56503dba 100644 --- a/v3/@claude-flow/cli/__tests__/cli.test.ts +++ b/v3/@claude-flow/cli/__tests__/cli.test.ts @@ -384,9 +384,20 @@ describe('CLI', () => { }); it('should disable color with --no-color', async () => { - await cli.run(['--no-color', '--help']); - // Color should be disabled - check output formatter state - expect(cli['output']['colorEnabled']).toBe(false); + const originalColorEnabled = cli['output']['colorEnabled']; + try { + for (const flag of ['--help', '--version', '-V']) { + // CI starts without a TTY; explicitly enable colors so this cannot + // pass merely because the formatter already has colors disabled. + cli['output'].setColorEnabled(true); + consoleOutput.length = 0; + await cli.run(['--no-color', flag]); + expect(cli['output']['colorEnabled']).toBe(false); + expect(consoleOutput.join('')).not.toMatch(/\u001b\[/); + } + } finally { + cli['output'].setColorEnabled(originalColorEnabled); + } }); }); diff --git a/v3/@claude-flow/cli/src/index.ts b/v3/@claude-flow/cli/src/index.ts index a417b95c1f..dbdf522121 100644 --- a/v3/@claude-flow/cli/src/index.ts +++ b/v3/@claude-flow/cli/src/index.ts @@ -108,15 +108,15 @@ export class CLI { const { command: commandPath, flags, positional } = parseResult; // Handle global flags + if (flags.noColor || flags.color === false) { + this.output.setColorEnabled(false); + } + if (flags.version || flags.V) { this.showVersion(); return; } - if (flags.noColor) { - this.output.setColorEnabled(false); - } - // Set verbosity level based on flags if (flags.quiet) { this.output.setVerbosity('quiet');