Skip to content
Back to skills

Auto Detect Ci

ASecurity

Add automatic CI/CD environment detection using ci-info package. Generic pattern for any CLI tool that needs to adapt behavior (prompts, output, integrations) based on whether it's running in CI.

  • 2 stars
  • 0 votes
  • 0 copies
  • 4 views
  • Added September 10, 2026
toolsgobashtestinggitci/cd

Works with

  • terminal
  • cli

Security analysis

A96/100
  • mediumInstalls packages at runtime which could introduce malicious dependencies

Pro shows the line behind each finding and how to fix it

Scanned September 10, 2026

npx -y skills add krafteq/infraglue --skill auto-detect-ci --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Auto Detect Ci?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Auto Detect Ci
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/krafteq-auto-detect-ci/badge)](https://www.skillsdirectory.com/skills/krafteq-auto-detect-ci)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: auto-detect-ci
description: Add automatic CI/CD environment detection using ci-info package. Generic pattern for any CLI tool that needs to adapt behavior (prompts, output, integrations) based on whether it's running in CI.
---

# Auto-Detect CI Environment

## Goal

Automatically detect CI environments and adapt CLI behavior — removing the need for explicit flags in most cases.

## Install

```bash
pnpm add ci-info
```

## Implementation

### Detection Function

```ts
import ci from 'ci-info'

type RunMode = 'interactive' | 'non-interactive' | string

function detectRunMode(explicit?: string): RunMode {
  // Explicit flag always wins
  if (explicit) return explicit

  // CI environment detected
  if (ci.isCI) {
    // Add CI-specific modes as needed, e.g.:
    // if (ci.GITLAB) return 'gitlab'
    // if (ci.GITHUB_ACTIONS) return 'github-actions'
    return 'non-interactive'
  }

  // Local: check if terminal is interactive
  return process.stdout.isTTY ? 'interactive' : 'non-interactive'
}
```

### Integration Points

1. In Commander action handlers, use detection as default:

```ts
const mode = detectRunMode(options.mode)
```

2. Log the detected mode in verbose/debug:

```ts
if (isDebug()) {
  logger.debug(`Run mode: ${mode}${ci.isCI ? ` (detected: ${ci.name})` : ''}`)
}
```

### Behavior Matrix

| Environment                     | TTY | Explicit flag            | Result                        |
| ------------------------------- | --- | ------------------------ | ----------------------------- |
| Local terminal                  | yes | not set                  | `interactive`                 |
| Local pipe (`mycli show \| jq`) | no  | not set                  | `non-interactive`             |
| GitHub Actions                  | no  | not set                  | `non-interactive`             |
| GitLab CI                       | no  | not set                  | `non-interactive`             |
| Any CI                          | no  | `interactive` (explicit) | `interactive` (user override) |

### Where to Apply

- Commands with interactive prompts (confirmations, selections)
- Output formatting (spinners vs plain text)
- Approval flows (auto-approve in CI vs prompt in terminal)
- Any behavior that differs between human and automated usage

### Testing

```ts
test('detects CI from environment', () => {
  vi.mock('ci-info', () => ({ isCI: true, GITLAB: false, name: 'GitHub Actions' }))
  expect(detectRunMode()).toBe('non-interactive')
})

test('explicit flag overrides detection', () => {
  expect(detectRunMode('interactive')).toBe('interactive')
})
```

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.