# Managing Croc Configuration Persistence with the `--remember` Flag

> Learn how to manage croc configuration persistence using the --remember flag. Save command-line settings to a JSON file for automatic reloading on future croc transfers.

- Repository: [Zack/croc](https://github.com/schollz/croc)
- Tags: how-to-guide
- Published: 2026-07-26

---

**The `--remember` flag in croc saves your current command-line settings to a JSON file that is automatically reloaded on subsequent runs unless overridden.**

Croc, the open-source file transfer tool written by schollz, provides a global `--remember` flag that eliminates repetitive typing by persisting frequently used options. When you append this flag to a `send` or `receive` command, croc serializes the effective configuration to your user directory and restores it on future invocations. This article examines the internal implementation in [`src/cli/cli.go`](https://github.com/schollz/croc/blob/main/src/cli/cli.go) and [`src/models/constants.go`](https://github.com/schollz/croc/blob/main/src/models/constants.go) to explain exactly how configuration persistence works under the hood.

## Flag Definition and Early Detection

The `--remember` flag is defined as a global boolean option in the CLI application structure. In [`src/cli/cli.go`](https://github.com/schollz/croc/blob/main/src/cli/cli.go) at line 33, the flag is registered with the description "save these settings to reuse next time":

```go
&cli.BoolFlag{Name: "remember", Usage: "save these settings to reuse next time"}

```

Before the main command logic executes, croc scans the raw arguments to detect the flag early. In [`src/models/constants.go`](https://github.com/schollz/croc/blob/main/src/models/constants.go) (lines 61-78), the `init()` function iterates over `os.Args` looking for `--remember`. When found, it sets an internal boolean `doRemember` and creates a temporary marker file named `internal-dns` to signal "remember mode" for internal DNS handling:

```go
if flag == "--remember" { doRemember = true }
// ...
if doRemember { f, _ := os.Create(fname); f.Close() }

```

## Configuration File Locations

Croc uses helper functions to determine where to read and write persisted settings. According to [`src/cli/cli.go`](https://github.com/schollz/croc/blob/main/src/cli/cli.go) (lines 71-78), the tool distinguishes between sending and receiving configurations:

- **Send configurations**: Stored in [`send.json`](https://github.com/schollz/croc/blob/main/send.json) via `getSendConfigFile()`
- **Receive configurations**: Stored in [`receive.json`](https://github.com/schollz/croc/blob/main/receive.json) via `getReceiveConfigFile()`

These files reside in the user's configuration directory, typically `$XDG_CONFIG_HOME/croc` on Linux or `$HOME/.config/croc` on other systems, as resolved by `utils.GetConfigDir` in [`src/utils/utils.go`](https://github.com/schollz/croc/blob/main/src/utils/utils.go).

## Saving Configurations with Security

When `--remember` is active, croc invokes `saveConfig` (lines 27-56 in [`src/cli/cli.go`](https://github.com/schollz/croc/blob/main/src/cli/cli.go)) after a successful transfer. This function clears sensitive fields for security—specifically setting `SharedSecret` to an empty string if the code was not explicitly provided—then calls `writePrivateConfigFile` (lines 6-25) to serialize the `croc.Options` struct to JSON.

The file is created with restrictive **0600 permissions** (owner read/write only) using `os.OpenFile`:

```go
os.OpenFile(filename, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0o600)

```

This ensures that relay passwords and other persisted options remain accessible only to the current user.

## Loading and Merging Configurations

On subsequent runs where `--remember` is **not** supplied, croc automatically attempts to load the saved configuration. In [`src/cli/cli.go`](https://github.com/schollz/croc/blob/main/src/cli/cli.go), both the `send` command (lines 402-511) and `receive` command (lines 610-662) contain logic that checks for the existence of the JSON file:

```go
if errOpen == nil && !c.Bool("remember") {
    // Unmarshal saved options and merge with CLI flags
}

```

The merging logic prioritizes explicit command-line arguments. If you specify `--relay` on the command line, that value overrides the persisted setting. Only options not explicitly set are populated from the saved file.

## Practical Usage Examples

### Persist a Send Configuration

Save your preferred relay and password for future sends:

```bash
croc send --relay myrelay.example.com --pass secret123 --remember myfile.txt

```

Croc writes the effective options to [`send.json`](https://github.com/schollz/croc/blob/main/send.json), including the relay address and password, but omitting the shared secret code.

### Reuse Saved Settings

Send another file using the previously saved configuration:

```bash
croc send anotherfile.txt

```

Since `--remember` is absent, croc reads [`send.json`](https://github.com/schollz/croc/blob/main/send.json) and applies the relay and password without requiring you to type them again.

### Override a Persisted Option

Use a different relay for a single execution while updating the saved configuration:

```bash
croc send --relay otherrelay.example.com --remember thirdfile.txt

```

The command-line relay takes precedence for this transfer, and because `--remember` is present, the new configuration overwrites the old one in [`send.json`](https://github.com/schollz/croc/blob/main/send.json).

### Persist a Receive Configuration

Store your preferred output directory and overwrite settings for receiving files:

```bash
croc --remember receive

```

The first run prompts for the transfer code, then saves your options to [`receive.json`](https://github.com/schollz/croc/blob/main/receive.json). Subsequent `croc receive` commands without `--remember` will use those defaults.

## Summary

- The `--remember` flag in `schollz/croc` persists command-line options to JSON files ([`send.json`](https://github.com/schollz/croc/blob/main/send.json) or [`receive.json`](https://github.com/schollz/croc/blob/main/receive.json)) in the user configuration directory.
- **Explicit CLI arguments always override** persisted values; the saved configuration only fills in gaps.
- Configuration files are written with **0600 permissions** and intentionally exclude sensitive fields like shared secrets unless explicitly set.
- The implementation spans [`src/cli/cli.go`](https://github.com/schollz/croc/blob/main/src/cli/cli.go) for file I/O and [`src/models/constants.go`](https://github.com/schollz/croc/blob/main/src/models/constants.go) for early flag detection.
- To update saved settings, simply run the command again with `--remember` and your new preferred options.

## Frequently Asked Questions

### Where does croc store the remembered configuration?

Croc stores configurations in your system's user config directory, typically `$XDG_CONFIG_HOME/croc` or `$HOME/.config/croc`, in files named [`send.json`](https://github.com/schollz/croc/blob/main/send.json) and [`receive.json`](https://github.com/schollz/croc/blob/main/receive.json) respectively. The exact path is determined by the `utils.GetConfigDir` function in [`src/utils/utils.go`](https://github.com/schollz/croc/blob/main/src/utils/utils.go).

### What happens if I use --remember with different options?

Each time you invoke croc with `--remember`, the entire configuration file is overwritten with the current effective options. This means your most recent settings become the new defaults for future runs. If you want to temporarily change a setting without updating the saved configuration, omit the `--remember` flag and explicitly specify the option on the command line.

### Are passwords and secret codes saved in the configuration file?

Relay passwords (`--pass`) are saved, but shared secret codes (`--code`) are automatically cleared from the persisted struct before writing to disk unless you explicitly provided them on the command line. Additionally, the JSON files are created with **0600 permissions** (readable only by the owner) to minimize exposure of saved credentials.

### How do I stop croc from using saved settings?

To ignore the persisted configuration for a specific run, simply ensure `--remember` is not present and explicitly provide all options you want to override on the command line. There is currently no dedicated "clear" or "forget" command; to effectively reset to defaults, you can manually delete the [`send.json`](https://github.com/schollz/croc/blob/main/send.json) or [`receive.json`](https://github.com/schollz/croc/blob/main/receive.json) files from your croc configuration directory.