> ## Documentation Index
> Fetch the complete documentation index at: https://cisco-ea52c096.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Coding tasks

> Ask Claude Code to write new code, edit existing files, refactor, debug, run tests, and search your codebase — all from the terminal.

Claude Code handles a wide range of software engineering work — from writing new features to tracking down bugs — directly in your terminal. Describe what you want in plain language and Claude uses tools like file reads, shell commands, and code search to get it done.

## Writing new code

Describe the feature or function you want and Claude writes it, places it in the right file, and follows the conventions already in your codebase.

**Example prompts:**

```text theme={null}
Add a /health endpoint to the Express app that returns { status: "ok" } and a 200 status code.
```

```text theme={null}
Write a Python utility function that parses a CSV file and returns a list of dicts. Put it in utils/csv_parser.py.
```

```text theme={null}
Create a React component called UserAvatar that accepts name and imageUrl props and renders a circular image with a fallback to initials.
```

Claude reads surrounding files to match your project's style, naming conventions, and import patterns before writing anything.

## Editing existing code

Point Claude at what to change and it makes targeted edits — without touching unrelated code.

**Example prompts:**

```text theme={null}
In src/auth/validate.ts, add a null check before accessing user.id. If user is null, return a 401 with the message "Session expired".
```

```text theme={null}
Change the database connection timeout in config/db.ts from 30 seconds to 60 seconds.
```

```text theme={null}
Rename the function processUserData to transformUserRecord in services/user.ts and update all call sites.
```

<Tip>
  The more specific you are about file paths and what to change, the more targeted Claude's edits will be.
</Tip>

## Refactoring

Ask Claude to restructure code for clarity, performance, or consistency. Give it context about your goal.

**Example prompts:**

```text theme={null}
Refactor the getUserById function in services/user.ts to use async/await instead of promise chains.
```

```text theme={null}
Extract the validation logic from the register route handler in routes/auth.ts into a separate validateRegistration function.
```

```text theme={null}
The OrderProcessor class in src/orders/processor.ts has grown too large. Split it into separate classes for OrderValidator, OrderPricer, and OrderFulfiller.
```

Claude reads the file first, understands the dependencies, and makes changes that preserve behavior while improving structure.

## Debugging

Share an error message or describe unexpected behavior and Claude diagnoses the cause and fixes it.

**Example prompts:**

```text theme={null}
I'm getting this error when running the app:

TypeError: Cannot read properties of undefined (reading 'id')
    at validateSession (src/auth/validate.ts:42:18)

Can you find and fix the cause?
```

```text theme={null}
The /users API endpoint returns a 500 error when the query parameter `role` is not provided. It should return an empty array instead.
```

```text theme={null}
My unit tests pass locally but fail in CI with "ECONNREFUSED 127.0.0.1:5432". What's going wrong?
```

Claude traces the error, reads relevant source files, and makes the fix — explaining what it found along the way.

## Running and fixing tests

Ask Claude to run your test suite and fix any failures it finds.

**Example prompts:**

```text theme={null}
Run the tests in tests/auth/ and fix any failures.
```

```text theme={null}
Write unit tests for the parseCSV function in utils/csv_parser.py and make sure they all pass.
```

```text theme={null}
The test at line 58 in validate.test.ts is failing. Read the error and fix the assertion or the implementation, whichever is wrong.
```

<Note>
  Claude runs tests using your project's existing test runner (Jest, pytest, Vitest, etc.) via the shell. Make sure your test command works from the terminal before asking Claude to run it.
</Note>

## Searching the codebase

Claude uses ripgrep and glob-based file search to find relevant code before making changes. You can also ask it to search explicitly.

**Example prompts:**

```text theme={null}
Find all places in the codebase where we call sendEmail and tell me what arguments each call uses.
```

```text theme={null}
Which files import from utils/logger.ts?
```

```text theme={null}
Search for any hardcoded API keys or tokens in the src/ directory.
```

Claude returns findings with file paths and line numbers so you can navigate directly to the relevant code.

## Example interactions

<Tabs>
  <Tab title="New feature">
    ```text theme={null}
    > Add pagination to GET /products in routes/products.ts.
      Accept `page` and `limit` query params and return
      { data, total, page, totalPages }.

    [Reading routes/products.ts and the Product model...]
    [Adding pagination logic and updating the response shape...]

    Done. The GET /products handler now accepts `page` (default: 1)
    and `limit` (default: 20). The response includes data, total,
    page, and totalPages.
    ```
  </Tab>

  <Tab title="Bug fix">
    ```text theme={null}
    > The app crashes on startup with:
      "ReferenceError: db is not defined at server.ts:12"

    [Reading server.ts...]

    The `db` import is missing. Line 12 calls `db.connect()` but
    the import was never added. I'll add it now.

    [Editing server.ts to add the missing import...]

    Fixed. The db import is now at the top of server.ts.
    ```
  </Tab>

  <Tab title="Refactor">
    ```text theme={null}
    > The getUser function in services/user.ts is 80 lines long.
      Break it into smaller functions.

    [Reading services/user.ts...]

    I'll extract: fetchUserRecord, validateUserPermissions, and
    formatUserResponse. The main getUser function will call all
    three in sequence.

    [Editing the file...]

    Done. Each extracted function has a single responsibility.
    The existing tests still pass.
    ```
  </Tab>
</Tabs>

## Tips for better prompts

<CardGroup cols={2}>
  <Card title="Include file paths" icon="folder">
    Tell Claude which file to look in. "In src/auth/validate.ts, fix the null check" is faster and more precise than "fix the null check somewhere in auth".
  </Card>

  <Card title="Share the error message" icon="triangle-alert">
    Paste the full error output when debugging. Stack traces, line numbers, and error text all help Claude pinpoint the issue.
  </Card>

  <Card title="Describe the goal, not just the change" icon="target">
    "Extract this into a separate function so it can be unit tested" gives Claude more context than "refactor this function".
  </Card>

  <Card title="Ask for tests alongside code" icon="flask-conical">
    "Write the function and add unit tests for it" in a single prompt ensures the new code is testable from the start.
  </Card>
</CardGroup>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.