Skip to content

fix: use .kilo instead of .kilocode for config directories - #6881

Merged
marius-kilocode merged 17 commits into
mainfrom
fix/use-kilo-dir-instead-of-kilocode
Mar 12, 2026
Merged

marius-kilocode merged 17 commits into
mainfrom
fix/use-kilo-dir-instead-of-kilocode

Conversation

@marius-kilocode

@marius-kilocode marius-kilocode commented Mar 10, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Closes #6874

Updates .kilocode directory handling to .kilo across the CLI and VS Code extension using two strategies depending on ownership.

Strategy 1: Agent Manager data -> migrate at startup

Files exclusively owned by Agent Manager (agent-manager.json, worktrees/, setup-script*) are moved from .kilocode/ to .kilo/ at startup via migrateAgentManagerData() in packages/kilo-vscode/src/agent-manager/constants.ts.

  • Called from WorktreeStateManager.load() and WorktreeManager.ensureMigrated()
  • Skips items that already exist in .kilo/ (no overwrite)
  • Repairs git worktree backrefs (.git/worktrees/{name}/gitdir) whenever .kilo/worktrees/ exists, so partially migrated repos recover too
  • Handles both normal repos (.git directory) and worktree roots (.git file)
  • Rewrites stale .kilocode/ paths in agent-manager.json worktree entries (Unix and Windows separators)
  • On Windows, rename can fail with EPERM/EBUSY if files are held open - retries on next startup
  • Idempotent and safe to call every startup
  • After migration, all Agent Manager reads/writes go to .kilo/ only
  • Per-worktree internal metadata (readMetadata) still checks both .kilo/ and .kilocode/ since those internal dirs are not moved

Strategy 2: CLI config data -> dual-read

Multiple CLI consumers read config data, so there is no single safe migration point. Instead, each component reads from both .kilo/ and .kilocode/, with .kilo/ taking precedence.

Component Strategy
paths.ts (skills) Discover project and global skills from both .kilo/ and .kilocode/
project-id.ts Check .kilo/config.json first, fall back to .kilocode/config.json
mcp-migrator.ts Read .kilocode/mcp.json then .kilo/mcp.json (later wins)
rules-migrator.ts Read project and global rules from both dirs, same filename: .kilo/ wins
workflows-migrator.ts Read project and global workflows from both dirs, .kilocode/ first and .kilo/ second (later wins)
config/paths.ts Discover .kilo, .kilocode, .opencode directories
config/config.ts Load config, agents, and commands from .kilocode/ dirs too

New writes go to .kilo/. Existing .kilocode/ content continues to work without manual migration.

What didn't change (separate concerns)

  • .kilocodeignore, .kilocoderules, .kilocodemodes (standalone dotfiles, not directories)
  • kilocode.kilo-code (VS Code extension publisher ID)
  • kilocodeToken, kilocodeOrganizationId (API property names)
  • legacy-migration.ts in kilo-gateway (explicit legacy auth migration)

Only rename project-level .kilocode/ to .kilo/. The global ~/.kilocode
directory must stay because legacy CLI instances and legacy-migration.ts
in kilo-gateway still read from it.
Comment thread packages/opencode/src/config/config.ts Resolved
@kilo-code-bot

kilo-code-bot Bot commented Mar 10, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: 1 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 0

Fix these issues in Kilo Cloud

Issue Details (click to expand)

WARNING

File Line Issue
packages/opencode/src/kilocode/mcp-migrator.ts 111 Malformed legacy .kilocode/mcp.json aborts loading before the valid .kilo/mcp.json fallback is tried
Other Observations (not in diff)

No additional issues found outside the diff.

