Consolidate file storage locations across platforms
Problem
Nanocoder currently saves files to multiple scattered locations across the filesystem. This is confusing for users and inconsistent across platforms.
This is a prerequisite for #51 (/resume command) - we should consolidate storage locations before adding session persistence, rather than creating yet another directory (~/.nanocoder-sessions/).
Current File Locations
macOS (darwin)
| Purpose | Current Path |
|---|---|
| Config | ~/Library/Preferences/nanocoder/ |
| App Data | ~/Library/Application Support/nanocoder/ |
| Logs | ~/Library/Preferences/nanocoder/logs/ |
| Cache | ~/Library/Caches/nanocoder/ |
| Sessions (proposed #51) | ~/.nanocoder-sessions/ |
Actual contents in Preferences (everything ends up here):
agents.config.json- Provider configurationnanocoder-preferences.json- User preferences.nano-coder-history- Command historylogs/- Debug logs
Application Support is EMPTY (usage.json should go here but isn't being created)
Linux
| Purpose | Current Path |
|---|---|
| Config | ~/.config/nanocoder/ |
| App Data | ~/.local/share/nanocoder/ |
| Logs | ~/.config/nanocoder/logs/ |
| Cache | ~/.cache/nanocoder/ |
| Sessions (proposed #51) | ~/.nanocoder-sessions/ |
Windows
| Purpose | Current Path |
|---|---|
| Config | %APPDATA%\nanocoder\ |
| App Data | %APPDATA%\nanocoder\ |
| Logs | %APPDATA%\nanocoder\logs\ |
| Cache | %LOCALAPPDATA%\nanocoder\ (via xdg-basedir) |
| Sessions (proposed #51) | ~/.nanocoder-sessions/ |
Environment Variable Overrides
| Variable | Purpose | Used By |
|---|---|---|
NANOCODER_CONFIG_DIR |
Override config path | getConfigPath() |
NANOCODER_DATA_DIR |
Override app data path | getAppDataPath() |
NANOCODER_LOG_DIR |
Override log directory | getDefaultLogDirectory() |
NANOCODER_LOG_LEVEL |
Set log level | Logger config |
NANOCODER_LOG_TO_FILE |
Enable file logging | Transports |
NANOCODER_LOG_DISABLE_FILE |
Disable file logging | Transports |
NANOCODER_LOG_TRANSPORTS |
Select transports | Transports |
XDG_CONFIG_HOME |
XDG config override | getConfigPath() (Linux) |
XDG_DATA_HOME |
XDG data override | getAppDataPath() |
XDG_CACHE_HOME |
XDG cache override | models-cache.ts |
Problems
- macOS: Uses
~/Library/Preferences/which is meant for.plistfiles only, not logs/data - Split locations: Config and data are in different directories on macOS/Linux
- Inconsistent: Windows correctly uses one location, others don't
- Proliferating: Issue #51 proposes adding yet another separate directory
- Confusing: Users don't know where to find their files
Proposed Solution
Consolidate to one base directory per platform with subdirectories:
~/.config/nanocoder/ # macOS & Linux (XDG convention for CLI tools)
%APPDATA%\nanocoder\ # Windows
nanocoder/
├── config/
│ └── agents.config.json
├── data/
│ ├── preferences.json
│ ├── usage.json
│ └── history
├── sessions/ # For issue #51
│ ├── index.json
│ └── {session-id}.json
├── logs/
│ └── nanocoder-YYYY-MM-DD.log
└── cache/
└── models.json
Single path function:
export function getBasePath(): string {
switch (process.platform) {
case 'darwin':
return join(homedir(), '.config', 'nanocoder');
case 'win32':
return join(process.env.APPDATA || homedir(), 'nanocoder');
default:
return join(process.env.XDG_CONFIG_HOME || join(homedir(), '.config'), 'nanocoder');
}
}
Single override:
NANOCODER_HOME=/custom/path # Overrides everything
Migration
Need to handle existing files in old locations:
- Check for files in legacy locations
- Move to new location on first run
- Log migration for user visibility
Questions for Team
- Is
~/.config/nanocoder/acceptable for macOS, or prefer~/Library/Application Support/nanocoder/? - Should we keep separate
NANOCODER_CONFIG_DIRandNANOCODER_DATA_DIRoverrides, or consolidate toNANOCODER_HOME? - What migration strategy - automatic move, or just start using new location?
Files to Modify
source/config/paths.ts- Main path functionssource/utils/logging/config.ts- Log directorysource/models/models-cache.ts- Cache directorysource/config/index.ts- Config loadingsource/config/preferences.ts- Preferences pathsource/usage/storage.ts- Usage data path
Related Issues
- Prerequisite for #51 (
/resumecommand) - sessions should use consolidated paths - Related to #229 (unified session service) - session tracking needs consistent storage
Hey @JimStenstrom - thanks for taking the time to think through the file storage experience! :)
I took a look at this alongside PR #85 which tackled similar themes and it seems like the current architecture which that put in place is the right way to go where PR #85 deliberately separated config and data directories to follow each platform's conventions:
- Linux: Uses XDG Base Directory Specification (~/.config/ for config, ~/.local/share/ for data)
- macOS: Uses Apple conventions (~/Library/Preferences/ for config, ~/Library/Application Support/ for data)
- Windows: Uses %APPDATA% for both (which is the standard Windows approach)
This was deemed the right kind of separation as it follows what users on each platform expect and enables things like proper backup strategies and system-level overrides.
Some ideas that might still add value:
- A Nanocoder
pathscommand to show all storage locations at a glance - Adding
getCachePath()if we need dedicated caching later - Improving the README with clearer docs on file locations
Also worth noting - issue #51 (the /resume command feature) was written before PR #85 landed, so it might need a quick update to reflect the new path structure if it references file locations.
I will admit PR #85 wasn't put in by me and I admit that I am not an expert at system paths etc. Therefore, very very happy to take your thoughts as well as others: @Avtrkrb, @spinualexandru, @mrspence, @DenizOkcu ?
If any of the ideas above sound useful, happy to spin them off into focused issues.
* Linux: Uses XDG Base Directory Specification (~/.config/ for config, ~/.local/share/ for data) * macOS: Uses Apple conventions (~/Library/Preferences/ for config, ~/Library/Application Support/ for data) * Windows: Uses %APPDATA% for both (which is the standard Windows approach)This was deemed the right kind of separation as it follows what users on each platform expect and enables things like proper backup strategies and system-level overrides.
Some ideas that might still add value:
* A Nanocoder `paths` command to show all storage locations at a glance * Adding `getCachePath()` if we need dedicated caching later * Improving the README with clearer docs on file locations
I feel this separation of concern is the standard practice & is followed by other popular OSS software, so probably sticking with this is better. Purely my opinion..
Hey,
The xdg base dir is a bit more than following a trend.
It's enabling things like portability, many maintenance scripts using those paths, cache home is on some distros written on tmpfs on ram.
The current setup enables/empowers users to have clean, maintainable and scriptable system paths.
For instance, my system automatically clears cache older than 7 days. With the new proposed setup, it wont know about nanocoder's cache location
Code Audit: File Storage on main Branch
Intent: This audit documents the actual state of file storage code on main to enable informed discussion. The goal is to understand where the code actually saves files (vs. where we think it does) so we can align on where we want it to go.
1. Path Functions in paths.ts
Only 2 functions exist in source/config/paths.ts:
// getAppDataPath() - lines 4-31
export function getAppDataPath(): string {
if (process.env.NANOCODER_DATA_DIR) return process.env.NANOCODER_DATA_DIR;
if (process.env.XDG_DATA_HOME) return join(process.env.XDG_DATA_HOME, 'nanocoder'); // ⚠️ All platforms
switch (process.platform) {
case 'darwin': return join(homedir(), 'Library', 'Application Support', 'nanocoder');
case 'win32': return join(process.env.APPDATA ?? ..., 'nanocoder');
default: return join(homedir(), '.local', 'share', 'nanocoder');
}
}
// getConfigPath() - lines 34-54
export function getConfigPath(): string {
if (process.env.NANOCODER_CONFIG_DIR) return process.env.NANOCODER_CONFIG_DIR;
switch (process.platform) {
case 'darwin': return join(homedir(), 'Library', 'Preferences', 'nanocoder'); // ⚠️
case 'win32': return join(process.env.APPDATA ?? ..., 'nanocoder');
default: return join(process.env.XDG_CONFIG_HOME ?? join(homedir(), '.config'), 'nanocoder');
}
}
Missing from paths.ts: getCacheDir(), getLogsDir(), getSessionsDir(), getGlobalCommandsDir()
2. Non-Centralized Path Definitions
Cache (models-cache.ts, lines 15-23)
const DEFAULT_CACHE_DIR =
process.platform === 'darwin'
? path.join(process.env.HOME || '~', 'Library', 'Caches')
: path.join(process.env.HOME || '~', '.cache'); // ⚠️ Used for Windows too
function getCacheDir(): string {
const cacheBase = xdgCache || DEFAULT_CACHE_DIR; // xdgCache from xdg-basedir package
return path.join(cacheBase, 'nanocoder');
}
Logs (logging/config.ts, lines 12-25)
export function getDefaultLogDirectory(): string {
if (process.env.NANOCODER_LOG_DIR) return process.env.NANOCODER_LOG_DIR;
switch (platform()) {
case 'win32': return join(process.env.APPDATA || homedir(), 'nanocoder', 'logs');
case 'darwin': return join(homedir(), 'Library', 'Preferences', 'nanocoder', 'logs'); // ⚠️
default: return join(homedir(), '.config', 'nanocoder', 'logs'); // ⚠️
}
}
3. Config File Search Order
getClosestConfigFile() in config/index.ts searches in this order:
1. CWD/{filename} // Project-local
2. ~/.{filename} // Legacy home hidden file
3. getConfigPath()/{filename} // Platform config dir
If not found anywhere, it creates the file at location #3.
4. Files That Use Path Functions
| File | Function Used | Data Stored |
|---|---|---|
config/index.ts |
getClosestConfigFile() |
Config files |
preferences.ts |
getClosestConfigFile() |
nanocoder-preferences.json |
prompt-history.ts |
getClosestConfigFile() |
.nano-coder-history |
usage/storage.ts |
getAppDataPath() |
usage.json |
wizard/location-step.tsx |
getConfigPath() |
agents.config.json |
custom-commands/loader.ts |
Hardcoded | CWD/.nanocoder/commands/ |
checkpoint-manager.ts |
Hardcoded | CWD/.nanocoder/checkpoints/ |
5. Complete Path Matrix
| Data Type | Source File | macOS | Linux | Windows |
|---|---|---|---|---|
| Config | paths.ts |
~/Library/Preferences/nanocoder/ |
~/.config/nanocoder/ |
%APPDATA%\nanocoder\ |
| Data | paths.ts |
~/Library/Application Support/nanocoder/ |
~/.local/share/nanocoder/ |
%APPDATA%\nanocoder\ |
| Cache | models-cache.ts |
~/Library/Caches/nanocoder/ |
~/.cache/nanocoder/ |
~/.cache/nanocoder/ ❌ |
| Logs | logging/config.ts |
~/Library/Preferences/nanocoder/logs/ |
~/.config/nanocoder/logs/ |
%APPDATA%\nanocoder\logs\ |
| Commands | loader.ts |
CWD/.nanocoder/commands/ |
CWD/.nanocoder/commands/ |
CWD/.nanocoder/commands/ |
| Checkpoints | checkpoint-manager.ts |
CWD/.nanocoder/checkpoints/ |
CWD/.nanocoder/checkpoints/ |
CWD/.nanocoder/checkpoints/ |
6. Platform Standards
macOS
Per Apple File System Programming Guide:
| Standard Directory | Purpose |
|---|---|
~/Library/Application Support/ |
App-specific data and user files |
~/Library/Preferences/ |
Preference files via NSUserDefaults only (.plist) |
~/Library/Caches/ |
Regenerable cached data |
~/Library/Logs/ |
Log files |
Key: "You should never create files directly in the Preferences directory."
Linux
Per XDG Base Directory Specification:
| Variable | Default | Purpose |
|---|---|---|
XDG_CONFIG_HOME |
~/.config |
User-specific configuration |
XDG_DATA_HOME |
~/.local/share |
User-specific data files |
XDG_CACHE_HOME |
~/.cache |
Non-essential cached data |
XDG_STATE_HOME |
~/.local/state |
State data (logs, history) |
Windows
Per Microsoft App Data Documentation:
| Variable | Purpose |
|---|---|
%APPDATA% |
Settings that sync across devices |
%LOCALAPPDATA% |
Device-specific data, cache |
7. Compliance Summary
| Platform | Config | Data | Cache | Logs | Score |
|---|---|---|---|---|---|
| macOS | ❌ Uses Preferences/ |
✅ | ✅ | ❌ Uses Preferences/.../logs/ |
2/4 |
| Linux | ✅ | ✅ | ✅ | ❌ Uses ~/.config/.../logs/ |
3/4 |
| Windows | ✅ | ✅ | ❌ Uses ~/.cache/ |
✅ | 3/4 |
8. Environment Variable Overrides
Current NANOCODER_* Variables
| Variable | Defined In | Centralized? |
|---|---|---|
NANOCODER_CONFIG_DIR |
paths.ts |
✅ Yes |
NANOCODER_DATA_DIR |
paths.ts |
✅ Yes |
NANOCODER_LOG_DIR |
logging/config.ts |
❌ No |
NANOCODER_LOG_LEVEL |
logging/config.ts |
❌ No |
NANOCODER_LOG_DISABLE_FILE |
logging/config.ts |
❌ No |
NANOCODER_CACHE_DIR |
— | ❌ Missing |
XDG Variable Handling
| Variable | Checked In | Platform Scope | Per XDG Spec |
|---|---|---|---|
XDG_CONFIG_HOME |
paths.ts default case |
Linux only ✅ | Linux |
XDG_DATA_HOME |
paths.ts before switch |
All platforms ❌ | Linux |
XDG_CACHE_HOME |
xdg-basedir pkg |
Linux only ✅ | Linux |
XDG_STATE_HOME |
Not checked | — | Linux |
Bug: XDG_DATA_HOME is checked before the platform switch (line 10-12), affecting all platforms instead of just Linux per the XDG spec.
9. Naming Convention Inconsistency
Three different suffixes in the codebase:
| Suffix | Example | Location |
|---|---|---|
*Path |
getAppDataPath(), getConfigPath() |
paths.ts |
*Directory |
getDefaultLogDirectory() |
logging/config.ts |
*Dir |
getCacheDir() |
models-cache.ts |
Questions for Discussion
- Should all path functions be centralized in
paths.ts? - Should function naming be standardized?
- Should
XDG_DATA_HOMEonly be checked on Linux per spec? - Should
NANOCODER_CACHE_DIRbe added? - Should we have both
XDG_andNANOCODER_environment variables? If so which ones supersedes? - Should migration logic be added for existing files?
- Should a
/pathscommand show users where data lives? - Should global commands be supported (not just project-local)?
Looking forward to community input on the intended direction.
Hey everyone, anymore thoughts on this issue?
Hey everyone, anymore thoughts on this issue?
I can comment on Linux: I vote we keep the Linux paths as they are, maybe only change the log location to either ~/.local/state or /var/logs/nanocoder ? Other than that, I think the paths for Linux already follow the standard practices as per XDG guidelines.
Probably someone with more authority can reason better. I'm not sure about Windows & Mac file paths, so I'm fine with anything that follows industry standards for those.
I do have a suggestion for the files though:
- Store provider & model configs in
agents.config.jsonboth user & project scope (Current) - Store preferences in
nanocoder-preferences.jsonboth user & project scope (Current) - Store mcp configurations in a dedicated
.nanocoder/mcp.jsonfor project scope &NANOCODER_CONFIG_DIR/mcp.jsonfor user scope. Justification for this is detailed in this issue: https://github.com/Nano-Collective/nanocoder/issues/268. This also add separation of concerns & reusability of mcp servers config jsons from other tools.
Questions for Discussion
1.Should all path functions be centralized in paths.ts?
- Yes ✅
2.Should function naming be standardized?
- Yes ✅
3.Should XDG_DATA_HOME only be checked on Linux per spec?
- Yes ✅
4.Should NANOCODER_CACHE_DIR be added?
- Yes if there is a proper use for this. ✅
5.Should we have both XDG_ and NANOCODER_ environment variables? If so which ones supersedes?
NANOCODER_environment variables can be utilized cross-platform.XDG_environment variables only apply to Linux. SoNANOCODER_should take higher precedence thanXDG_but we must ensure that they both are compliant & hold the same values, lest it lead to conflicts.
6.Should migration logic be added for existing files?
- Yes ✅
7.Should a /paths command show users where data lives?
- Yes ✅
8.Should global commands be supported (not just project-local)?
- Yes ✅
I would recommend checking how the propriatary solutions are doing it. I guess all of their locations are quite battle tested at this point. Mac should be similar to Linux. I am happy to look into Mac.
On Mac I personally do not like using: ~/Library/Preferences
My preference for Unix systems is always User home with a .nanocoder directory for easy editing and easy backup
On Mac I personally do not like using:
~/Library/PreferencesMy preference for Unix systems is always User home with a.nanocoderdirectory for easy editing and easy backup
Or the ~/.config. That's also a very standard location.
Hey,
The xdg base dir is a bit more than following a trend.
It's enabling things like portability, many maintenance scripts using those paths, cache home is on some distros written on tmpfs on ram.
The current setup enables/empowers users to have clean, maintainable and scriptable system paths.
+1 on Denis as per my previous comment