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(agent): instruct sessions to follow repo rules and comment style (#91603)

Vojta Bartoš642c47617594
diff --git a/products/desktop/packages/agent/src/adapters/claude/session/instructions.test.ts b/products/desktop/packages/agent/src/adapters/claude/session/instructions.test.ts
index d720e82a01dd..b5b9067b544c 100644
--- a/products/desktop/packages/agent/src/adapters/claude/session/instructions.test.ts
+++ b/products/desktop/packages/agent/src/adapters/claude/session/instructions.test.ts
@@ -22,6 +22,7 @@ describe("buildAppendedInstructions", () => {
"# Plan Mode",
"# MCP Tool Access",
"# Data Handling",
+ "# Repository Conventions",
"# Shell Efficiency",
])("always appends %s", (heading) => {
expect(buildAppendedInstructions({ spokenNarration: false })).toContain(
diff --git a/products/desktop/packages/agent/src/adapters/claude/session/instructions.ts b/products/desktop/packages/agent/src/adapters/claude/session/instructions.ts
index 7d65643b9baf..b702bbb3fab6 100644
--- a/products/desktop/packages/agent/src/adapters/claude/session/instructions.ts
+++ b/products/desktop/packages/agent/src/adapters/claude/session/instructions.ts
@@ -41,6 +41,17 @@ const DATA_HANDLING = `
Material you were given as task context — customer conversations, support tickets, logs, internal threads — stays out of code, test data, comments, commit messages, and pull request text. Rewriting it, summarizing it, or swapping out names and domains does not clear it.
`;
+const REPOSITORY_CONVENTIONS = `
+# Repository Conventions
+
+Repositories carry their own coding conventions. Before your first edit, discover and read the ones this harness does not load for you:
+
+- \`AGENTS.md\` files: at the repo root and in any directory whose files you edit. \`CLAUDE.md\` is loaded for you automatically; when an \`AGENTS.md\` merely mirrors it you can move on, but when it carries its own content, follow that too.
+- Cursor rule files: \`.cursor/rules/*.mdc\` (the repo root's, and any nested \`.cursor/rules/\` near the files you edit) and the legacy \`.cursorrules\`. These are never loaded automatically. A rule's frontmatter tells you its scope: \`alwaysApply: true\` rules apply to every change, \`globs\` scope a rule to matching files.
+
+Follow those conventions, and match the style of the surrounding code even where no rule states it. Comment density matters most: do not add comments that narrate the change or restate what the code plainly does. Keep only comments a rule or the existing code style would call for.
+`;
+
const SHELL_EFFICIENCY = `
# Shell Efficiency
@@ -78,6 +89,7 @@ const BASE_INSTRUCTIONS =
PLAN_MODE +
MCP_TOOLS +
DATA_HANDLING +
+ REPOSITORY_CONVENTIONS +
SHELL_EFFICIENCY;
/** Shell-word shaped, so nothing else in the variable reaches the prompt. */