# panic: flag redefined: -verbose

- **ID:** `go/flag-redefined-panic`
- **Domain:** go
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 90%

## Root Cause

Calling flag.String, flag.Int, or similar with a flag name that has already been registered in the same flag.CommandLine set.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| go1.20 | active | — | — |
| go1.21 | active | — | — |
| go1.22 | active | — | — |
| go1.23 | active | — | — |

## Workarounds

1. **Ensure each flag name is unique across the entire program: use descriptive prefixes like `-server-port` and `-client-port` instead of just `-port`.** (95% success)
   ```
   Ensure each flag name is unique across the entire program: use descriptive prefixes like `-server-port` and `-client-port` instead of just `-port`.
   ```
2. **Use separate flag sets for different packages and parse each set independently: `fs := flag.NewFlagSet("myapp", flag.ExitOnError); fs.String("verbose", "", "desc")`** (90% success)
   ```
   Use separate flag sets for different packages and parse each set independently: `fs := flag.NewFlagSet("myapp", flag.ExitOnError); fs.String("verbose", "", "desc")`
   ```

## Dead Ends

- **** — The default set is still used; panics persist unless all flags are on a custom set. (70% fail)
- **** — The flag name string is what matters; variable name change doesn't affect registration. (80% fail)
