code-context-engine icon indicating copy to clipboard operation
code-context-engine copied to clipboard

cce init writes an unquoted Windows path into settings.local.json, breaking the SessionStart hook

Open nosferatu0205 opened this issue 4 months ago • 2 comments

What happened?

On Windows, cce init writes an unquoted absolute path into .claude/settings.local.json:

"command": "C:\\Users\\<user>\\.local\\bin\\cce.exe status --oneline"

Claude Code runs hook commands through bash (Git Bash on Windows). Unquoted backslashes are consumed as escape characters, so the path collapses and every session start prints:

SessionStart:startup hook error
Failed with non-blocking status code: /usr/bin/bash: line 1: C:Users<user>.localbincce.exe: command not found

The CCE status line never appears, so the agent loses the "USE context_search / do NOT use Read/Grep" instruction that the hook injects — which is the whole point of the hook.

The cause is at src/context_engine/cli.py:427, where the command is interpolated bare:

    session_hooks.append({
        "matcher": "",
        "hooks": [{"type": "command", "command": f"{cce_cmd} status --oneline"}],
    })

_resolve_cce_cmd() → resolve_cce_binary() returns a native Windows path with backslashes, and nothing quotes it.

The repo already has the right helper and uses it in the sibling generator. memory/hook_installer.py:255, which writes the five lifecycle hooks into settings.json, does:

                "command": f"{port_env}{_quote_hook_path(HOOK_PATH)} {hook_name}",

_quote_hook_path (hook_installer.py:176) already handles Windows vs POSIX quoting correctly. That is exactly why the settings.json hooks work on Windows while the settings.local.json status hook does not — same machine, same path style, one quoted and one not.

What did you expect?

cce init should emit a hook command that executes on Windows, the way the settings.json lifecycle hooks already do.

Steps to reproduce

  1. On Windows, with cce installed at a path containing backslashes (any default install, e.g. C:\Users\<you>\.local\bin\cce.exe).
  2. cd into any project and run cce init --agent claude.
  3. Open .claude/settings.local.json — the SessionStart command is unquoted.
  4. Start Claude Code in that project.

Reproduced on 14 out of 14 fresh cce init runs across separate projects — it is not intermittent or install-specific. Existing projects whose settings.local.json was hand-fixed keep working, which is what masks the bug.

Relevant logs or error output

# every session start, in every project initialised by cce init on Windows:
SessionStart:startup hook error
Failed with non-blocking status code: /usr/bin/bash: line 1: C:Users<user>.localbincce.exe: command not found

# the same path, quoted, works:
$ "C:/Users/<user>/.local/bin/cce.exe" status --oneline
CCE v0.4.25 · afflynk · 5158 chunks indexed
USE context_search MCP tool for all code questions. Do NOT use Read/Grep to explore code.

# unquoted, as cce init writes it:
$ C:\Users\<user>\.local\bin\cce.exe status --oneline
/usr/bin/bash: line 1: C:Users<user>.localbincce.exe: command not found

Suggested fix

Reuse the existing helper at cli.py:427:

from context_engine.memory.hook_installer import _quote_hook_path

"command": f"{_quote_hook_path(Path(cce_cmd))} status --oneline",

Note that _quote_hook_path returns cmd-style double quotes on Windows, which bash also dequotes correctly, so a single implementation covers both shells. PR incoming.

Worth a grep for other bare interpolations of resolve_cce_binary() output into shell strings — _configure_mcp (cli.py:162) passes the path as an argv element rather than a shell string, so that one is fine, but the pattern is easy to reintroduce.

Python version

3.13.5

OS

Windows 11 Pro 10.0.22631

CCE version

0.4.25

nosferatu0205 avatar Jul 27 '26 11:07 nosferatu0205

Fix is in #146. One-line change: wraps cce_cmd with the existing _quote_hook_path helper before interpolating it into the hook command string.

Your diagnosis was spot-on. The settings.json lifecycle hooks already use _quote_hook_path (via hook_installer.py:255), while the settings.local.json status hook was the only callsite that interpolated the path bare. The MCP config at cli.py:162 passes the path as an argv element (not a shell string), so it doesn't need quoting.

Existing projects need to re-run cce init --agent claude to regenerate the hook with proper quoting. Alternatively, manually quoting the path in .claude/settings.local.json works (as you already found).

Thanks for the thorough report and the exact fix suggestion, @nosferatu0205.

rajkumarsakthivel avatar Jul 27 '26 11:07 rajkumarsakthivel

Thanks for the quick turnaround on #146. One follow-up: that PR leaves the dedup marker on the line above unchanged.

    if not _has_cce_hook(session_hooks, "cce status"):

On Windows the resolved binary is cce.exe, so the command contains cce.exe status and the substring cce status is never present. After #146 it becomes "C:\Users\<user>\.local\bin\cce.exe" status --oneline, which still does not match.

So _has_cce_hook returns False on every run and cce init appends a new SessionStart entry instead of recognising the existing one. Verified on 0.4.25, two inits in a fresh project:

--- after 1st init ---
1 SessionStart entries
--- after 2nd init ---
2 SessionStart entries
    C:\Users\<user>\.local\bin\cce.exe status --oneline
    C:\Users\<user>\.local\bin\cce.exe status --oneline

This affects the upgrade path suggested above. Re-running cce init --agent claude on an existing project adds a correctly quoted hook but leaves the broken unquoted one in place, so the command not found error keeps firing and the status line prints twice. Manually quoting the path stays the only clean remedy until the marker is fixed.

Matching on status --oneline covers both the quoted and unquoted forms. _is_cce_settings_hook_command (cli.py:2354) is the other option, since its regex already handles .exe and surrounding quotes, which is why cce uninstall finds these hooks correctly today.

nosferatu0205 avatar Jul 27 '26 12:07 nosferatu0205