Fix/data dir home fallback#1514
Open
Longchuanzheng wants to merge 3 commits into
Open
Conversation
added 2 commits
July 8, 2026 20:58
The Claude Code agent subprocess `cd`s into the project's work_dir before
resolving the system-prompt file path. When `data_dir` is empty or set to
a relative value in config.toml, and the service manager (systemd system
units, launchd LaunchAgents bootstrapped via gui/...) does not propagate
HOME, os.UserHomeDir() fails and config.Load() would fall back to a bare
relative ".cc-connect", which the child then resolves against work_dir
instead of the supervisor's home. The user-visible failure is:
Error: Append system prompt file not found:
<work_dir>/.cc-connect/agent-prompts/cc-connect-system.md
Fix has three parts and applies regardless of whether HOME is /root,
/home/app, or unset:
1. config.Load unconditionally absolutizes cfg.DataDir via filepath.Abs
after all fallbacks, so a relative value can never leak to child
processes. Also emits a slog.Warn when the fallback path is taken.
2. daemon.Config gains a HomeDir field; Resolve() captures os.UserHomeDir
at install time so the value survives into the service definition
even when the service runtime lacks HOME.
3. systemd.buildUnit emits `Environment="HOME=..."`, and launchd.buildPlist
emits `<key>HOME</key><string>...</string>`. HOME is added to
launchd's templateOwnedEnvKeys so an EnvExtra HOME cannot override
the captured value.
Regression tests:
- config: TestLoad_DataDirAbsoluteWhenExplicitlyRelative,
TestLoad_DataDirAbsoluteWhenHOMEEmpty
- systemd: TestBuildUnit_IncludesHOME, TestBuildUnit_OmitsHOMEWhenEmpty
- launchd: TestBuildPlist_IncludesHOME, TestBuildPlist_OmitsHOMEWhenEmpty,
TestBuildPlist_EnvExtraHOMEDoesNotOverrideTemplateHOME
config.example.toml gains a note recommending an absolute data_dir under
systemd/launchd.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix daemon startup/runtime path resolution under systemd and launchd by absolutizing
data_dirand injecting the install-timeHOMEinto generated service definitions. This prevents agent subprocesses thatcdintowork_dirfrom resolving.cc-connectunder the project directory whenHOMEis missing.Type of change
Testing
Verified targeted config and daemon regressions locally:
GOCACHE=/tmp/cc-connect-gocache go test ./config -run 'TestLoad_DataDirAbsolute|TestLoad_DefaultsDataDir' -vGOCACHE=/tmp/cc-connect-gocache go test ./daemon -run 'TestBuildPlist_IncludesHOME|TestBuildPlist_OmitsHOMEWhenEmpty|TestBuildPlist_EnvExtraHOMEDoesNotOverrideTemplateHOME' -vGOCACHE=/tmp/cc-connect-gocache GOOS=linux go test -c ./daemon -o /tmp/cc-connect-daemon-linux.testgit diff --checkNote: Linux systemd tests were compile-verified from macOS; the Linux test binary cannot be executed on macOS.
Automated tests added in this PR
TestLoad_DataDirAbsoluteWhenExplicitlyRelativeinconfig/config_test.go- asserts explicit relativedata_diris returned as an absolute path.TestLoad_DataDirAbsoluteWhenHOMEEmptyinconfig/config_test.go- asserts emptydata_dirstill becomes absolute whenHOMEis unavailable.TestBuildUnit_IncludesHOMEindaemon/systemd_test.go- asserts systemd units include capturedHOME.TestBuildUnit_OmitsHOMEWhenEmptyindaemon/systemd_test.go- asserts systemd units omit emptyHOME.TestBuildUnit_EnvExtraHOMEDoesNotOverrideTemplateHOMEindaemon/systemd_test.go- assertsEnvExtra["HOME"]cannot override template-ownedHOME.TestBuildPlist_IncludesHOMEindaemon/launchd_test.go- asserts launchd plists include capturedHOME.TestBuildPlist_OmitsHOMEWhenEmptyindaemon/launchd_test.go- asserts launchd plists omit emptyHOME.TestBuildPlist_EnvExtraHOMEDoesNotOverrideTemplateHOMEindaemon/launchd_test.go- assertsEnvExtra["HOME"]cannot override template-ownedHOME.For bug fixes only - regression test
TestLoad_DataDirAbsoluteWhenHOMEEmptyCritical User Journeys (CUJ) impact
/new/switch/list/historyetc.)/mode/cancel/stoppermissions)allow_fromadmin_frombanned_wordsrate limits)/cron/timer)/lang/provider/modelreload)Manual / user-visible behavior change
When running as a systemd/launchd service, cc-connect now preserves a usable
HOMEfor the daemon and agent subprocesses. Users should no longer see system prompt file lookup failures caused by.cc-connectbeing resolved underwork_dir.Checklist (reviewer will verify)
go build ./...passesgo test ./...passes (with-raceif touching concurrency)core/Related