@shikijs/cli | Shiki

ID: 1759https://shiki.matsu.io/packages/cli
Source

@shikijs/cli

NPM version
NPM downloads
GitHub

Shiki in the command line.

Usage

The Shiki CLI works like cat command, but with syntax highlighting.

npx @shikijs/cli README.md

Install

You can also install it globally. Command aliases @shikijs/cli, shiki, and skat are registered.

# npm
npm i -g @shikijs/cli

# yarn
yarn global add @shikijs/cli

# pnpm
pnpm add -g @shikijs/cli

# bun
bun add -g @shikijs/cli

# deno
deno install -gREn skat npm:@shikijs/cli

Example usage:

skat src/index.ts

Options

--theme

Specify the theme to use. Defaults to vitesse-dark.

npx @shikijs/cli README.md --theme=nord

--lang

Language is auto‑inferred from the file extension. You can override it with --lang.

npx @shikijs/cli src/index.js --lang=ts

Node.js API

The @shikijs/cli package also provides a Node.js API.

# Install
npm i @shikijs/cli
yarn add @shikijs/cli
pnpm add @shikijs/cli
bun add @shikijs/cli
deno install npm:@shikijs/cli

codeToANSI

The asynchronous codeToANSI function allows you to convert code to ANSI escape codes for terminal output. This is useful for rendering syntax‑highlighted code in the terminal.

import { codeToANSI } from '@shikijs/cli';

const highlighted = await codeToANSI(source, 'typescript', 'nord');

console.log(highlighted);

codeToANSI takes three required parameters:

  1. code: string
  2. lang: BundledLanguage
  3. theme: BundledTheme