Install
openclaw skills install phy-ai-context-genAnalyzes a codebase to generate precise, project-specific AI coding assistant context files for Claude, OpenClaw, Cursor, Windsurf, and GitHub Copilot tools.
openclaw skills install phy-ai-context-genAnalyzes a codebase and generates accurate, project-specific context files for every major AI coding assistant — not boilerplate, but rules derived from what your codebase actually does.
Use when the user says any of:
phy-ai-context-gen or /ai-context-gen| File | Tool | Purpose |
|---|---|---|
CLAUDE.md | Claude Code (Anthropic) | Project instructions, API keys, conventions |
AGENTS.md | OpenClaw / Codex / Antigravity | Agent behavior, allowed commands, tool restrictions |
.cursorrules | Cursor AI | Inline suggestions style, framework rules |
.windsurfrules | Windsurf (Codeium) | Same as cursorrules, Windsurf format |
.github/copilot-instructions.md | GitHub Copilot | Completion style, language patterns |
When this skill is invoked:
Run ALL of the following in parallel to understand the project:
# 1. Directory structure (top 3 levels)
find . -maxdepth 3 -type f -name "*.json" -o -name "*.toml" -o -name "*.yaml" -o -name "*.yml" | grep -v node_modules | grep -v .git | head -30
# 2. Detect package managers and tech stack
cat package.json 2>/dev/null | head -60
cat requirements.txt 2>/dev/null || cat pyproject.toml 2>/dev/null | head -40
cat Cargo.toml 2>/dev/null | head -30
cat go.mod 2>/dev/null | head -20
cat composer.json 2>/dev/null | head -30
cat Gemfile 2>/dev/null | head -20
# 3. Read README (if present)
cat README.md 2>/dev/null | head -80
# 4. Detect test framework
ls -la tests/ test/ __tests__/ spec/ 2>/dev/null
cat jest.config.* 2>/dev/null | head -20
cat pytest.ini 2>/dev/null || cat setup.cfg 2>/dev/null | grep -A10 "\[tool:pytest\]"
# 5. Detect linter / formatter
cat .eslintrc* 2>/dev/null | head -30
cat .prettierrc* 2>/dev/null | head -20
cat .ruff.toml 2>/dev/null || cat ruff.toml 2>/dev/null | head -20
cat .flake8 2>/dev/null | head -20
# 6. Detect CI
ls -la .github/workflows/ 2>/dev/null | head -10
ls -la .gitlab-ci.yml .circleci/ 2>/dev/null
# 7. Check for existing context files to avoid overwriting
ls -la CLAUDE.md AGENTS.md .cursorrules .windsurfrules .github/copilot-instructions.md 2>/dev/null
# 8. Detect framework
ls -la src/app/ src/pages/ app/ pages/ 2>/dev/null # Next.js / React Router
ls -la src/main.py app.py manage.py 2>/dev/null # Python
ls -la cmd/ main.go 2>/dev/null # Go
Also read these files if they exist (limit to first 40 lines each):
src/index.ts, src/main.ts, src/app.ts — entry pointssrc/index.js, src/main.js, src/app.jsmain.py, app.py, __init__.pysrc/main.rs, main.goCLAUDE.md, .cursorrules (read current content before generating)From the gathered data, determine:
Critical: If you cannot determine a value from the files, write # TODO: fill in rather than inventing plausible-sounding defaults.
Generate each file in sequence, then confirm with the user before writing.
CLAUDE.mdFormat:
# [Project Name] — Claude Code Instructions
## Project Overview
[1-2 sentences: what this project does, who uses it]
## Tech Stack
- **Language**: [primary language + version if found]
- **Framework**: [framework name]
- **Package manager**: [npm/yarn/pnpm/pip/poetry/cargo/go]
- **Test runner**: [test command e.g. `npm test`, `pytest`, `go test ./...`]
## Development Commands
```bash
# Install dependencies
[install command]
# Run dev server
[dev command]
# Run tests
[test command]
# Build
[build command]
# Lint
[lint command]
[key directories with one-line descriptions, inferred from actual structure]
In long conversations (10+ exchanges), proactively re-check constraints from earlier in the session.
---
#### File 2: `AGENTS.md`
Format:
```markdown
# [Project Name] — Agent Instructions
## Project Context
[Brief description of what this project does]
## Allowed Operations
- Read any file in the repository
- Run: `[test command]`, `[lint command]`, `[build command]`
- Edit files in: `src/`, `tests/`, `[other safe directories]`
## Restricted Operations
- Do NOT run: `rm -rf`, destructive database commands
- Do NOT modify: `[generated files]`, `[config files that break CI]`
- Do NOT commit without user confirmation
- Do NOT push to remote without explicit approval
## Tech Stack
[Same as CLAUDE.md tech stack section]
## Development Workflow
1. Understand the task — read relevant files before writing
2. Write tests first if adding new functionality
3. Run tests: `[test command]`
4. Run linter: `[lint command]`
5. Only then make the change
## Key File Locations
- Entry point: `[detected entry file]`
- Tests: `[test directory]`
- Config: `[config files]`
- Types/models: `[types directory if present]`
## Tool Preferences
- Search code: use Grep, not `grep` command
- Read files: use Read tool, not `cat`
- File operations: prefer Edit over Write for existing files
.cursorrulesFormat (Cursor prefers compact, imperative style):
# [Project Name] Cursor Rules
## Stack
[Language] + [Framework] project.
Package manager: [manager]. Test runner: [test runner].
## Code Style
- Use [snake_case/camelCase] for [variables/functions]
- Use [PascalCase] for [classes/components]
- [Import style instruction]
- Max function length: [50/40/30] lines
- [Type annotation instruction for TypeScript/Python]
## Patterns to Follow
- [Detected error handling pattern]
- [Detected async pattern]
- [Testing pattern — e.g. "write tests in __tests__/ using Jest describe/it blocks"]
## Patterns to Avoid
- No `any` types in TypeScript / no untyped Python functions
- No `console.log` in production code — use [detected logger]
- No hardcoded credentials or magic numbers
- [Framework-specific antipatterns if detected]
## File Structure
- New features go in: [detected directory]
- Tests go in: [test directory]
- Shared utilities: [utils directory if present]
## Before Suggesting
1. Check if a similar utility already exists in [utils/lib/common directory]
2. Follow the naming conventions in the surrounding files
3. Run `[test command]` to verify changes
.windsurfrulesUse the same content as .cursorrules — Windsurf reads the same format. Note this explicitly so the user knows both files are identical (they can diverge later if preferred).
.github/copilot-instructions.mdFormat (Copilot prefers markdown with ## sections):
# GitHub Copilot Instructions for [Project Name]
## Project Type
[Project type description]. Built with [framework] in [language].
## Coding Standards
### Naming
- Variables and functions: [convention]
- Classes and types: [convention]
- Files: [convention]
- Constants: [convention]
### TypeScript / Python / Go specifics
[Language-specific rules derived from actual codebase patterns]
### Error Handling
[Detected error handling pattern — e.g. "Use try/catch with typed errors, not bare exceptions"]
## Testing
- Framework: [test framework]
- Test files location: [test directory]
- Pattern: [describe/it blocks, pytest classes, etc.]
- Always write tests for new public functions
## Imports
[Import ordering preference if detectable — e.g. "stdlib → third-party → local"]
## What to Avoid
- [Antipatterns specific to this project]
- Do not suggest deprecated [framework] APIs
- Prefer [detected utility library] over implementing from scratch
Before writing:
.github/ directory if it doesn't exist (for copilot-instructions.md)# Create .github directory if needed
mkdir -p .github
# Write files
# (Use Write tool for each file)
After writing, confirm:
✅ Generated 5 AI context files:
- CLAUDE.md (Claude Code)
- AGENTS.md (OpenClaw / Codex)
- .cursorrules (Cursor AI)
- .windsurfrules (Windsurf)
- .github/copilot-instructions.md (GitHub Copilot)
Next step: Review CLAUDE.md and fill in any # TODO: sections.
Add to .gitignore if you don't want to commit: echo ".cursorrules" >> .gitignore
User can request a single file:
If files already exist, user can say "regenerate" or "overwrite" to skip the diff confirmation.
"show me what you'd generate" → display all 5 files without writing them.
DO:
# TODO: [what to fill in] when information isn't determinableDON'T:
| Skill | Focus |
|---|---|
phy-ai-context-gen | Generates files for AI coding tools based on real codebase analysis |
phy-prd-writer | Generates product requirement documents through Q&A |
large-codebase-workflow | Best practices guide for working with large repos |
phy-living-adr | Architecture Decision Records from git diffs |
This skill is the onboarding layer — run it once at project start, or whenever you bring a new AI assistant into an existing project. It removes the "cold start" penalty where the agent wastes the first few messages rediscovering obvious context.
Input: User runs /ai-context-gen in a Next.js 15 + TypeScript + Prisma project.
What Claude does:
package.json → detects Next.js 15, TypeScript, Prisma, Jest, ESLint, PrettierREADME.md → project descriptionsrc/ → finds app/, components/, lib/, prisma/.env.local for secretsGenerated .cursorrules excerpt:
# MyApp Cursor Rules
Next.js 15 App Router + TypeScript + Prisma project.
Package manager: pnpm. Test runner: jest.
## Code Style
- Variables/functions: camelCase
- React components: PascalCase in PascalCase.tsx files
- Imports: React → Next.js → third-party → @/lib → @/components → relative
- No `any` types — use Prisma generated types or explicit interfaces
## Patterns to Follow
- Server components by default, add "use client" only when needed
- Database access only in Server Components or API routes (never in client components)
- Prisma queries go in lib/db/ only
## Before Suggesting
1. Check lib/utils.ts for existing helpers
2. Check components/ui/ for existing UI primitives
3. Run: pnpm test && pnpm lint
Time saved: ~45 minutes of manual writing per new project onboarding.
Canlah AI — Run performance marketing without breaking your brand.