# custom-command-example

> Example of custom commands in ag-bash

Latest version **1.3.3** (published 2026-09-24) · 0 weekly downloads

## Install

```sh
npm install custom-command-example
pnpm add custom-command-example
yarn add custom-command-example
bun add custom-command-example
```

## Health

**Score 65/100 (B)** — status: active.

Positive: esm support; no vulnerabilities; has provenance; recently updated; high maintenance score.

Warnings: low downloads; no types.

## Facts

| | |
|---|---|
| Version | 1.3.3 |
| Published | 2026-09-24 |
| First published | 2026-04-24 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | ESM |
| Dependencies | 4 |
| Unpacked size | 24 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 0 |
| Maintainers | sairamugge-0000 |

## Links

- npm: https://www.npmjs.com/package/custom-command-example
- Repository: https://github.com/sairam0424/ag-bash
- Homepage: https://github.com/sairam0424/ag-bash#readme
- Issues: https://github.com/sairam0424/ag-bash/issues
- npm.io page: https://npm.io/package/custom-command-example

## Dependencies (4)

- [ai](https://npm.io/package/ai.md) ^6.0.66
- [@ag-bash/bash](https://npm.io/package/@ag-bash/bash.md) 6.0.5
- [@ai-sdk/gateway](https://npm.io/package/@ai-sdk/gateway.md) ^3.0.2
- [@steipete/summarize-core](https://npm.io/package/@steipete/summarize-core.md) ^0.21.0

## Recent versions

- 1.3.3 (latest) — 2026-09-24
- 1.3.2 — 2026-06-15
- 1.3.1 — 2026-06-15
- 1.3.0 — 2026-04-24

## README

# Custom Commands Example

This example demonstrates how to extend @ag-bash/bash with custom TypeScript commands.

## Commands Included

- **uuid** - Generate random UUIDs (`uuid -n 5` for multiple)
- **json-format** - Pretty-print JSON from stdin or file
- **lorem** - Generate lorem ipsum text (`lorem 3` for 3 paragraphs)
- **wordcount** - Count lines, words, and characters with labels
- **reverse** - Reverse text character by character
- **summarize** - Summarize a URL to markdown (uses [@steipete/summarize-core](https://github.com/steipete/summarize))

## Running the Example

```bash
# Install dependencies
pnpm install

# Run the demo
pnpm start

# To enable the summarize command, set your AI Gateway API key:
AI_GATEWAY_API_KEY=your-key pnpm start
```

## Summarize Command

The `summarize` command fetches content from a URL and generates a markdown summary:

```bash
# Summarize a URL and save to file
summarize https://example.com > summary.md

# Summarize with specific length
summarize --length short https://example.com > summary.md
```

This demonstrates how custom commands can:
- Make network requests (via summarize-core's content extraction)
- Use AI APIs (AI Gateway with Claude)
- Output to files via shell redirection

## Creating Your Own Commands

Use `defineCommand` from @ag-bash/bash:

```typescript
import { defineCommand } from "@ag-bash/bash";

const myCommand = defineCommand("mycommand", async (args, ctx) => {
  // args: command arguments (string[])
  // ctx: CommandContext with fs, cwd, env, stdin, exec
  
  return {
    stdout: "output here\n",
    stderr: "",
    exitCode: 0,
  };
});
```

Then register it:

```typescript
const bash = new Bash({
  customCommands: [myCommand],
});
```

## CommandContext

Your command receives a context object with:

- `fs` - Virtual filesystem interface
- `cwd` - Current working directory
- `env` - Environment variables
- `stdin` - Standard input (from pipes)
- `exec` - Function to run subcommands

---
_Source: https://npm.io/package/custom-command-example · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
