Skip to content

feat(nx-plugin): emit AGENTS.md and CLAUDE.md from the app generator - #2465

Merged
brandonroberts merged 1 commit into
betafrom
feat/2463-app-generator-agent-context
Aug 6, 2026
Merged

feat(nx-plugin): emit AGENTS.md and CLAUDE.md from the app generator#2465
brandonroberts merged 1 commit into
betafrom
feat/2463-app-generator-agent-context

Conversation

@brandonroberts

Copy link
Copy Markdown
Member

PR Checklist

The preset generator seeds AGENTS.md and CLAUDE.md pointing at node_modules/@analogjs/platform/AGENTS.md, but the app generator emitted neither. Whether an Analog app shipped with agent guidance depended on how it was created.

Closes #2463

Affected scope

  • Primary scope: nx-plugin
  • Secondary scopes: docs

Recommended merge strategy for maintainer [optional]

  • Squash merge
  • Rebase merge
  • Other

Commit preservation note [optional]

N/A

What is the new behavior?

  • nx g @analogjs/platform:application <name> now writes AGENTS.md and CLAUDE.md into the app folder (apps/<name>/), so the guidance stays scoped to the Analog app in a workspace that may hold other projects.
  • Either file is skipped if it already exists, so re-running the generator, or adding Analog to a project that already has hand-written agent docs, does not clobber anything.
  • The two templates moved from preset/files/ to app/files/agents/ and are now shared by both generators, so there is one source of truth for the content.
  • The preset still seeds them at the workspace root, since that workspace is created for Analog. It passes an internal skipAgentContext flag into the app generator so a preset generated workspace does not end up with duplicate copies at the root and in the app folder.
  • Added an "Agent Context" section to the Nx integration guide covering both placements.

Test plan

  • nx format:check
  • pnpm build (ran nx build nx-plugin, and verified the templates land at src/generators/app/files/agents/ in the built package so the generator resolves them at runtime)
  • pnpm test (ran nx test nx-plugin, 25 tests passing)
  • Manual verification

New tests cover the app generator emitting the files into the app folder and leaving an existing AGENTS.md untouched. The preset spec now also asserts no app level copies are created.

nx lint nx-plugin reports only pre-existing warnings, none from the new code.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

The placement split (preset at the workspace root, app generator in the app folder) is the decision the issue flagged as non-obvious. Root placement makes sense when the workspace exists for Analog, and app folder placement avoids putting Analog specific guidance at the root of a mixed workspace or overwriting a root CLAUDE.md that is already there.

🤖 Generated with Claude Code

The preset generator seeded agent context files pointing at
node_modules/@analogjs/platform/AGENTS.md, but the app generator emitted
neither, so whether an Analog app had agent guidance depended on how it
was created.

The app generator now writes AGENTS.md and CLAUDE.md into the app folder,
keeping the guidance scoped to the Analog app in a workspace that may hold
other projects. Existing files are left alone, so re-running the generator
or adding Analog to a project with hand-written agent docs is safe.

The templates moved to the app generator and are shared with the preset,
which still seeds them at the workspace root and now skips the app-level
copies to avoid duplicating them in a preset generated workspace.

Closes #2463

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SbfASDa35cNavxsHVBPpEP
@netlify

netlify Bot commented Aug 6, 2026

Copy link
Copy Markdown

Deploy Preview for analog-blog ready!

Name Link
🔨 Latest commit 6c84b87
🔍 Latest deploy log https://app.netlify.com/projects/analog-blog/deploys/6a74fe07fb820b0008218227
😎 Deploy Preview https://deploy-preview-2465--analog-blog.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented Aug 6, 2026

Copy link
Copy Markdown

Deploy Preview for analog-docs ready!

Name Link
🔨 Latest commit 6c84b87
🔍 Latest deploy log https://app.netlify.com/projects/analog-docs/deploys/6a74fe07bd703a0008d996f1
😎 Deploy Preview https://deploy-preview-2465--analog-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented Aug 6, 2026

