Skip to content

svelte-check: CLAUDECODE=1 auto-detection broken due to sade default value #2897

@trevormunoz

Description

@trevormunoz

Description

The fix in #2870 to auto-detect CLAUDECODE=1 and use machine format doesn't work because the --output option has a default value in the sade CLI definition.

Note: svelte-check --output machine works correctly. The bug is specifically in the auto-detection path when no --output flag is provided.

Minimal Reproduction

// Run: CLAUDECODE=1 node reproduce.js
// Expected output: "machine"
// Actual output: "human-verbose"

const outputFormats = ['human', 'human-verbose', 'machine', 'machine-verbose'];

// sade sets default: .option('--output', '...', 'human-verbose')
const opts = { output: 'human-verbose' };

function getOutputFormat(opts) {
  if (outputFormats.includes(opts.output)) {
    return opts.output;  // ← Always returns here (default is valid)
  } else if (process.env.CLAUDECODE === '1') {
    return 'machine';    // ← Never reached
  }
  return 'human-verbose';
}

console.log('CLAUDECODE:', process.env.CLAUDECODE);
console.log('Result:', getOutputFormat(opts));

Output:

CLAUDECODE: 1
Result: human-verbose

Root Cause

In packages/svelte-check/src/index.ts, the sade option definition provides a default:

.option('--output', '...', 'human-verbose')  // ← Default value

This means opts.output is always 'human-verbose' when user doesn't provide --output, so getOutputFormat() returns early before reaching the CLAUDECODE check.

Suggested Fix

Remove the default from .option():

.option('--output', 'What output format to use...')  // No default

And guard the check in getOutputFormat:

function getOutputFormat(opts) {
    if (opts.output && outputFormats.includes(opts.output)) {
        return opts.output;
    } else if (process.env.CLAUDECODE === '1') {
        return 'machine';
    } else {
        return 'human-verbose';
    }
}

Environment

  • svelte-check: 4.3.4
  • Node: 20.x

Metadata

Metadata

Assignees

No one assigned

    Labels

    FixedFixed in master branch. Pending production release.

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions