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');