Skip to content

Commit 897d83c

Browse files
authored
refactor(init): tighten AGENTS guidance (#20422)
1 parent 0a125e5 commit 897d83c

File tree

4 files changed

+75
-11
lines changed

4 files changed

+75
-11
lines changed

packages/opencode/src/command/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export namespace Command {
8585

8686
commands[Default.INIT] = {
8787
name: Default.INIT,
88-
description: "create/update AGENTS.md",
88+
description: "guided AGENTS.md setup",
8989
source: "command",
9090
get template() {
9191
return PROMPT_INITIALIZE.replace("${path}", ctx.worktree)
Lines changed: 63 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,66 @@
1-
Please analyze this codebase and create an AGENTS.md file containing:
2-
1. Build/lint/test commands - especially for running a single test
3-
2. Code style guidelines including imports, formatting, types, naming conventions, error handling, etc.
1+
Create or update `AGENTS.md` for this repository.
42

5-
The file you create will be given to agentic coding agents (such as yourself) that operate in this repository. Make it about 150 lines long.
6-
If there are Cursor rules (in .cursor/rules/ or .cursorrules) or Copilot rules (in .github/copilot-instructions.md), make sure to include them.
7-
8-
If there's already an AGENTS.md, improve it if it's located in ${path}
3+
The goal is a compact instruction file that helps future OpenCode sessions avoid mistakes and ramp up quickly. Every line should answer: "Would an agent likely miss this without help?" If not, leave it out.
94

5+
User-provided focus or constraints (honor these):
106
$ARGUMENTS
7+
8+
## How to investigate
9+
10+
Read the highest-value sources first:
11+
- `README*`, root manifests, workspace config, lockfiles
12+
- build, test, lint, formatter, typecheck, and codegen config
13+
- CI workflows and pre-commit / task runner config
14+
- existing instruction files (`AGENTS.md`, `CLAUDE.md`, `.cursor/rules/`, `.cursorrules`, `.github/copilot-instructions.md`)
15+
- repo-local OpenCode config such as `opencode.json`
16+
17+
If architecture is still unclear after reading config and docs, inspect a small number of representative code files to find the real entrypoints, package boundaries, and execution flow. Prefer reading the files that explain how the system is wired together over random leaf files.
18+
19+
Prefer executable sources of truth over prose. If docs conflict with config or scripts, trust the executable source and only keep what you can verify.
20+
21+
## What to extract
22+
23+
Look for the highest-signal facts for an agent working in this repo:
24+
- exact developer commands, especially non-obvious ones
25+
- how to run a single test, a single package, or a focused verification step
26+
- required command order when it matters, such as `lint -> typecheck -> test`
27+
- monorepo or multi-package boundaries, ownership of major directories, and the real app/library entrypoints
28+
- framework or toolchain quirks: generated code, migrations, codegen, build artifacts, special env loading, dev servers, infra deploy flow
29+
- repo-specific style or workflow conventions that differ from defaults
30+
- testing quirks: fixtures, integration test prerequisites, snapshot workflows, required services, flaky or expensive suites
31+
- important constraints from existing instruction files worth preserving
32+
33+
Good `AGENTS.md` content is usually hard-earned context that took reading multiple files to infer.
34+
35+
## Questions
36+
37+
Only ask the user questions if the repo cannot answer something important. Use the `question` tool for one short batch at most.
38+
39+
Good questions:
40+
- undocumented team conventions
41+
- branch / PR / release expectations
42+
- missing setup or test prerequisites that are known but not written down
43+
44+
Do not ask about anything the repo already makes clear.
45+
46+
## Writing rules
47+
48+
Include only high-signal, repo-specific guidance such as:
49+
- exact commands and shortcuts the agent would otherwise guess wrong
50+
- architecture notes that are not obvious from filenames
51+
- conventions that differ from language or framework defaults
52+
- setup requirements, environment quirks, and operational gotchas
53+
- references to existing instruction sources that matter
54+
55+
Exclude:
56+
- generic software advice
57+
- long tutorials or exhaustive file trees
58+
- obvious language conventions
59+
- speculative claims or anything you could not verify
60+
- content better stored in another file referenced via `opencode.json` `instructions`
61+
62+
When in doubt, omit.
63+
64+
Prefer short sections and bullets. If the repo is simple, keep the file simple. If the repo is large, summarize the few structural facts that actually change how an agent should work.
65+
66+
If `AGENTS.md` already exists at `${path}`, improve it in place rather than rewriting blindly. Preserve verified useful guidance, delete fluff or stale claims, and reconcile it with the current codebase.

packages/web/src/content/docs/rules.mdx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,17 @@ To create a new `AGENTS.md` file, you can run the `/init` command in opencode.
1515
You should commit your project's `AGENTS.md` file to Git.
1616
:::
1717

18-
This will scan your project and all its contents to understand what the project is about and generate an `AGENTS.md` file with it. This helps opencode to navigate the project better.
18+
`/init` scans the important files in your repo, may ask a couple of targeted questions when the codebase cannot answer them, and then creates or updates `AGENTS.md` with concise project-specific guidance.
1919

20-
If you have an existing `AGENTS.md` file, this will try to add to it.
20+
It focuses on the things future agent sessions are most likely to need:
21+
22+
- build, lint, and test commands
23+
- command order and focused verification steps when they matter
24+
- architecture and repo structure that are not obvious from filenames alone
25+
- project-specific conventions, setup quirks, and operational gotchas
26+
- references to existing instruction sources like Cursor or Copilot rules
27+
28+
If you already have an `AGENTS.md`, `/init` will improve it in place instead of blindly replacing it.
2129

2230
---
2331

packages/web/src/content/docs/tui.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ Show the help dialog.
153153

154154
### init
155155

156-
Create or update `AGENTS.md` file. [Learn more](/docs/rules).
156+
Guided setup for creating or updating `AGENTS.md`. [Learn more](/docs/rules).
157157

158158
```bash frame="none"
159159
/init

0 commit comments

Comments
 (0)