Fix Scattered AI Coding Tool Configuration With One Command: API Endpoints, Keys, and Model Names

    AI coding tools all let you point at a custom endpoint, but each one stores the endpoint, API key, and model name in a different place and format — JSON `env` blocks, TOML provider tables, shell environment variables, or a desktop app's own config store. This article maps where those settings live across macOS, Linux, and Windows, explains the failure modes of editing them by hand (including a subtle TOML table-scope trap that silently reverts your model), and walks through the design of an interactive configuration wizard that merges changes in place, tightens file permissions to 0600, and backs up before every write. It also covers safe installation with checksum verification, and how teams can move secrets into a managed key service.

    AI coding tools have become a daily assistant for many developers over the past couple of years. Mainstream tools generally let you override the API base URL, the API key, and the model name, which makes it easy to connect a self-hosted model service, a cloud vendor’s model service, or an internal enterprise gateway. But “they all support customization” does not mean “they configure it the same way”: some tools write the endpoint into an environment-variable section of a user-level JSON config, some use a TOML provider table, some read only system environment variables, and desktop apps maintain their own config store inside their own directory.

    The endpoint, the key, and the model name are all mandatory, yet the format differs every time. Setting up a new tool or switching model services usually means reading docs, hunting for paths, and figuring out which format applies. Miss a field, mistype a value, or leave permissions too loose, and at best the tool reports “authentication failed” or “model not found”; at worst, the key sits in a file in plaintext.

    Instead of editing configs by hand every time, one command can do the job: a configuration management tool that locates the right file, preserves its existing format, tightens permissions, and backs up automatically before making changes. This article first lays out what these configs have in common, then covers the design and implementation of an interactive configuration wizard, plus notes on installation verification and key management.

    1. Why the configuration is so scattered

    The first source of fragmentation is where the configuration lives. For something as simple as setting an API address, a tool may use one or more of four different carriers:

    • An environment-variable section in a user-level JSON config: the tool ships a config file with a reserved environment-variable object that it injects when spawning child processes.
    • A TOML config file: a common format for programmatic configuration, it supports comments and lets you organize different parts into separate tables.
    • System environment variables: the most universal option, reading and writing the user environment or shell startup files directly.
    • A desktop app’s dedicated config store: independent of CLI tools and located in the application data directory.

    The second is platform differences. On macOS, Linux, and Windows, the meaning of “home directory,” the way environment variables are stored, and the location of a desktop app’s config all differ, so the same setting maps to a different path on each system.

    Finally, some tools share one config between their CLI, desktop, and IDE extension versions, while others keep a separate one for each. Fixing the CLI config does not guarantee the desktop app picks it up, and vice versa.

    These differences are not accidental; they follow from what each category of tool is designed for:

    Tool type Typical config shape Design rationale
    CLI coding tools User-level TOML file, or an env section in a JSON config Config files are easy to generate programmatically, to annotate with comments, and to share across a team; a JSON env section takes effect without touching the shell
    Desktop AI apps Built-in config store (some support third-party inference services) Isolated from CLI tools so they do not interfere with each other
    CLI tools that rely on env vars System environment variables, or export lines in shell startup files No extra config parsing logic, and a natural fit for scripts and containers
    AI plugins embedded in an IDE Often share the config with the CLI tool Avoids making users configure the same thing twice

    With that logic in mind, one rule covers all of them: every AI coding tool that supports a custom endpoint requires the developer to supply the endpoint URL, the key, and the model name correctly — they only differ in where those three values are stored, in what format, and how they take effect. The goal of configuration management is a single entry point that guarantees all three values are written to the place each tool actually reads.

    2. Where each tool keeps its config, and cross-platform paths

    1. User-level config files: two mainstream formats

    User-level config files usually live in a hidden directory under the home directory, and two kinds dominate.

    An env section in a JSON config. Some CLI coding tools write the endpoint and key into the env object of settings.json, which effectively declares a set of “tool-specific environment variables”:

    1. {
    2. "env": {
    3. "ANTHROPIC_BASE_URL": "https://your-gateway.example.com",
    4. "ANTHROPIC_AUTH_TOKEN": "<your key>"
    5. }
    6. }

    A provider table in a TOML config. Other CLI tools use TOML, define a custom provider in a model_provider table, and then point model at that provider:

    1. # This line must appear before the first [table header]; it belongs to the root table
    2. model = "your-model"
    3. [model_providers.custom]
    4. name = "custom"
    5. base_url = "https://your-gateway.example.com"
    6. env_key = "CUSTOM_API_KEY"

    There is a syntax trap here that must be emphasized: in TOML, a table header stays in effect until the next header. If model is written after [model_providers.custom], it is parsed as a sub-key of that table rather than a root-level field. The tool cannot find model in the root table and falls back to the default model. The typical symptom: the endpoint is clearly correct, but the model is still the default one — and it is hard to see why at a glance.

    2. A desktop app’s independent config store

    Most AI desktop apps create their own application data directory after installation, with the endpoint and related settings stored in a config library subdirectory. These apps usually do not read the CLI tools’ config files, so even when a CLI tool already points at a custom endpoint, the desktop app still needs to be configured separately.

    3. Cross-platform path reference

    The table below summarizes common config locations. The paths are examples; always defer to each tool’s official documentation. Think of it as a unified configuration map:

    Tool type macOS / Linux Windows
    TOML-based CLI tools (including desktop and IDE variants that share the config) ~/.config.toml %USERPROFILE%\.config.toml
    JSON-based CLI tools ~.<tool>/settings.json %USERPROFILE%\.<tool>\settings.json
    Desktop app config library macOS: ~/Library/Application Support/Claude-3p/; Linux: ~/.config/Claude-3p/ %APPDATA%\Claude\configLibrary\
    CLI tools that rely on env vars ~.<tool>/settings.json plus env vars in shell startup files %USERPROFILE%\.<tool>\settings.json plus user environment variables

    (Claude-3p in the config library paths is an example; the directory name depends on the actual product.)

    A few points matter when reading this table:

    1. ~ on Windows: in a shell, ~ usually corresponds to %USERPROFILE% on Windows. In code, use the platform-provided home directory API rather than hardcoding a drive letter or username.
    2. Store-installed desktop apps: desktop apps may also be installed from an application store. Their data directory is not necessarily in the locations listed above, and the directory name may carry an extra suffix, so these cases need to be verified individually.
    3. What is special about env-var-based tools: besides settings.json, these tools also require the auth mode to be set explicitly to API key. Developers must write the endpoint and key into a shell startup file or into user environment variables. GUI applications on macOS are launched by the system by default and do not read shell startup files, so the variables need to go into the user environment or be injected with launchctl setenv; on Windows, use user-level environment variables. Follow the tool’s official instructions for the specifics.

    3. The pain points of editing configs by hand

    Even after you find the config file, manual editing tends to run into the following problems:

    1. Locations are hard to remember and formats differ: JSON, TOML, and environment variables are three mutually incompatible syntaxes, so every new tool means reading the docs again.
    2. Structural traps are subtle: TOML root-table vs. sub-table scoping, and the fact that env vars “must be set before the process starts,” both run counter to intuition, and error messages do not necessarily point at the real cause.
    3. Edits do not survive: many tools rewrite the config file when saving settings, which can wipe out comments and formatting the user wrote by hand, making a carefully maintained config hard to keep over time.
    4. Keeping multiple tools consistent is hard: when several tools are in use, rotating the endpoint or key means editing each one separately. Miss one, and that tool keeps using the old key.
    5. Security risks: keys are stored in plaintext, and if the file has default 0644 permissions (readable by other users on the same machine), or if it is edited with something like Notepad or echo redirection that alters permissions, the exposure risk increases noticeably. On top of that, the same variable may exist in the config file, in a shell startup file, and in the system environment at once, with precedence varying by tool. Editing the wrong place can mean the change does not take effect, or even two sets of keys coexisting — which is hard to troubleshoot.

    All of these pain points share one root cause: the tools each speak their own dialect and leave the reconciliation work to the developer. Handling these problems centrally with a configuration management tool is the more sensible approach.

    4. One command to configure everything: an interactive wizard

    The idea is straightforward: hand the repetitive work — path resolution, format conversion, merging, permission setting, and backups — to a single configuration management tool. The typical CLI experience is: run one command to launch the interactive wizard, press Enter to accept the default tool; select other tools by their number; enter the endpoint, key, and model name; confirm, and the values are written automatically after a backup is created.

    A good wizard should meet these requirements:

    • Only touch the selected tool by default: handle only the most common configuration by default (for example, the TOML config shared by the CLI and desktop versions), so a single operation does not affect every tool at once.
    • Merge writes: apply incremental changes on top of the existing config, keeping all original fields and comments intact.
    • Tighten permissions: files written with 0600, so only the owner can read and write.
    • Reversible: back up automatically before every write, with one-command restore.
    • Lightweight and easy to distribute: a single executable that is easy to install.

    Here is what a typical configuration run looks like:

    1. $ configure
    2. Select the tool to configure (press Enter to accept the default):
    3. 1) CLI coding tool / desktop app (shared ~/.config.toml)
    4. 2) Coding assistant (~.<tool>/settings.json)
    5. 3) CLI tool that relies on environment variables
    6. 4) AI desktop app config library
    7. > [1]
    8. Custom endpoint [press Enter to keep the current value]: https://your-gateway.example.com
    9. API key [input is hidden]: ************
    10. Model name [your-model]:
    11. About to write: ~/.config.toml (backed up to ~/.config.toml.bak-20250612-101530)
    12. Done: the configuration is in effect. Restart the tool.

    The wizard itself can be a statically compiled Go binary with no third-party dependencies, released under the permissive MIT license so it is easy to audit and extend. An interactive prompt library can provide the selection menu and password-style input, format-preserving JSON and TOML libraries can handle config reads and writes, and file operations can use the standard library directly.

    5. Implementation notes: get “correct, non-destructive, reversible” right

    The interactive experience is only the surface. What really determines whether the tool is reliable is the write strategy.

    1. Merge writes and preserve existing content

    • JSON: parse while preserving order, modify by path, and output as-is. Only the target keys in the env section are changed; missing keys are added as needed; key order, indentation style, and spacing are preserved as much as possible, avoiding the format drift that full serialization introduces.
    • TOML: pick a parser library that preserves comments and formatting, and modify target keys semantically rather than with plain text search-and-replace. When inserting content, specify explicitly which table it belongs to, so that root-level fields such as model always stay before the first table header.
    • Idempotency: compare old and new values before writing. If nothing changed, skip the write to avoid piling up redundant backup files on repeated runs.

    2. Only touch the selected tool

    Each tool maps to an independent configuration task, and the default task handles only the most common configuration. This prevents the surprise of “I only wanted to change the CLI tool’s endpoint, but the desktop app’s config changed too,” and keeps the scope of each change clear and controlled.

    3. Permissions and security

    • After creating or overwriting a config file, set permissions to 0600 immediately; on Windows, achieve equivalent access control through file ACLs.
    • Write using “temp file in the same directory + atomic replace” to prevent a half-written file if the process is interrupted mid-write.
    • Try to parse the original file before merging. If it is already corrupted or invalid, abort and notify the user rather than overwriting their existing config with new content.
    • Hide key input in the terminal by default, and show only the first few characters in logs for verification.

    Reference write logic (illustrative):

    1. func writeConfig(path string, patch map[string]any) error {
    2. old, err := os.ReadFile(path)
    3. if err != nil && !errors.Is(err, fs.ErrNotExist) {
    4. return fmt.Errorf("failed to read config, write aborted: %w", err)
    5. }
    6. // If the original file exists, parse and validate it first; abort if it is broken
    7. // so we never overwrite the user's config
    8. base, err := parse(old)
    9. if err != nil {
    10. return fmt.Errorf("the existing config cannot be parsed, please fix it first: %w", err)
    11. }
    12. // Merge: only the keys in patch change; other fields and comments stay as they are
    13. merged, err := merge(base, patch)
    14. // Temp file in the same directory + atomic replace, so an interrupted
    15. // write never leaves a half-written file behind
    16. tmp, err := os.CreateTemp(filepath.Dir(path), ".cfg-*")
    17. if err != nil {
    18. return err
    19. }
    20. defer os.Remove(tmp.Name())
    21. if _, err := tmp.Write(merged); err != nil {
    22. tmp.Close()
    23. return err
    24. }
    25. if err := tmp.Close(); err != nil {
    26. return err
    27. }
    28. // 0600: owner read/write only, so other users on the same machine cannot read the key
    29. if err := os.Chmod(tmp.Name(), 0600); err != nil {
    30. return err
    31. }
    32. return os.Rename(tmp.Name(), path)
    33. }

    4. Backups and restore

    Before writing, create a backup named after the original file plus a timestamp (for example config.toml.bak-20250612-101530), and set the backup to 0600 as well. Provide subcommands to list, restore, and prune old backups so that a single mistake can be rolled back.

    For shell startup files, a safer approach is to have the tool maintain a separate fragment — for example, writing variables such as API_KEY and API_BASE_URL into ~/.config/shell-ai-env and sourcing it from the startup file. Restoring then means removing just that one line, leaving the user’s own scripts untouched.

    5. Cross-platform adaptation

    • Path resolution: resolve the home directory through the platform API in one place. On Linux, follow the XDG conventions (environment variables prefixed with XDG_CONFIG_HOME); on macOS and Windows, use the respective system APIs.
    • Windows environment variables: changing user environment variables on Windows requires calling the corresponding system API and broadcasting a notification of the environment change. Terminals and editors that are already open will not pick up the new values automatically; a restart is required. The wizard should tell the user this when it finishes.
    • Backup naming: Windows filenames are case-insensitive, so backup names only need to avoid colliding with existing files.

    6. Installation and verification: do not run one command blindly

    Installing with a single command is convenient, but “download a script and pipe it into a shell” carries its own risk. A safer sequence looks like this:

    1. Prefer a trusted mirror: the install script can fetch the binary from a trusted mirror first and fall back to the upstream repository, printing the URL actually used so the process is transparent and auditable.
    2. Download first, verify, then execute: download the script and verify its hash before running it by hand. A reference approach (run the first block, compare the SHA-256, then run the second):

      1. # 1) Download the script and verify its hash; do not execute it directly
      2. curl -fsSL https://<trusted-url>/install.sh -o /tmp/install.sh
      3. sha256sum /tmp/install.sh # compare against the officially published hash
      4. # 2) Run it only after the hash matches
      5. sh /tmp/install.sh
    3. Verify the binary: before writing to disk, the install script should verify the binary’s SHA-256 against the checksum list shipped with the release (checksums.txt). Only after the terminal reports that the checksum matches should the binary be placed in a PATH directory and given execute permission.

    4. Choose a safe install location: do not make a broad-permission sudo the default. If the tool can be installed into a user-level directory such as ~/.local/bin, there is no need to write to system directories — that keeps any flaw in the script from being amplified into a system-wide risk.

    7. Key management and team collaboration

    The wizard solves the single-machine problem. A team environment needs another layer of key governance:

    • Keep keys out of the repository: the key field can remain in the config file, but the actual value should be injected dynamically by a key management service, so plaintext keys do not spread along with the codebase.
    • Least privilege: issue separate keys per tool or per project, with quotas and expiry dates, so a leak only requires rotating the affected key.
    • Traceable changes: put config changes under version control with a review process, and use common cloud capabilities such as logging and monitoring alerts to spot unusual call sources quickly.
    • Manage it centrally with cloud services: in a cloud environment, common capabilities such as API gateways, object storage, and key management can be combined. For example, the team reaches the model service through a unified gateway that handles authentication and rate limiting on the gateway side; config backups go to object storage with a lifecycle policy; config drift and authentication failures reach the owner through monitoring alerts. Cloud products such as object storage, log services, and monitoring alerts from Baidu AI Cloud can cover this kind of baseline need.

    8. Summary

    The configuration differences among AI coding tools come down to an ecosystem where “one tool means one config”: JSON env sections, TOML provider tables, system environment variables, and desktop app config stores each have their own syntax and path rules.

    Rather than relying on memory and manual edits every time, hand the configuration process to a unified interactive wizard. Its key capabilities come down to five points:

    1. Locate the correct config file by tool type and handle cross-platform paths.
    2. Merge writes, preserving existing fields and comments.
    3. Tighten file permissions to 0600 and use atomic writes.
    4. Back up automatically before writing, with one-command restore.
    5. During installation, download and verify checksums before executing.

    For developers who use several AI coding tools at once, this means adding a tool or rotating a key can be done with one command, with a controlled scope of change and the ability to roll back at any time. For teams, moving keys into a managed key service and pairing that with monitoring and alerting is what takes you from “the config works” to “the config is trustworthy.”