r/CLI • • 1d ago

Which CLI setting should never be remembered from the last run?

Remembering a preferred output format feels helpful. Remembering the last server or a destructive option feels like a very different promise.

Where do you draw the line between a convenient default and a surprise waiting to happen? I'd love a concrete example of a setting a tool should remember, and one it should always make explicit.

0 Upvotes

6 comments sorted by

3

u/obhect88 1d ago

Not sure what you’re suggesting, because “remembering” makes me think that the CLI saw some flag, wrote it to file or someplace persistent, then the next time that you run, it automatically injects that?

If that is what you are suggesting, I would say, never. A big part of this is, a CLI may be used from an interactive shell, or it may be used from a script, and learning from a script feels like it would lead to big surprises.

For the CLIs that I have built, I’ve had them look for a config file at an overridable but default location, and allow setting defaults in there.

2

u/illegal_appendix 1d ago

Output format or colors, sure, remember those. Anything that decides what gets changed should never carry over though, like which server it hits or a force flag. If I forced a delete yesterday I don't want that quietly turned on again today.

2

u/funkdefied 17h ago

CLIs should be as stateless as possible. They shouldn’t “remember” anything except auth stuff. “Remembering” user preferences is what configs are for. “Remembering” last run commands is handled by shell history. 

TUIs are different, since they are strictly run interactively. 

1

u/gumnos 1d ago

(assuming you're talking about remembering settings rather than default settings compiled into the application itself)

a convenient default is something I've set/requested explicitly. This can take the form of a shell alias/function wrapper that sets various command-line arguments the way I want them (e.g. alias psa='ps auxww'). Or it can be setting those defaults in a config file (e.g. my ~/.vimrc) or save-state file (e.g. Vim's :mksession and corresponding :source sessionfile.txt commands). Or it can be enabling a "remember my current settings" option (my fluxbox window-manager lets me choose "Remember→{window position,workspace,head,dimensions,decorations,…}" so that the next time I open the same window/application, it comes back as I had it previously) .

I don't want my nightly cron job to fail or produce unexpected output just because some time during the day I ran the command with (temporary-intended) different options and those got remembered, getting applied to the cron job unintentionally.

1

u/HelicopterUpbeat5199 15h ago

I think your question could be better asked as "what should go in the config file vs on the command line" to me.

I think it just really depends on the application. The same thing can be innocuous or deadly depending on context.

1

u/Automatic-Fan-3993 9h ago

resume is where i had to pick in the agent terminal i build. the session id is remembered, that's the point of resume. the permission mode isn't: every resume reads the bypass toggle as it is right now, not what the session started with. otherwise you switch bypass off, resume an old session and it's quietly back on.

and the stored id gets checked on replay. one starting with a dash is refused, since --dangerously-skip-permissions in that field would land on the command line as a flag.