Skip to content

Commit 335d8b5

Browse files
fix(server): Claude --settings and prompt-file launch args expand ~ (pingdotgg#26649)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 7d8f6c9 commit 335d8b5

3 files changed

Lines changed: 63 additions & 8 deletions

File tree

‎apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,6 +1184,50 @@ describe("ClaudeAdapterV2 append-system-prompt-file launch argument", () => {
11841184
),
11851185
);
11861186

1187+
// regression: #26631 `~/` launch argument paths resolved under the project cwd
1188+
it.effect.each([
1189+
[
1190+
"--settings ~/.claude/settings.json",
1191+
(options: ClaudeAdapterV2.ClaudeAgentSdkQueryOptions) =>
1192+
assert.deepInclude(options.settings, { skillOverrides: { lint: "off" } }),
1193+
],
1194+
[
1195+
"--append-system-prompt-file ~/.claude/settings.json",
1196+
(options: ClaudeAdapterV2.ClaudeAgentSdkQueryOptions) =>
1197+
assert.include(appendSystemPrompt(options), '{"skillOverrides":{"lint":"off"}}'),
1198+
],
1199+
] as const)("reads %s from the home directory", ([launchArgs, assertOptions]) =>
1200+
Effect.scoped(
1201+
Effect.gen(function* () {
1202+
const fileSystem = yield* FileSystem.FileSystem;
1203+
const home = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-claude-home-" });
1204+
const cwd = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-claude-home-cwd-" });
1205+
yield* fileSystem.makeDirectory(NodePath.join(home, ".claude"));
1206+
yield* fileSystem.writeFileString(
1207+
NodePath.join(home, ".claude", "settings.json"),
1208+
'{"skillOverrides":{"lint":"off"}}',
1209+
);
1210+
const { exit, opened } = yield* startTurnWithLaunchArgs(launchArgs, cwd).pipe(
1211+
Effect.provideService(HostProcess.HomeDirectory, home),
1212+
);
1213+
if (Exit.isFailure(exit)) {
1214+
assert.fail(makeProviderFailure({ cause: exit.cause, class: "provider_error" }).message);
1215+
}
1216+
assert.lengthOf(opened, 1);
1217+
assertOptions(opened[0]!);
1218+
}).pipe(
1219+
Effect.provide(
1220+
Layer.mergeAll(
1221+
IdAllocator.layer,
1222+
McpProviderSessions.layer,
1223+
NodeServices.layer,
1224+
NodeCrypto.layer,
1225+
),
1226+
),
1227+
),
1228+
),
1229+
);
1230+
11871231
// regression: #20413 malformed append-system-prompt launch args fail before a query opens
11881232
it.effect.each([
11891233
[

‎apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts‎

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1938,10 +1938,10 @@ export function makeClaudeQueryOptions(input: {
19381938
}
19391939

19401940
/**
1941-
* Checks the append launch arguments the way the Claude CLI would and reads
1942-
* the file relative to the process cwd. makeClaudeQueryOptions folds these
1943-
* flags out of extraArgs, so a value the CLI would have rejected has to be
1944-
* rejected here or it silently disappears.
1941+
* Checks the append launch arguments the way the Claude CLI would and reads the
1942+
* file (leading ~ expanded) relative to the thread's cwd. makeClaudeQueryOptions
1943+
* folds these flags out of extraArgs, so a value the CLI would have rejected has
1944+
* to be rejected here or it silently disappears.
19451945
*/
19461946
const readClaudeAppendSystemPromptFile = Effect.fnUntraced(function* (input: {
19471947
readonly settings: ClaudeSettings | undefined;
@@ -1966,7 +1966,10 @@ const readClaudeAppendSystemPromptFile = Effect.fnUntraced(function* (input: {
19661966
flag: "--append-system-prompt-file",
19671967
});
19681968
}
1969-
const filePath = input.path.resolve(input.cwd ?? ".", file);
1969+
const filePath = input.path.resolve(
1970+
input.cwd ?? ".",
1971+
expandHomePath(file, yield* HostProcess.HomeDirectory),
1972+
);
19701973
return yield* input.fileSystem
19711974
.readFileString(filePath)
19721975
.pipe(
@@ -1980,8 +1983,9 @@ const decodeClaudeLaunchArgSettings = Schema.decodeUnknownEffect(
19801983

19811984
/**
19821985
* Reads the --settings launch argument: a value starting with a brace is inline
1983-
* JSON, anything else is a file path relative to the cwd. makeClaudeQueryOptions
1984-
* merges the result beneath T3's own settings.
1986+
* JSON, anything else is a file path that expands a leading ~ and is otherwise
1987+
* relative to the thread's cwd (the project or its worktree).
1988+
* makeClaudeQueryOptions merges the result beneath T3's own settings.
19851989
*/
19861990
const readClaudeLaunchArgSettings = Effect.fn("ClaudeAdapterV2.readLaunchArgSettings")(
19871991
function* (input: {
@@ -2002,7 +2006,10 @@ const readClaudeLaunchArgSettings = Effect.fn("ClaudeAdapterV2.readLaunchArgSett
20022006
Effect.mapError((cause) => new ClaudeSettingsLaunchArgError({ cause })),
20032007
)) as ClaudeSdkSettings;
20042008
}
2005-
const filePath = input.path.resolve(input.cwd ?? ".", trimmed);
2009+
const filePath = input.path.resolve(
2010+
input.cwd ?? ".",
2011+
expandHomePath(trimmed, yield* HostProcess.HomeDirectory),
2012+
);
20062013
return (yield* input.fileSystem.readFileString(filePath).pipe(
20072014
Effect.flatMap(decodeClaudeLaunchArgSettings),
20082015
Effect.mapError((cause) => new ClaudeSettingsLaunchArgError({ path: filePath, cause })),

‎docs/user/providers-claude.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ state. Claude does not have Codex's shared-home and shadow-home arrangement.
4040
For presets that differ only in API keys or endpoints, use the instance's
4141
**Environment variables**. Variable assignments do not belong in **Launch arguments**.
4242

43+
File paths in the `--settings` and `--append-system-prompt-file` launch arguments
44+
can start with `~` for the home directory of the machine running T3 Code. Any
45+
other relative path is read from the thread's project folder, or its worktree.
46+
4347
Claude Code's verbose mode can stay enabled when you use Claude for text generation, including
4448
thread titles, branch names, commit messages, and pull request descriptions. On a remote connection,
4549
T3 Code uses the Claude configuration on the connected server.

0 commit comments

Comments
 (0)