Skip to content

Commit 606215a

Browse files
MattPuacharlesvien
andauthored
chore(agent): add shell efficiency section to appended instructions (#3207)
Co-authored-by: Charles Vien <charles.v@posthog.com>
1 parent c31ca3b commit 606215a

3 files changed

Lines changed: 33 additions & 7 deletions

File tree

packages/agent/src/adapters/claude/session/instructions.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,16 @@ If an MCP tool call is explicitly denied with a message, relay that denial messa
3232
If an MCP tool call returns an error, treat it as a normal tool error — troubleshoot, retry, or inform the user about the specific error. Do NOT assume it is a permissions issue and do NOT direct the user to any settings page.
3333
`;
3434

35+
const SHELL_EFFICIENCY = `
36+
# Shell Efficiency
37+
38+
Optimize for the fewest shell round trips.
39+
40+
- Batch related commands into one Bash invocation using \`&&\` (e.g. \`npm run typecheck && npm run lint && npm test\`).
41+
- Emit all independent tool calls in the same response.
42+
- Read multiple files at once.
43+
- Never rerun a command solely to reproduce output you already have.
44+
`;
45+
3546
export const APPENDED_INSTRUCTIONS =
36-
BRANCH_NAMING + PULL_REQUEST_LINKS + PLAN_MODE + MCP_TOOLS;
47+
BRANCH_NAMING + PULL_REQUEST_LINKS + PLAN_MODE + MCP_TOOLS + SHELL_EFFICIENCY;

packages/agent/src/server/agent-server.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2665,6 +2665,14 @@ When you mention a pull request in any reply or summary, always hyperlink it to
26652665
(e.g. a Markdown link like [#123](https://github.com/org/repo/pull/123)) rather than plain
26662666
text, so readers can open it directly.`;
26672667

2668+
const shellEfficiencyInstructions = `
2669+
## Shell efficiency
2670+
Optimize for the fewest shell round trips.
2671+
- Batch related commands into one Bash invocation using \`&&\` (e.g. \`npm run typecheck && npm run lint && npm test\`).
2672+
- Emit all independent tool calls in the same response.
2673+
- Read multiple files at once.
2674+
- Never rerun a command solely to reproduce output you already have.`;
2675+
26682676
const whyContextInstruction = ` - Add a brief **Why** to the body — one or two sentences capturing the reason the user asked for this change (the motivation, not a restatement of the diff). Keep it short.`;
26692677
const publicRepoSafetyInstruction = ` - **Public-repo safety.** Treat the target repository as public-readable unless you have verified otherwise. The PR title, description, and commit messages must not contain private operational scale (exact event counts, internal row volumes, customer-usage percentages), customer names / emails / companies, references to internal tickets or incidents, the contents of Slack threads (do not quote or paraphrase what was said), or unreleased roadmap details. Linking to the originating Slack thread is fine and encouraged — Slack links are auth-gated and useful as context — as are channel references like "raised in #team-foo". Describe findings qualitatively ("present on nearly all X events, absent from Y") rather than with quantitative figures pulled from analytics queries — the reasoning that uses those numbers can stay in the thread; the PR copy cannot.`;
26702678
// Slack- and inbox-originated PRs are attributed to PostHog, not the
@@ -2691,7 +2699,7 @@ Do the requested work, but stop with local changes ready for review.
26912699
Important:
26922700
- Do NOT create new commits, push to the branch, or update the pull request unless the user explicitly asks.
26932701
- Do NOT create a new branch or a new pull request.
2694-
${signedCommitInstructions}${prLinkInstructions}
2702+
${signedCommitInstructions}${prLinkInstructions}${shellEfficiencyInstructions}
26952703
`;
26962704
}
26972705

@@ -2712,7 +2720,7 @@ After completing the requested changes:
27122720
Important:
27132721
- Do NOT create a new branch or a new pull request.
27142722
- Do NOT push fixes for review comments without replying to and resolving each related thread.
2715-
${signedCommitInstructions}${prLinkInstructions}
2723+
${signedCommitInstructions}${prLinkInstructions}${shellEfficiencyInstructions}
27162724
`;
27172725
}
27182726

@@ -2751,7 +2759,7 @@ ${publishInstructions}
27512759
27522760
Important:
27532761
- Prefer using MCP tools to answer questions with real data over giving generic advice.
2754-
${signedCommitInstructions}${prLinkInstructions}
2762+
${signedCommitInstructions}${prLinkInstructions}${shellEfficiencyInstructions}
27552763
`;
27562764
}
27572765

@@ -2763,7 +2771,7 @@ Do the requested work, but stop with local changes ready for review.
27632771
27642772
Important:
27652773
- Do NOT create a branch, commit, push, or open a pull request unless the user explicitly asks.
2766-
${signedCommitInstructions}${prLinkInstructions}
2774+
${signedCommitInstructions}${prLinkInstructions}${shellEfficiencyInstructions}
27672775
`;
27682776
}
27692777

@@ -2790,7 +2798,7 @@ ${prFooter}
27902798
27912799
Important:
27922800
- Always create the PR as a draft. Do not ask for confirmation.
2793-
${signedCommitInstructions}${prLinkInstructions}
2801+
${signedCommitInstructions}${prLinkInstructions}${shellEfficiencyInstructions}
27942802
`;
27952803
}
27962804

packages/workspace-server/src/services/agent/agent.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,14 @@ When creating pull requests, add the following footer at the end of the PR descr
605605
*Created with [PostHog Code](https://posthog.com/code?ref=pr)*
606606
\`\`\`
607607
608-
When you mention a pull request in any reply or summary, always hyperlink it to its full URL (e.g. a Markdown link like [#123](https://github.com/org/repo/pull/123)) rather than plain text, so readers can open it directly.`;
608+
When you mention a pull request in any reply or summary, always hyperlink it to its full URL (e.g. a Markdown link like [#123](https://github.com/org/repo/pull/123)) rather than plain text, so readers can open it directly.
609+
610+
## Shell efficiency
611+
Optimize for the fewest shell round trips.
612+
- Batch related commands into one Bash invocation using \`&&\` (e.g. \`npm run typecheck && npm run lint && npm test\`).
613+
- Emit all independent tool calls in the same response.
614+
- Read multiple files at once.
615+
- Never rerun a command solely to reproduce output you already have.`;
609616

610617
if (channelMode) {
611618
const localFolders = (knownLocalFolders ?? []).filter(

0 commit comments

Comments
 (0)