Files Reviewed (26 files)
  • packages/kilo-vscode/AGENTS.md - 0 issues
  • packages/kilo-vscode/src/agent-manager/AgentManagerProvider.ts - 0 issues
  • packages/kilo-vscode/src/agent-manager/SetupScriptService.ts - 0 new issues
  • packages/kilo-vscode/src/agent-manager/WorktreeManager.ts - 0 new issues
  • packages/kilo-vscode/src/agent-manager/WorktreeStateManager.ts - 0 new issues
  • packages/kilo-vscode/src/agent-manager/__tests__/AgentManagerProvider.spec.ts - 0 issues
  • packages/kilo-vscode/src/agent-manager/__tests__/SetupScriptService.spec.ts - 0 issues
  • packages/kilo-vscode/src/agent-manager/constants.ts - 0 new issues
  • packages/kilo-vscode/tests/unit/worktree-manager.test.ts - 0 issues
  • packages/kilo-vscode/tests/unit/worktree-state-manager.test.ts - 0 issues
  • packages/opencode/src/config/config.ts - 0 new issues
  • packages/opencode/src/config/paths.ts - 0 new issues
  • packages/opencode/src/kilocode/ignore-migrator.ts - 0 issues
  • packages/opencode/src/kilocode/mcp-migrator.ts - 1 issue
  • packages/opencode/src/kilocode/paths.ts - 0 new issues
  • packages/opencode/src/kilocode/project-id.ts - 0 new issues
  • packages/opencode/src/kilocode/rules-migrator.ts - 0 new issues
  • packages/opencode/src/kilocode/workflows-migrator.ts - 0 new issues
  • packages/opencode/src/skill/skill.ts - 0 new issues
  • packages/opencode/test/config/config.test.ts - 0 issues
  • packages/opencode/test/kilocode/mcp-migrator.test.ts - 0 issues
  • packages/opencode/test/kilocode/paths.test.ts - 0 issues
  • packages/opencode/test/kilocode/project-id.test.ts - 0 issues
  • packages/opencode/test/kilocode/rules-migrator.test.ts - 0 issues
  • packages/opencode/test/kilocode/workflows-migrator.test.ts - 0 issues
  • packages/sdk/js/test/server.test.ts - 0 issues

Comment thread packages/opencode/src/kilocode/paths.ts Resolved
- Fix comment referencing ~/.kilo when globalDir() returns ~/.kilocode
- Revert to specific .kilo/ git exclude entries instead of blanket .kilo/
  to avoid hiding user-authored rules/workflows/config from git status
Comment thread packages/opencode/src/kilocode/paths.ts Resolved
- readMetadata() falls back to .kilocode/ inside worktrees since the
  per-worktree metadata dirs aren't renamed by the top-level migration
- Rewrite stale .kilocode/ paths in agent-manager.json on load
…Manager

Move migration call to the top of activate() so it runs for all users
on every extension startup, before kilo serve is spawned or any code
reads from the .kilo directory.
After renaming the directory, git's internal .git/worktrees/*/gitdir
files still reference the old .kilocode path. This causes git to lose
track of worktrees, leading to crashes. Both the CLI and extension
migration now rewrite these gitdir files after a successful rename.
@marius-kilocode

Copy link
Copy Markdown
Collaborator Author

We probably want to postpone this after GA, closing

Replace the one-time directory rename migration with a dual-read strategy:

- CLI config (rules, workflows, skills, MCP, project-id): read from both
  .kilo/ and .kilocode/ directories, with .kilo taking precedence
- Agent Manager data (worktrees, state, setup scripts): migrate from
  .kilocode/ to .kilo/ at startup since the extension exclusively owns these
- Config discovery (paths.ts, config.ts): include .kilocode in directory
  and agent/command pattern matching

Key decisions:
- .kilo/ is the new canonical write location for all new data
- .kilocode/ is read as a legacy fallback (no data loss for existing users)
- No directory rename: both dirs can coexist safely
- Agent Manager migration is item-level (moves individual files), not a
  full directory rename, so it handles both-dirs-exist gracefully
