|
| 1 | +--- |
| 2 | +title: Agentic Coding |
| 3 | +description: Leverage AI coding assistants to build higher quality NativeScript applications faster |
| 4 | +contributors: |
| 5 | + - NathanWalker |
| 6 | +--- |
| 7 | + |
| 8 | +Agentic coding refers to using AI-powered coding assistants that can autonomously perform complex multi-step development tasks. These tools go beyond simple code completion; they can understand your entire codebase, make architectural decisions, write tests, and implement features end-to-end. |
| 9 | + |
| 10 | +## Why Agentic Coding for NativeScript? |
| 11 | + |
| 12 | +NativeScript's architecture provides the following: |
| 13 | + |
| 14 | +- **Direct native API access** - AI agents need to understand both JavaScript/TypeScript and native iOS/Android APIs |
| 15 | +- **Cross-platform patterns** - Agents must generate code that works correctly on multiple platforms |
| 16 | +- **Framework flexibility** - Code generation should adapt to Angular, Vue, Solid, Svelte, React, or plain TypeScript |
| 17 | +- **Performance considerations** - Agents should follow best practices for native mobile performance |
| 18 | + |
| 19 | +By providing proper context, AI coding assistants can generate high-quality NativeScript code that follows best practices and leverages the full power of the platform. |
| 20 | + |
| 21 | +## The NATIVESCRIPT.md Context File |
| 22 | + |
| 23 | +NativeScript provides a comprehensive context file that can be used with any AI coding assistant to dramatically improve code generation quality. This file contains: |
| 24 | + |
| 25 | +- Project structure conventions |
| 26 | +- Core API patterns and imports |
| 27 | +- UI component reference |
| 28 | +- Best practices for performance |
| 29 | +- Platform-specific code patterns |
| 30 | +- Framework integration examples |
| 31 | +- Custom view creation patterns |
| 32 | + |
| 33 | +### Getting the Context File |
| 34 | + |
| 35 | +The `NATIVESCRIPT.md` file is available for download: |
| 36 | + |
| 37 | +**[Download NATIVESCRIPT.md](https://docs.nativescript.org/assets/agentic/NATIVESCRIPT.md)** |
| 38 | + |
| 39 | +You can also download it via the command line: |
| 40 | + |
| 41 | +```bash |
| 42 | +curl -o CLAUDE.md https://docs.nativescript.org/assets/agentic/NATIVESCRIPT.md |
| 43 | +``` |
| 44 | + |
| 45 | +## Using with Claude Code |
| 46 | + |
| 47 | +[Claude Code](https://code.claude.com) is Anthropic's agentic coding tool that runs in your terminal. It uses `CLAUDE.md` files to understand project context. |
| 48 | + |
| 49 | +### Setup |
| 50 | + |
| 51 | +1. Download the NativeScript context file to your project root: |
| 52 | + |
| 53 | +```bash |
| 54 | +curl -o CLAUDE.md https://docs.nativescript.org/assets/agentic/NATIVESCRIPT.md |
| 55 | +``` |
| 56 | + |
| 57 | +2. Optionally, add project-specific instructions at the top of the file: |
| 58 | + |
| 59 | +```markdown |
| 60 | +# Project Context |
| 61 | + |
| 62 | +This is a NativeScript Vue 3 application for managing recipes. |
| 63 | + |
| 64 | +## Project-Specific Patterns |
| 65 | +- We use Pinia for state management |
| 66 | +- API calls go through `src/services/api.ts` |
| 67 | +- All components are in `src/components/` |
| 68 | + |
| 69 | +--- |
| 70 | + |
| 71 | +# NativeScript AI Agent Context |
| 72 | +... (rest of NATIVESCRIPT.md content) |
| 73 | +``` |
| 74 | + |
| 75 | +3. Start Claude Code in your project: |
| 76 | + |
| 77 | +```bash |
| 78 | +cd your-nativescript-project |
| 79 | +claude |
| 80 | +``` |
| 81 | + |
| 82 | +Claude will automatically read the `CLAUDE.md` file and use it to inform all code generation. |
| 83 | + |
| 84 | +### Example Prompts |
| 85 | + |
| 86 | +With the context file in place, you can give high-level instructions: |
| 87 | + |
| 88 | +``` |
| 89 | +Create a settings page with switches for notifications, dark mode, and location tracking. |
| 90 | +Save preferences using ApplicationSettings. |
| 91 | +``` |
| 92 | + |
| 93 | +``` |
| 94 | +Build a ListView that shows products with images, names, and prices. |
| 95 | +Use template selectors for featured vs regular items. |
| 96 | +``` |
| 97 | + |
| 98 | +``` |
| 99 | +Create a custom native view that wraps Android's MaterialCardView and iOS's UIVisualEffectView. |
| 100 | +``` |
| 101 | + |
| 102 | +## Using with Other AI Tools |
| 103 | + |
| 104 | +The `NATIVESCRIPT.md` context file works with any AI coding assistant that supports custom context: |
| 105 | + |
| 106 | +### GitHub Copilot |
| 107 | + |
| 108 | +Download and add to your workspace's `.github/copilot-instructions.md`: |
| 109 | + |
| 110 | +```bash |
| 111 | +curl -o .github/copilot-instructions.md https://docs.nativescript.org/assets/agentic/NATIVESCRIPT.md |
| 112 | +``` |
| 113 | + |
| 114 | +### Cursor |
| 115 | + |
| 116 | +Add to your `.cursorrules` file or include in your project's context settings. |
| 117 | + |
| 118 | +### Windsurf |
| 119 | + |
| 120 | +Add to your workspace's `.windsurfrules` file. |
| 121 | + |
| 122 | +### ChatGPT / Claude.ai Web |
| 123 | + |
| 124 | +Copy the relevant sections into your conversation as context before asking NativeScript-related questions. |
| 125 | + |
| 126 | +## Best Practices for AI-Assisted NativeScript Development |
| 127 | + |
| 128 | +### 1. Be Specific About Your Framework |
| 129 | + |
| 130 | +When prompting, specify which framework you're using: |
| 131 | + |
| 132 | +``` |
| 133 | +Using NativeScript with Vue 3, create a component that... |
| 134 | +``` |
| 135 | + |
| 136 | +``` |
| 137 | +In my Angular NativeScript app, implement a service that... |
| 138 | +``` |
| 139 | + |
| 140 | +``` |
| 141 | +Using NativeScript with SolidJS, build a custom directive that... |
| 142 | +``` |
| 143 | + |
| 144 | +``` |
| 145 | +While using NativeScript with React, create a functional component that... |
| 146 | +``` |
| 147 | + |
| 148 | +``` |
| 149 | +Using NativeScript with Svelte, create a store that... |
| 150 | +``` |
| 151 | + |
| 152 | +### 2. Reference Platform When Needed |
| 153 | + |
| 154 | +For platform-specific features, mention the target: |
| 155 | + |
| 156 | +``` |
| 157 | +Create an iOS-specific implementation that uses UIBlurEffect. You can reference it here https://developer.apple.com/documentation/uikit/uiblureffect?language=objc |
| 158 | +``` |
| 159 | + |
| 160 | +``` |
| 161 | +Add Android haptic feedback using the native Vibrator API. You can reference it here https://developer.android.com/reference/android/os/Vibrator |
| 162 | +``` |
| 163 | + |
| 164 | +### 3. Mention Performance Requirements |
| 165 | + |
| 166 | +Help the AI understand performance constraints: |
| 167 | + |
| 168 | +``` |
| 169 | +This will be used in a ListView with 1000+ items, so optimize for scroll performance. |
| 170 | +``` |
| 171 | + |
| 172 | +``` |
| 173 | +This animation runs during user interaction, keep it on the UI thread. |
| 174 | +``` |
| 175 | + |
| 176 | +### 4. Describe the User Experience |
| 177 | + |
| 178 | +Provide UX context for better implementations: |
| 179 | + |
| 180 | +``` |
| 181 | +Create a pull-to-refresh list that shows a loading indicator while fetching new data. |
| 182 | +``` |
| 183 | + |
| 184 | +``` |
| 185 | +Build a form that validates on blur and shows inline error messages. |
| 186 | +``` |
| 187 | + |
| 188 | +### 5. Request Tests When Appropriate |
| 189 | + |
| 190 | +``` |
| 191 | +Create unit tests for the data transformation logic in this service. |
| 192 | +``` |
| 193 | + |
| 194 | +## Extending the Context File |
| 195 | + |
| 196 | +For team projects, consider extending the base context file with project-specific information: |
| 197 | + |
| 198 | +### Create a Project-Specific Section |
| 199 | + |
| 200 | +```markdown |
| 201 | +# Project: Recipe Manager App |
| 202 | + |
| 203 | +## Architecture |
| 204 | +- Feature-based folder structure (`src/features/recipes/`, `src/features/auth/`) |
| 205 | +- Shared components in `src/shared/components/` |
| 206 | +- All API calls through `src/core/api/client.ts` |
| 207 | + |
| 208 | +## Conventions |
| 209 | +- Use `const` for all variables unless reassignment is needed |
| 210 | +- Prefer composition over inheritance |
| 211 | +- All async operations use async/await (no raw promises) |
| 212 | + |
| 213 | +## State Management |
| 214 | +- Pinia stores in `src/stores/` |
| 215 | +- Each feature has its own store |
| 216 | + |
| 217 | +--- |
| 218 | + |
| 219 | +@CLAUDE.md |
| 220 | +``` |
| 221 | + |
| 222 | +The `@` import syntax (supported in Claude Code) lets you reference the base file without duplicating its contents. Just ensure you've downloaded `NATIVESCRIPT.md` as `CLAUDE.md` in your project root. |
| 223 | + |
| 224 | +### Add Framework-Specific Rules |
| 225 | + |
| 226 | +If your team uses specific patterns, document them: |
| 227 | + |
| 228 | +```markdown |
| 229 | +## Vue Component Patterns |
| 230 | + |
| 231 | +- Use `<script setup lang="ts">` for all components |
| 232 | +- Props must have TypeScript types defined |
| 233 | +- Emit events using `defineEmits` with typed payloads |
| 234 | +- Use `v-model` for two-way binding with form inputs |
| 235 | +``` |
| 236 | + |
| 237 | +## Security Considerations |
| 238 | + |
| 239 | +When using AI coding assistants: |
| 240 | + |
| 241 | +- **Never include secrets** in context files (API keys, passwords) |
| 242 | +- **Review generated code** before committing, especially for security-sensitive features |
| 243 | +- **Validate native API usage** - ensure proper permissions are requested |
| 244 | +- **Test on real devices** - Even if something runs in emulators, always verify on actual devices |
| 245 | + |
| 246 | +## Troubleshooting |
| 247 | + |
| 248 | +### AI Generates Web-Specific Code |
| 249 | + |
| 250 | +If the AI generates DOM-based code instead of NativeScript: |
| 251 | + |
| 252 | +- Ensure the context file is properly loaded |
| 253 | +- Explicitly mention "NativeScript" in your prompts |
| 254 | +- Specify the target platforms (iOS/Android/visionOS) |
| 255 | + |
| 256 | +### Generated Code Uses Outdated APIs |
| 257 | + |
| 258 | +- Update to the latest `@nativescript/core` to get the current context file |
| 259 | +- Mention the NativeScript version you're using in prompts |
| 260 | + |
| 261 | +### Framework-Specific Syntax Issues |
| 262 | + |
| 263 | +- Verify your context file includes the correct framework examples |
| 264 | +- Add your framework's specific patterns to the context |
| 265 | + |
| 266 | +## Resources |
| 267 | + |
| 268 | +- [Download NATIVESCRIPT.md](https://docs.nativescript.org/assets/agentic/NATIVESCRIPT.md) |
| 269 | +- [Claude Code Documentation](https://code.claude.com/docs) |
| 270 | +- [NativeScript Best Practices](/best-practices/) |
| 271 | +- [Creating Custom Elements](/guide/create-custom-native-elements) |
0 commit comments