Building a Local Command-Line AI Assistant with AI Coding Tools: A Practical Guide
This guide walks through the process of building a local, multi-model command-line AI assistant using the autonomous mode of AI coding tools. It covers environment preparation, automated code generation, configuration for cloud and local models, packaging into standalone executables across Windows, macOS, and Linux, troubleshooting dependency installation issues, and security considerations for handling sensitive data, particularly in digital forensics scenarios.
With the widespread adoption of large language models, integrating AI capabilities into daily development workflows has become a common way to boost productivity. For developers and digital forensics professionals, a command-line AI assistant that runs locally and supports switching between different underlying models can reduce repetitive tasks while providing better control over data flow. This article demonstrates how to generate a multi-model command-line assistant from an empty directory using the autonomous mode of AI coding tools, and how to package it into executable programs that run on target machines.
1. Environment Preparation and Planning
Before letting the coding tool generate code automatically, confirm three categories of prerequisites: the tool itself, the runtime environment, and the model access method.
1.1 AI Coding Tool
Choose an AI coding tool or AI-powered IDE that offers a fully autonomous mode. These tools can decompose natural language requirements into tasks, write code, execute commands, and fix errors. Before use, verify the tool version, the entry point for the autonomous mode, and whether it will prompt for confirmation before executing commands. Since interfaces and feature names vary across products, always refer to the official documentation for your specific version.
1.2 Runtime Environment
This guide uses Node.js. Install the latest LTS version (version 18 or higher). After installation, run the following commands in a terminal to confirm both are available:
node -vnpm -v
If you want the final program to run without a Node.js runtime installed on the target machine, packaging tools can generate standalone executables—details are covered in Section 4.
1.3 Model Access Methods
The assistant needs a callable model service, with two common options:
- Cloud Models: Create an API key in the cloud provider’s console, and note the endpoint (base_url) and model name. Many providers, including Baidu AI Cloud, offer services compatible with the OpenAI API format.
- Local Models: Install a local model runtime (e.g., Ollama), pull the desired model, and call it via a local endpoint. Since data never leaves the machine, this is suitable for handling sensitive material.
1.4 Network and Dependency Source Check
During the build and run phases, package downloads and model API access may be subject to network restrictions. Verify the following before starting:
node -vandnpm -vexecute successfully in the terminal.- The model service endpoint is reachable.
- Dependencies can be downloaded from the default or a mirror registry.
If a proxy is required, use only the proxy settings permitted by your organization or project.
2. Driving the Tool for Automated Build
2.1 Prepare a Working Directory and Switch Modes
Create a new empty directory on your local machine for the project files. Open this directory in the AI coding tool and switch to fully autonomous mode. The tool will create and modify files within this directory, so ensure it contains no other files you need to keep.
2.2 Issue a Structured Requirement
The more specific the requirement description, the closer the generated result will match expectations. Below is a ready-to-use instruction template:
Write a command-line AI assistant in Node.js in the current directory. Requirements:
- Read three fields from config.json at startup: base_url, api_key, and model;
- Send requests through an OpenAI-compatible chat endpoint with streaming output support;
- Exit the program when the user enters “exit”;
- The API key must not be hardcoded in the source code—only read from the config file;
- Provide a README explaining the installation, configuration, and running steps;
- Use pkg to generate executable files for Windows, macOS, and Linux.
2.3 Confirm Key Decision Points
After you submit the instruction, the tool typically breaks the work into steps: initializing the project, installing dependencies, writing interaction logic, generating configuration files, and packaging. Confirmation prompts may appear during this process, for example, when choosing a dependency source or overwriting existing files. Pause and review carefully when the tool asks to:
- Write the API key into the code or commit it to a version control repository.
- Delete or overwrite existing files.
- Execute global installations with administrative privileges.
2.4 Post-Generation Checks
Once the automatic generation is complete, manually verify three things: search the source code for any leaked keys, confirm that the dependencies listed in package.json match what the code actually imports, and run a full conversation in the terminal to verify streaming output and the exit function work correctly.
3. Configuration Files and Multi-Model Integration
The API key should be stored in a separate configuration file, never in the source code. Recommended fields for the configuration file:
base_url: The model service endpoint.api_key: The access key.model: The model name to call.
Example for a cloud model—replace the URL and model name with the actual values provided by your service provider:
{"base_url": "https://your-provider.example.com/v1","api_key": "enter your key","model": "enter the provider's model name"}
When running a local model with Ollama, the endpoint is typically http://127.0.0.1:11434/v1. Ollama’s compatibility interface does not validate the key, but the program requires a non-empty value, so any placeholder string will work. Replace the model name with a model you have pulled locally:
{"base_url": "http://127.0.0.1:11434/v1","api_key": "local-placeholder","model": "enter a locally pulled model name"}
To switch between the two model types, save two configuration files—for example, config.cloud.json and config.local.json—and have the program accept a startup argument to specify which file to load. If the generated program does not support this parameter, either add this requirement in the instruction and regenerate, or manually replace config.json each time.
Key management notes for the configuration file:
- Add config.json to .gitignore to keep it out of the version control repository.
- On macOS and Linux, run
chmod 600 config.jsonto restrict access to the current user only. - Assign the key the minimum required permissions in the cloud console and rotate it periodically. If you suspect a leak, revoke the key immediately.
4. Packaging, Cross-Platform Builds, and Portable Deployment
4.1 Understanding Build Artifacts
Packaging tools generate binary files specific to each target operating system, not a universal script that runs on every platform. With pkg, you can specify multiple target platforms from a single machine using the --targets flag, for example:
npx pkg . --targets node18-win-x64,node18-macos-x64,node18-linux-x64 --output dist/ai-assistant
The Node.js version and platform identifiers in the command must match the actual version used by your project. Other packaging tools, such as PyInstaller, typically require separate builds on each target system.
4.2 Runtime Dependency Boundaries
Standalone executables produced by packaging tools include the Node.js runtime, so the target machine does not need Node.js installed. If you instead distribute source code or plain scripts, the target machine must have the corresponding runtime and dependencies installed. These two scenarios must be treated separately.
4.3 Windows Startup Script
A batch file is Windows-specific: it launches the compiled executable and passes the configuration file path to the program. It does not replace the packaging process. Place it next to the executable and config.json in the same directory:
@echo off"%~dp0ai-assistant-win.exe" --config "%~dp0config.json"pause
4.4 USB Drive or Portable Storage
After copying the executable, startup script, and configuration file to a USB drive, the program can run on another machine provided the following conditions are met:
- The target machine can reach the model service endpoint. If using a local model, the model service must also be running on that machine.
- The target machine’s operating system matches the executable’s platform.
- The API key travels with the USB drive, creating a leak risk. When carrying sensitive work environments, consider encrypting the USB drive or carrying only a template file without the key and filling it in at the scene.
After deployment, verify the following:
- The program launches and reads the specified configuration file.
- A complete Q&A exchange works with normal output.
- Entering “exit” terminates the program cleanly.
- With the network disconnected, a local model still responds; a cloud model should show a clear connection error.
5. Troubleshooting Dependency Installation Failures
When automated installation fails, work through the following steps in order instead of retrying repeatedly.
5.1 Use the Correct Install Command
If a package-lock.json exists in the project directory, use npm ci first. It installs strictly from the lock file, producing reproducible results:
npm ci
Without a lock file, use npm install and commit the resulting package-lock.json afterward.
5.2 Switch the Registry Mirror
When downloads time out or connections are reset, switching to a mirror registry on a temporary basis may help. The following uses the npmmirror registry as an example—check the mirror provider’s official documentation for the current address:
npm config set registry https://registry.npmmirror.comnpm config get registry
After installation completes, run npm config set registry https://registry.npmjs.org to restore the official registry. If your project has fixed mirror requirements, document them in the project rather than keeping them only in your personal environment.
5.3 Check Proxy Settings
Run npm config get proxy and npm config get https-proxy, and also check the HTTP_PROXY and HTTPS_PROXY environment variables for consistency with your current network configuration. Incorrect proxy settings cause all downloads to fail in a way that looks identical to an unreachable upstream server.
5.4 Resolve Permission Errors
When EACCES or permission denied errors occur, avoid running the terminal as an administrator. Instead, check the ownership of the project directory and fix the permissions of the global install directory. Using sudo for npm installs writes packages to system directories with elevated privileges, which carries unnecessary risk.
5.5 Resolve Version Conflicts
If a dependency reports a version incompatibility, inspect the dependency tree with npm ls package-name to find the package causing the conflict. Then pin a compatible version in package.json, delete node_modules, and run npm ci again. Keep a change log for each modification so you can roll back if needed.
5.6 Save Installation Logs
For intermittent failures, save the output to a file to compare results across attempts:
npm ci > install.log 2>&1
Logs may contain paths or proxy addresses—remove sensitive information before sharing them.
6. Security and Usage Boundaries in Forensics Scenarios
Digital forensics work has strict requirements for data origin, transmission, and audit trails. Before using an AI assistant in such contexts, clarify the following boundaries:
Confirm authorization and data scope. Only feed legally authorized materials to the AI assistant. If the material contains personally identifiable information, de-identify it according to your organization’s policies first.
Distinguish between cloud and local processing. When using cloud models, prompts and context are sent to the service provider. Before sending original evidence, chat logs, or identity information to an external endpoint, review the provider’s data processing terms and obtain organizational approval. For case-related material, prioritize local models.
Protect original evidence. When analyzing with the assistant, use copies only—never modify the original evidence directly. Compute hash values before and after analysis and record them in the work log for later verification.
Control logs and records. Conversation history, cache files, and log files generated by the assistant may contain sensitive content. Clean them up according to policy after the session, or store them encrypted in a controlled environment.
7. Conclusion
With the autonomous mode of AI coding tools, developers can offload a substantial amount of boilerplate code and basic configuration to the tool, leaving only the requirement description, result verification, and confirmation of critical steps. For the command-line assistant described in this article, this approach quickly yields a working prototype.
The generated result still requires manual verification. Check whether the code contains any residual API keys, whether dependencies match the lock file, and whether the packaged executables actually run on the target machines. When forensic material is involved, also confirm the authorization scope and data flow before deciding between cloud models and local models.
