Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(desktop): sync agent instructions from the home root too (#81051)

Paul D'Ambra20877a4d9dcd
diff --git a/products/desktop/packages/ui/src/features/settings/sections/PersonalizationSettings.tsx b/products/desktop/packages/ui/src/features/settings/sections/PersonalizationSettings.tsx
index e7dcc61e7099..5539e5e94d45 100644
--- a/products/desktop/packages/ui/src/features/settings/sections/PersonalizationSettings.tsx
+++ b/products/desktop/packages/ui/src/features/settings/sections/PersonalizationSettings.tsx
@@ -54,9 +54,9 @@ export function PersonalizationSettingsView({
{syncFromFile && !synced && (
<Callout.Root size="1" color="amber" mb="2">
<Callout.Text>
- No AGENTS.md or CLAUDE.md found in ~/.agents, ~/.codex or
- ~/.claude. Nothing is synced — add one of those files, or turn
- sync off to use the instructions below.
+ No AGENTS.md or CLAUDE.md found in your home directory or in
+ ~/.agents, ~/.codex or ~/.claude. Nothing is synced — add one of
+ those files, or turn sync off to use the instructions below.
</Callout.Text>
</Callout.Root>
)}
diff --git a/products/desktop/packages/workspace-server/src/services/os/os.test.ts b/products/desktop/packages/workspace-server/src/services/os/os.test.ts
index 837bec00210f..dfa35785de08 100644
--- a/products/desktop/packages/workspace-server/src/services/os/os.test.ts
+++ b/products/desktop/packages/workspace-server/src/services/os/os.test.ts
@@ -179,6 +179,8 @@ describe("OsService.getUserAgentInstructions", () => {
const agentsPath = path.join(home, ".agents", "AGENTS.md");
const codexPath = path.join(home, ".codex", "AGENTS.md");
const claudePath = path.join(home, ".claude", "CLAUDE.md");
+ const rootAgentsPath = path.join(home, "AGENTS.md");
+ const rootClaudePath = path.join(home, "CLAUDE.md");
function givenFiles(files: Record<string, string>) {
mockReadFile.mockImplementation(async (filePath: string) => {
@@ -221,6 +223,61 @@ describe("OsService.getUserAgentInstructions", () => {
content: "claude instructions",
},
},
+ {
+ label: "reads ~/AGENTS.md at the home root",
+ files: { [rootAgentsPath]: "root agents instructions" },
+ winner: {
+ path: rootAgentsPath,
+ displayPath: "~/AGENTS.md",
+ content: "root agents instructions",
+ },
+ },
+ {
+ label: "reads ~/CLAUDE.md at the home root",
+ files: { [rootClaudePath]: "root claude instructions" },
+ winner: {
+ path: rootClaudePath,
+ displayPath: "~/CLAUDE.md",
+ content: "root claude instructions",
+ },
+ },
+ {
+ label: "prefers ~/.agents/AGENTS.md over the home-root AGENTS.md",
+ files: {
+ [agentsPath]: "agents instructions",
+ [rootAgentsPath]: "root agents instructions",
+ },
+ winner: {
+ path: agentsPath,
+ displayPath: "~/.agents/AGENTS.md",
+ content: "agents instructions",
+ },
+ },
+ {
+ label: "prefers the home-root AGENTS.md over any CLAUDE.md",
+ files: {
+ [rootAgentsPath]: "root agents instructions",
+ [claudePath]: "claude instructions",
+ [rootClaudePath]: "root claude instructions",
+ },
+ winner: {
+ path: rootAgentsPath,
+ displayPath: "~/AGENTS.md",
+ content: "root agents instructions",
+ },
+ },
+ {
+ label: "prefers ~/.claude/CLAUDE.md over the home-root CLAUDE.md",
+ files: {
+ [claudePath]: "claude instructions",
+ [rootClaudePath]: "root claude instructions",
+ },
+ winner: {
+ path: claudePath,
+ displayPath: "~/.claude/CLAUDE.md",
+ content: "claude instructions",
+ },
+ },
])("$label", async ({ files, winner }) => {
const { service } = createService();
givenFiles(files);
diff --git a/products/desktop/packages/workspace-server/src/services/os/os.ts b/products/desktop/packages/workspace-server/src/services/os/os.ts
index d99ae556f6d1..159062045552 100644
--- a/products/desktop/packages/workspace-server/src/services/os/os.ts
+++ b/products/desktop/packages/workspace-server/src/services/os/os.ts
@@ -49,14 +49,18 @@ const MAX_FILE_SIZE = 50 * 1024 * 1024;
const CLIPBOARD_TEMP_DIR = path.join(os.tmpdir(), "posthog-code-clipboard");
const claudeSettingsPath = path.join(os.homedir(), ".claude", "settings.json");
-// User-level agent instruction files, most-preferred first: AGENTS.md (the
-// cross-agent convention) from any of its conventional homes wins over Claude
-// Code's CLAUDE.md.
-const USER_AGENT_INSTRUCTIONS_CANDIDATES: ReadonlyArray<[string, string]> = [
+// User-level agent instruction files as path segments under the home
+// directory, most-preferred first: AGENTS.md (the cross-agent convention) from
+// any of its conventional homes wins over Claude Code's CLAUDE.md, and a
+// tool-specific home wins over the bare home root. Only the first match is
+// read, so pointing several of these at one file still syncs it once.
+const USER_AGENT_INSTRUCTIONS_CANDIDATES: ReadonlyArray<readonly string[]> = [
[".agents", "AGENTS.md"],
[".codex", "AGENTS.md"],
[".claude", "AGENTS.md"],
+ ["AGENTS.md"],
[".claude", "CLAUDE.md"],
+ ["CLAUDE.md"],
];
// Claude Code follows `@path` imports up to four hops deep; we match that so a
@@ -113,8 +117,8 @@ export class OsService {
* user's CLAUDE.md. Null when none exists.
*/
async getUserAgentInstructions(): Promise<UserAgentInstructions | null> {
- for (const [dir, file] of USER_AGENT_INSTRUCTIONS_CANDIDATES) {
- const filePath = path.join(os.homedir(), dir, file);
+ for (const segments of USER_AGENT_INSTRUCTIONS_CANDIDATES) {
+ const filePath = path.join(os.homedir(), ...segments);
let content: string;
try {
content = await fsPromises.readFile(filePath, "utf-8");
@@ -133,7 +137,7 @@ export class OsService {
const truncated = expanded.length > USER_AGENT_INSTRUCTIONS_MAX_LENGTH;
return {
path: filePath,
- displayPath: `~/${dir}/${file}`,
+ displayPath: `~/${segments.join("/")}`,
content: truncated
? expanded.slice(0, USER_AGENT_INSTRUCTIONS_MAX_LENGTH)
: expanded,