- Windows path rewrite in WorktreeStateManager handles both / and \ separators
- Workflow/MCP load order: .kilocode first, .kilo second (last wins)
- Rules dedup via seen-set with .kilo checked first (first wins)
- Delete migrate-kilo-dir.ts (no longer needed)
When the project root is itself a worktree, .git is a file pointing
at the shared git dir, not a directory. Follow the gitdir pointer to
find the actual .git/worktrees/ location.
Always repair stale git worktree refs when .kilo worktrees already exist so partially migrated repos recover on startup. Also dual-read global skills, rules, and workflows from both legacy and new home directories.
Comment thread packages/opencode/src/config/paths.ts Resolved
Comment thread packages/opencode/src/kilocode/paths.ts Resolved

@markijbema markijbema left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few comments,otherwise good to go

for (const [id, wt] of Object.entries(data.worktrees ?? {})) {
this.worktrees.set(id, { id, ...wt })
// Rewrite stale .kilocode/ paths (handles both Unix / and Windows \ separators)
const fixed = wt.path?.replace(/[/\\]\.kilocode[/\\]/g, `${path.sep}.kilo${path.sep}`) ?? wt.path

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WARNING: Relative legacy worktree paths are left stale

This replacement only matches .kilocode when it has a leading slash or backslash. A persisted relative entry like .kilocode/worktrees/foo will survive unchanged, and validate() later resolves it against root, so the migrated state still points at the old location and the worktree gets dropped as missing.

const skillsDir = path.join(dir, "skills")
if (await Filesystem.isDir(skillsDir)) {
directories.push(dir) // Return parent (.kilocode/), not skills/
for (const target of [".kilocode", ".kilo"] as const) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SUGGESTION: This makes .kilo skills load twice

Skill.state() already scans project .kilo directories through Config.directories(). Returning .kilo from this helper means the same skills/**/SKILL.md files are parsed a second time, which produces false duplicate skill name warnings and an extra disk walk for every project that already uses .kilo/skills.

@marius-kilocode
marius-kilocode merged commit 466644e into main Mar 12, 2026
13 checks passed
@marius-kilocode
marius-kilocode deleted the fix/use-kilo-dir-instead-of-kilocode branch March 12, 2026 11:50
allServers.push({ name, server }) // Later entries win in deduplication
for (const dir of [".kilocode", ".kilo"]) {
const projectSettingsPath = path.join(options.projectDir, dir, "mcp.json")
const projectSettings = await readMcpSettings(projectSettingsPath)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WARNING: Malformed legacy MCP config blocks .kilo fallback

If .kilocode/mcp.json contains invalid JSON, readMcpSettings() throws here and aborts the entire loop before .kilo/mcp.json is read. In mixed-state repos, that means a stale broken legacy file makes the new-path MCP config disappear completely instead of falling back to the valid .kilo copy. Catch parse errors per directory and continue to the next location.

marius-kiloclaw added a commit to marius-kiloclaw/kilocode that referenced this pull request Mar 12, 2026
readMcpSettings() called JSON.parse() without try/catch. In migrate(),
if .kilocode/mcp.json existed but contained malformed JSON, the uncaught
exception propagated out of the dual-read loop, preventing .kilo/mcp.json
from ever being read. The outer loadMcpConfig() catch returned {} instead
of the valid config — silently losing MCP server configuration.

Wrap the file read + parse in try/catch, log a warning, and return null
so the loop continues to the next config directory.

Regression tests added for both readMcpSettings (unit) and migrate
(integration) to prove the bug and verify the fix.

Refs: Kilo-Org#6881
marius-kilocode pushed a commit that referenced this pull request Mar 13, 2026
…#7012)

readMcpSettings() called JSON.parse() without try/catch. In migrate(),
if .kilocode/mcp.json existed but contained malformed JSON, the uncaught
exception propagated out of the dual-read loop, preventing .kilo/mcp.json
from ever being read. The outer loadMcpConfig() catch returned {} instead
of the valid config — silently losing MCP server configuration.

Wrap the file read + parse in try/catch, log a warning, and return null
so the loop continues to the next config directory.

Regression tests added for both readMcpSettings (unit) and migrate
(integration) to prove the bug and verify the fix.

Refs: #6881

Co-authored-by: marius-kiloclaw <[email protected]>
jliounis pushed a commit to jliounis/kilocode that referenced this pull request May 18, 2026
…6881)

* fix: use .kilo instead of .kilocode for config directories

* fix: keep global ~/.kilocode untouched for legacy CLI compat

Only rename project-level .kilocode/ to .kilo/. The global ~/.kilocode
directory must stay because legacy CLI instances and legacy-migration.ts
in kilo-gateway still read from it.

* test: update VS Code extension tests to use .kilo directory paths

* fix: correct paths.ts comment and use specific git exclude entries

- Fix comment referencing ~/.kilo when globalDir() returns ~/.kilocode
- Revert to specific .kilo/ git exclude entries instead of blanket .kilo/
  to avoid hiding user-authored rules/workflows/config from git status

* fix: handle legacy per-worktree metadata and stale paths in state

- readMetadata() falls back to .kilocode/ inside worktrees since the
  per-worktree metadata dirs aren't renamed by the top-level migration
- Rewrite stale .kilocode/ paths in agent-manager.json on load

* fix: run .kilocode migration at extension activation, not just Agent Manager

Move migration call to the top of activate() so it runs for all users
on every extension startup, before kilo serve is spawned or any code
reads from the .kilo directory.

* fix: update git worktree refs after .kilocode → .kilo rename

After renaming the directory, git's internal .git/worktrees/*/gitdir
files still reference the old .kilocode path. This causes git to lose
track of worktrees, leading to crashes. Both the CLI and extension
migration now rewrite these gitdir files after a successful rename.

* fix: read from both .kilo and .kilocode, write to .kilo

Replace the one-time directory rename migration with a dual-read strategy:

- CLI config (rules, workflows, skills, MCP, project-id): read from both
  .kilo/ and .kilocode/ directories, with .kilo taking precedence
- Agent Manager data (worktrees, state, setup scripts): migrate from
  .kilocode/ to .kilo/ at startup since the extension exclusively owns these
- Config discovery (paths.ts, config.ts): include .kilocode in directory
  and agent/command pattern matching

Key decisions:
- .kilo/ is the new canonical write location for all new data
- .kilocode/ is read as a legacy fallback (no data loss for existing users)
- No directory rename: both dirs can coexist safely
- Agent Manager migration is item-level (moves individual files), not a
  full directory rename, so it handles both-dirs-exist gracefully
- Windows path rewrite in WorktreeStateManager handles both / and \ separators
- Workflow/MCP load order: .kilocode first, .kilo second (last wins)
- Rules dedup via seen-set with .kilo checked first (first wins)
- Delete migrate-kilo-dir.ts (no longer needed)

* fix: resolve .git file when fixing worktree refs during migration

When the project root is itself a worktree, .git is a file pointing
at the shared git dir, not a directory. Follow the gitdir pointer to
find the actual .git/worktrees/ location.

* fix: recover partial .kilo migrations and global dirs

Always repair stale git worktree refs when .kilo worktrees already exist so partially migrated repos recover on startup. Also dual-read global skills, rules, and workflows from both legacy and new home directories.

* fix: keep .kilo ahead of legacy config dirs

* fix: narrow legacy agent manager excludes

* chore: link migration cleanup follow-up
jliounis pushed a commit to jliounis/kilocode that referenced this pull request May 18, 2026
…Kilo-Org#7012)

readMcpSettings() called JSON.parse() without try/catch. In migrate(),
if .kilocode/mcp.json existed but contained malformed JSON, the uncaught
exception propagated out of the dual-read loop, preventing .kilo/mcp.json
from ever being read. The outer loadMcpConfig() catch returned {} instead
of the valid config — silently losing MCP server configuration.

Wrap the file read + parse in try/catch, log a warning, and return null
so the loop continues to the next config directory.

Regression tests added for both readMcpSettings (unit) and migrate
(integration) to prove the bug and verify the fix.

Refs: Kilo-Org#6881
t7tran pushed a commit to t7tran/kilocode that referenced this pull request Aug 14, 2026
…6881)

* fix: use .kilo instead of .kilocode for config directories

* fix: keep global ~/.kilocode untouched for legacy CLI compat

Only rename project-level .kilocode/ to .kilo/. The global ~/.kilocode
directory must stay because legacy CLI instances and legacy-migration.ts
in kilo-gateway still read from it.

* test: update VS Code extension tests to use .kilo directory paths

* fix: correct paths.ts comment and use specific git exclude entries

- Fix comment referencing ~/.kilo when globalDir() returns ~/.kilocode
- Revert to specific .kilo/ git exclude entries instead of blanket .kilo/
  to avoid hiding user-authored rules/workflows/config from git status

* fix: handle legacy per-worktree metadata and stale paths in state

- readMetadata() falls back to .kilocode/ inside worktrees since the
  per-worktree metadata dirs aren't renamed by the top-level migration
- Rewrite stale .kilocode/ paths in agent-manager.json on load

* fix: run .kilocode migration at extension activation, not just Agent Manager

Move migration call to the top of activate() so it runs for all users
on every extension startup, before kilo serve is spawned or any code
reads from the .kilo directory.

* fix: update git worktree refs after .kilocode → .kilo rename

After renaming the directory, git's internal .git/worktrees/*/gitdir
files still reference the old .kilocode path. This causes git to lose
track of worktrees, leading to crashes. Both the CLI and extension
migration now rewrite these gitdir files after a successful rename.

* fix: read from both .kilo and .kilocode, write to .kilo

Replace the one-time directory rename migration with a dual-read strategy:

- CLI config (rules, workflows, skills, MCP, project-id): read from both
  .kilo/ and .kilocode/ directories, with .kilo taking precedence
- Agent Manager data (worktrees, state, setup scripts): migrate from
  .kilocode/ to .kilo/ at startup since the extension exclusively owns these
- Config discovery (paths.ts, config.ts): include .kilocode in directory
  and agent/command pattern matching

Key decisions:
- .kilo/ is the new canonical write location for all new data
- .kilocode/ is read as a legacy fallback (no data loss for existing users)
- No directory rename: both dirs can coexist safely
- Agent Manager migration is item-level (moves individual files), not a
  full directory rename, so it handles both-dirs-exist gracefully
- Windows path rewrite in WorktreeStateManager handles both / and \ separators
- Workflow/MCP load order: .kilocode first, .kilo second (last wins)
- Rules dedup via seen-set with .kilo checked first (first wins)
- Delete migrate-kilo-dir.ts (no longer needed)

* fix: resolve .git file when fixing worktree refs during migration

When the project root is itself a worktree, .git is a file pointing
at the shared git dir, not a directory. Follow the gitdir pointer to
find the actual .git/worktrees/ location.

* fix: recover partial .kilo migrations and global dirs

Always repair stale git worktree refs when .kilo worktrees already exist so partially migrated repos recover on startup. Also dual-read global skills, rules, and workflows from both legacy and new home directories.

* fix: keep .kilo ahead of legacy config dirs

* fix: narrow legacy agent manager excludes

* chore: link migration cleanup follow-up
t7tran pushed a commit to t7tran/kilocode that referenced this pull request Aug 14, 2026
…Kilo-Org#7012)

readMcpSettings() called JSON.parse() without try/catch. In migrate(),
if .kilocode/mcp.json existed but contained malformed JSON, the uncaught
exception propagated out of the dual-read loop, preventing .kilo/mcp.json
from ever being read. The outer loadMcpConfig() catch returned {} instead
of the valid config — silently losing MCP server configuration.

Wrap the file read + parse in try/catch, log a warning, and return null
so the loop continues to the next config directory.

Regression tests added for both readMcpSettings (unit) and migrate
(integration) to prove the bug and verify the fix.

Refs: Kilo-Org#6881

Co-authored-by: marius-kiloclaw <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

In some places .kilocode is used instead of .kilo

4 participants