Building a Portable Terminal AI Assistant with an AI Coding Tool

    This guide shows developers how to use an AI coding tool to build a terminal AI assistant that runs from a USB drive on Windows without a Node.js installation. It covers generating the project, creating a double-click start script, and storing the API key locally.

    This guide is for developers who know the command line and want to carry a terminal AI assistant on a USB drive. By the end, you will be able to do three things: generate the project with an AI coding tool, run the project by double-clicking on a Windows computer that does not have Node.js installed, and store your API key securely on the local machine.

    Prerequisites: a 64-bit Windows 10 or Windows 11 computer, access to a large language model service, and an API key for that service. The .bat script in this guide works only on Windows. macOS and Linux require a shell script instead, which this guide does not cover.

    Why a Portable Terminal AI Assistant

    The command line is a core tool for everyday development work. Once a large language model is connected to the terminal, it can generate code, explain error messages, and write scripts. Many terminal AI assistants, however, depend on a specific runtime environment and a number of dependencies. These tools often cannot run directly when you switch between computers, work offline, or handle problems on a machine with strict network security requirements.

    Packaging the assistant as a single folder that you can carry on a USB drive solves this problem. Plug the drive into any Windows computer and double-click to run it. The steps below let the AI coding tool do most of the coding work while you set the direction and check the results.

    How to Choose the Tool and Model

    The AI coding tool must have an automatic execution mode. In this mode, the tool can read and write files, run commands, and install dependencies. This means the tool runs commands on your computer, so read every confirmation prompt carefully.

    Choose the model based on your actual tasks. Test candidate models with three typical tasks: generating a small script, explaining an error log, and writing a description of command-line arguments. Compare the output quality, the price per million tokens, and the response speed of each model. If the tool offers an “Auto” mode, switch to manually selecting one fixed model. This avoids differences in output style between models and keeps the generated code consistent.

    The build machine needs the Node.js LTS release, preferably 20.x or 22.x. After installing it, run the following two commands in the command line. If each command prints a version number, the environment is ready:

    1. node -v
    2. npm -v

    How to Create the Workspace and Give the Requirements

    In File Explorer, create an empty folder, for example D:\portable-ai-cli. Open this folder with the AI coding tool, switch to automatic execution mode, and enter your requirements. The following prompt is ready to use. You can change the model service URL and the command name to suit your needs:

    1. Create a Node.js command-line application named portable-ai-cli in the current directory. Requirements:
    2. 1. On startup, read config/config.json. If the file does not exist, prompt me to enter the API base URL, model name, and API key, and save them to that file.
    3. 2. Communicate with the model through an OpenAI-compatible /chat/completions endpoint. Support multi-turn conversations, and exit when the user enters exit.
    4. 3. Provide start.bat in the project root so it runs on double-click. The script should prefer runtime\node.exe and fall back to the system-installed node if that file does not exist.
    5. 4. Do not depend on globally installed packages. If third-party packages are needed, install them into node_modules inside the project.
    6. 5. Add config/ and node_modules/ to .gitignore.

    This prompt specifies how the program runs, where the configuration is stored, the scope of dependencies, and which sensitive files are excluded. The more specific the prompt, the more control you have over the result.

    How to Handle Confirmation Prompts During Execution

    While running, the tool may show options for you to confirm, such as installing a specific version of a library or overwriting an existing file. Follow these guidelines.

    For dependency installation, the default first option is usually fine. Before overwriting a file, check the file name and path carefully. If the tool asks to delete or overwrite a file outside the workspace, reject the request and ask the tool to explain why.

    When the tool finishes, check the file structure it generated. A normal project directory looks like this:

    1. portable-ai-cli/
    2. ├── package.json
    3. ├── src/
    4. │ └── index.js
    5. ├── config/
    6. │ └── config.json (generated after the first run, do not commit)
    7. ├── runtime/
    8. │ └── node.exe (optional, place it here if the target machine has no Node.js)
    9. ├── node_modules/ (present only when third-party packages are used)
    10. ├── start.bat
    11. └── .gitignore

    The start command in package.json should look similar to this:

    1. {
    2. "name": "portable-ai-cli",
    3. "version": "1.0.0",
    4. "main": "src/index.js",
    5. "scripts": {
    6. "start": "node src/index.js"
    7. }
    8. }

    The program creates the configuration file on its first run. Its format is roughly as follows. Replace baseUrl and model with the actual values for your service:

    1. {
    2. "baseUrl": "https://api.example.com/v1",
    3. "model": "your-model-name",
    4. "apiKey": "sk-xxxxxxxx"
    5. }

    How to Write a .bat Script That Starts on Double-Click

    start.bat is the entry point of the portable version. If the tool does not generate a suitable script, you can create it manually with the following content:

    1. @echo off
    2. chcp 65001 >nul
    3. setlocal
    4. cd /d "%~dp0"
    5. if exist "runtime\node.exe" (
    6. set "NODE=runtime\node.exe"
    7. ) else (
    8. set "NODE=node"
    9. )
    10. "%NODE%" src\index.js %*
    11. pause

    Here is what each line does. chcp 65001 switches the console to UTF-8 encoding, which prevents Chinese text from displaying as garbled characters. cd /d "%~dp0" switches the working directory to the folder that contains the script, so the script runs correctly no matter where you double-click it from.