# Code

Code mode makes changes to files. Before writing anything, it reads the existing codebase so that additions and modifications are consistent with what's already there matching the project's folder structure, naming conventions, import patterns, and code style.

<figure><img src="/files/bp0h75sakPwfFc4rqsd6" alt=""><figcaption></figcaption></figure>

***

### Adding new features

When adding a feature to an existing project, Code mode reads the current architecture before writing anything. New files follow the conventions already in use. New endpoints follow the pattern of existing endpoints. New components follow the pattern of existing components.

```
Add a webhook system so organizations can register HTTPS endpoints
to receive alerts when a specific event type exceeds a threshold.
Retry failed deliveries up to 3 times with exponential backoff.
```

Cora will add the `WebhookEndpoint` model to the schema, create the registration API and management UI, extend the aggregation pipeline to check thresholds, build a delivery service with retry logic, and update the admin panel in a style consistent with the surrounding code.

***

### Refactoring

Code mode can refactor across multiple files simultaneously, maintaining consistency across the change.

```
The rate limiter logic is duplicated in three middleware files.
Extract it into a shared utility and update all three to import from there.
```

```
The dashboard API calls are scattered across components. Move them
into a centralized api.ts client with typed return values.
```

***

### Staying in scope

Code mode works best with clear, scoped prompts. The smaller the scope, the more precise the implementation and the easier the diff is to review. For large features, break them into steps model changes first, then service logic, then API layer, then frontend and run Code mode once per step.

> For changes that touch authentication, API key handling, tenant isolation, or database access patterns, follow up with a Review pass after Code completes.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.codemate.ai/cora/modes/code.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