Copy link
Copy Markdown

Deploy Preview for analog-app ready!

Name Link
🔨 Latest commit 6c84b87
🔍 Latest deploy log https://app.netlify.com/projects/analog-app/deploys/6a74fe076252f200082f3df2
😎 Deploy Preview https://deploy-preview-2465--analog-app.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The Nx app generator now creates missing AGENTS.md and CLAUDE.md files from bundled templates while preserving existing files. The preset generator disables project-local generation and places the same context files at the workspace root. Tests cover creation, preservation, and preset placement. Nx integration documentation describes the generated files and their locations.

Estimated code review effort: 3 (Moderate) | ~20 minutes

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title uses the required Conventional Commit format and accurately describes the nx-plugin change.
Description check ✅ Passed The description clearly explains the generator behavior, file placement, preservation rules, tests, and documentation changes.
Linked Issues check ✅ Passed The changes satisfy issue #2463 by adding app-level agent guidance, preserving existing files, and avoiding duplicate preset output.
Out of Scope Changes check ✅ Passed The changes remain within the linked issue scope, including required tests, preset coordination, shared templates, and related documentation.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/nx-plugin/src/generators/app/generator.spec.ts`:
- Around line 213-225: Update the “does not overwrite existing agent context in
the app” test to seed both AGENTS.md and CLAUDE.md with custom content before
calling generator. Assert that each file still exists and contains its
respective custom content after generation, preserving the existing test setup
and generator invocation.

In `@packages/nx-plugin/src/generators/preset/generator.ts`:
- Around line 18-23: Update the preset generator’s generateFiles call in
packages/nx-plugin/src/generators/preset/generator.ts:18-23 to use the
existing-file-safe agent context path/strategy already used by the app-level
generator, and add a regression test confirming root AGENTS.md and CLAUDE.md
files are preserved. Update
apps/docs-analog/src/content/integrations/nx/index.md:89-91 to state the
conditions under which existing root context files are preserved instead of
claiming they are never overwritten.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 05ff51fe-c7e7-42bc-a0ba-e2ded9488eee

📥 Commits

Reviewing files that changed from the base of the PR and between b684396 and 6c84b87.

📒 Files selected for processing (9)
  • apps/docs-analog/src/content/integrations/nx/index.md
  • packages/nx-plugin/src/generators/app/files/agents/AGENTS.md
  • packages/nx-plugin/src/generators/app/files/agents/CLAUDE.md
  • packages/nx-plugin/src/generators/app/generator.spec.ts
  • packages/nx-plugin/src/generators/app/generator.ts
  • packages/nx-plugin/src/generators/app/lib/add-agent-context.ts
  • packages/nx-plugin/src/generators/app/schema.d.ts
  • packages/nx-plugin/src/generators/preset/generator.spec.ts
  • packages/nx-plugin/src/generators/preset/generator.ts

Comment on lines +213 to +225
it('does not overwrite existing agent context in the app', async () => {
const analogAppName = 'existing-agents-app';
const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });

addDependenciesToPackageJson(tree, {}, { nx: '21.0.0' });
tree.write(`apps/${analogAppName}/AGENTS.md`, '# Custom guidance');

await generator(tree, { analogAppName });

expect(tree.read(`apps/${analogAppName}/AGENTS.md`).toString()).toContain(
'# Custom guidance',
);
expect(tree.exists(`apps/${analogAppName}/CLAUDE.md`)).toBe(true);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Cover preservation for both agent files.

The test seeds only AGENTS.md. It does not prove that an existing CLAUDE.md survives. Seed both files and assert that both custom contents remain after generation.

Proposed test update
       tree.write(`apps/${analogAppName}/AGENTS.md`, '# Custom guidance');
+      tree.write(
+        `apps/${analogAppName}/CLAUDE.md`,
+        '# Custom Claude guidance',
+      );

       await generator(tree, { analogAppName });

       expect(tree.read(`apps/${analogAppName}/AGENTS.md`).toString()).toContain(
         '# Custom guidance',
       );
+      expect(tree.read(`apps/${analogAppName}/CLAUDE.md`).toString()).toContain(
+        '# Custom Claude guidance',
+      );
       expect(tree.exists(`apps/${analogAppName}/CLAUDE.md`)).toBe(true);

As per coding guidelines, tests must validate behavior for new functionality.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
it('does not overwrite existing agent context in the app', async () => {
const analogAppName = 'existing-agents-app';
const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
addDependenciesToPackageJson(tree, {}, { nx: '21.0.0' });
tree.write(`apps/${analogAppName}/AGENTS.md`, '# Custom guidance');
await generator(tree, { analogAppName });
expect(tree.read(`apps/${analogAppName}/AGENTS.md`).toString()).toContain(
'# Custom guidance',
);
expect(tree.exists(`apps/${analogAppName}/CLAUDE.md`)).toBe(true);
it('does not overwrite existing agent context in the app', async () => {
const analogAppName = 'existing-agents-app';
const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
addDependenciesToPackageJson(tree, {}, { nx: '21.0.0' });
tree.write(`apps/${analogAppName}/AGENTS.md`, '# Custom guidance');
tree.write(
`apps/${analogAppName}/CLAUDE.md`,
'# Custom Claude guidance',
);
await generator(tree, { analogAppName });
expect(tree.read(`apps/${analogAppName}/AGENTS.md`).toString()).toContain(
'# Custom guidance',
);
expect(tree.read(`apps/${analogAppName}/CLAUDE.md`).toString()).toContain(
'# Custom Claude guidance',
);
expect(tree.exists(`apps/${analogAppName}/CLAUDE.md`)).toBe(true);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/nx-plugin/src/generators/app/generator.spec.ts` around lines 213 -
225, Update the “does not overwrite existing agent context in the app” test to
seed both AGENTS.md and CLAUDE.md with custom content before calling generator.
Assert that each file still exists and contains its respective custom content
after generation, preserving the existing test setup and generator invocation.

