hashicorp/terraform · error
Too many command line arguments. Did you mean to use -chdir?
Error message
Too many command line arguments. Did you mean to use -chdir?
What it means
Returned at workspace_list.go:39 when 'terraform workspace list' is invoked with any positional arguments. The command takes no positional arguments; historically there was a DIR argument that was replaced by the global -chdir flag. The error message suggests -chdir to guide users who may be relying on the old behavior.
Solutions
- Use the -chdir global flag: 'terraform -chdir=/path/to/dir workspace list'.
- Omit positional arguments entirely: 'terraform workspace list'.
- cd into the target directory before running the command.
Example fix
// before terraform workspace list /path/to/config // error: Too many command line arguments. Did you mean to use -chdir? // after terraform -chdir=/path/to/config workspace list
Defensive patterns
Strategy: validation
Validate before calling
// Use -chdir instead of positional args for workspace list:
// exec.Command("terraform", "-chdir="+dir, "workspace", "list") Prevention
- Use the -chdir global flag instead of positional directory arguments.
- Update scripts that rely on pre-0.10 workspace command syntax.
- Document the -chdir flag for teams migrating from older terraform versions.
When it happens
Trigger: Running 'terraform workspace list .' or 'terraform workspace list /path/to/dir'. workspace_list.go:37-38 checks 'len(args) != 0' after flag parsing and appends this error.
Common situations: Users upgrading from very old terraform versions where 'workspace list' accepted a directory; muscle memory from 'terraform env list'; confusion about where to specify the working directory.
Related errors
- Expected a single argument: NAME.
- Expected a single argument: NAME.
- Expected a single argument: NAME.
- A managed resource address is required. Importing into a…
- errInitCopyNotEmpty
AI-assisted analysis of hashicorp/terraform@d32a084675 (2026-08-11).
Data as JSON: /api/errors/619a7918c7a498df.
Report an issue: GitHub.
Appendix: source
Thrown at internal/command/arguments/workspace_list.go:39
var diags tfdiags.Diagnostics
var jsonOutput bool
cmdFlags := defaultFlagSet("workspace list")
cmdFlags.BoolVar(&jsonOutput, "json", false, "produce JSON output")
if err := cmdFlags.Parse(args); err != nil {
diags = diags.Append(tfdiags.Sourceless(
tfdiags.Error,
"Failed to parse command-line flags",
err.Error(),
))
}
// `workspace list` takes no positional arguments. Historically there was a DIR argument that was replaced with the -chdir flag.
// Here we replicate the old behaviour of suggesting the user to use -chdir if they provide any positional arguments.
args = cmdFlags.Args()
if len(args) != 0 {
diags = diags.Append(errors.New("Too many command line arguments. Did you mean to use -chdir?"))
}
switch {
case jsonOutput:
return &WorkspaceList{Workspace: Workspace{ViewType: ViewJSON}}, diags
default:
return &WorkspaceList{Workspace: Workspace{ViewType: ViewHuman}}, diags
}
}
View on GitHub (pinned to d32a084675)