Source: Coding guidelines

Comment on lines +18 to +23
generateFiles(
tree,
join(__dirname, '..', 'app', 'files', 'agents'),
'.',
options,
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== workspace files =="
git ls-files | rg '(^packages/nx-plugin/src/generators/preset/generator\.ts$|^apps/docs-analog/src/content/integrations/nx/index\.md$|^workspace\.json$|^nx\.json$|^package\.json$|jest|test|migrations|schematics|generators|agents|CLAUDE|AGENTS)' | head -200

echo
echo "== target preset generator =="
if [ -f packages/nx-plugin/src/generators/preset/generator.ts ]; then
  cat -n packages/nx-plugin/src/generators/preset/generator.ts
fi

echo
echo "== generator files snippets =="
fd -t f 'generator\.ts$' packages/nx-plugin/src/generators | while read -r f; do
  echo "--- $f"
  rg -n "generateFiles|OverwriteStrategy|addAgentContext|CLAUDE|AGENTS|agents" "$f" || true
done

echo
echo "== app/agenerator files snippets =="
fd -t f 'generator\.ts$' packages/nx-plugin/src/generators | while read -r f; do
  echo "--- $f"
  rg -n "generateFiles\(|OverwriteStrategy|addAgentContext|AGENTS|CLAUDE|agents" "$f" || true
done

Repository: analogjs/analog

Length of output: 14279


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== package deps nx version =="
node - <<'JS'
const fs = require('fs');
const p = JSON.parse(fs.readFileSync('package.json','utf8'));
if (p.devDependencies?.nx) console.log('package.json devDependencies.nx:', p.devDependencies.nx);
if (p.dependencies?.nx) console.log('package.json dependencies.nx:', p.dependencies.nx);
JS

echo
echo "== preset generator =="
cat -n packages/nx-plugin/src/generators/preset/generator.ts

echo
echo "== app generator relevant sections =="
cat -n packages/nx-plugin/src/generators/app/generator.ts | sed -n '1,220p'

echo
echo "== references to generateFiles and KeepExisting =="rg
rg -n "generateFiles\(|OverwriteStrategy|KeepExisting|addAgentContext|AGENTS\.md|CLAUDE\.md|agents" packages/nx-plugin packages -g '*.ts' -g '*.json' | head -200

echo
echo "== tests relevant references =="
rg -n "preset|generateFiles|KeepExisting|AGENTS|CLAUDE|agent" packages/nx-plugin -g '*.spec.ts' -g '*.ts' | head -200

Repository: analogjs/analog

Length of output: 21086


🌐 Web query:

Nx generateFiles default overwrite strategy OverwriteStrategy KeepExisting

💡 Result:

In Nx, the generateFiles function supports an optional configuration to control how existing files are handled using the OverwriteStrategy [1][2]. To use the KeepExisting strategy, you pass an options object as the final argument to generateFiles [1][3]: generateFiles(tree, srcFolder, target, substitutions, { overwriteStrategy: OverwriteStrategy.KeepExisting }); Available strategies in the OverwriteStrategy enumeration include [4][5]: OverwriteStrategy.Overwrite (default): Automatically overwrites existing files [1][3]. OverwriteStrategy.KeepExisting: Only creates files if the target does not already exist; existing files are preserved [1][3]. OverwriteStrategy.ThrowIfExisting: Throws an exception if a target file already exists, which is useful when a pristine environment is required [1][3].

Citations:


Preserve existing root agent context files in preset-generated workspaces.

Preset agent context generation uses generateFiles with Nx’s default overwrite strategy, so root AGENTS.md or CLAUDE.md files can be replaced. Implement the same existing-file safeguard documented for app-level agent context at the workspace root, and add a regression test.

  • packages/nx-plugin/src/generators/preset/generator.ts#L18-L23: Use the existing-file-safe agent context path/strategy.
  • apps/docs-analog/src/content/integrations/nx/index.md#L89-91: Update this claim to describe when existing root files are preserved rather than saying they are never overwritten.
📍 Affects 2 files
  • packages/nx-plugin/src/generators/preset/generator.ts#L18-L23 (this comment)
  • apps/docs-analog/src/content/integrations/nx/index.md#L89-L91
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/nx-plugin/src/generators/preset/generator.ts` around lines 18 - 23,
Update the preset generator’s generateFiles call in
packages/nx-plugin/src/generators/preset/generator.ts:18-23 to use the
existing-file-safe agent context path/strategy already used by the app-level
generator, and add a regression test confirming root AGENTS.md and CLAUDE.md
files are preserved. Update
apps/docs-analog/src/content/integrations/nx/index.md:89-91 to state the
conditions under which existing root context files are preserved instead of
claiming they are never overwritten.

Source: Path instructions

@github-actions github-actions Bot added scope:docs Documentation changes scope:nx-plugin Changes in @analogjs/nx-plugin labels Aug 6, 2026
@nx-cloud

nx-cloud Bot commented Aug 6, 2026

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit 6c84b87

Command Status Duration Result
nx run-many --target build --all --parallel=1 -... ❌ Failed 1m 52s View ↗
nx run-many --target lint --all --exclude=conte... ✅ Succeeded 1m 54s View ↗
nx-cloud record -- pnpm prettier:check ✅ Succeeded 10s View ↗

💡 Dealing with memory or CPU issues? See memory and CPU details with the resource usage add-on ↗.


☁️ Nx Cloud last updated this comment at 2026-08-06 22:10:13 UTC

@brandonroberts
brandonroberts merged commit 28ca452 into beta Aug 6, 2026
18 of 21 checks passed
@brandonroberts
brandonroberts deleted the feat/2463-app-generator-agent-context branch August 6, 2026 23:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope:docs Documentation changes scope:nx-plugin Changes in @analogjs/nx-plugin

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: emit AGENTS.md and CLAUDE.md from the app generator

1 participant