Chalk advanced

From TerminalSkills/skills · View interactive version

Chalk advanced is an AI agent skill from the GitHub repository TerminalSkills/skills. Chalk colors and styles text in the terminal with a chainable API for Node.js (bold, underline, 16/256/truecolor, backgrounds). Use when adding colors to CLI output, formatting log messages, styling errors and warnings, honoring --no-color and FORCE_COLOR, or building developer tools with readable o

How to use this skill

Skill file

Chalk

Overview

Chalk styles terminal strings with colors, bold, underline and backgrounds. The current release is chalk 6.0.1 (checked 2026-10-24 on npm): ESM only, Node.js 22 or newer. Styles chain (chalk.red.bold), and Chalk downsamples truecolor to what the terminal supports. If you must stay on an older Node.js, pin chalk 5 (npm install chalk@5); the API shown here is the same. Chalk 4 is the last CommonJS version.

Instructions

Step 1: Basic styling

import chalk from "chalk";

console.log(chalk.green("✓ Success"));
console.log(chalk.red.bold("✗ Error: file not found"));
console.log(chalk.yellow("⚠ Warning: deprecated API"));
console.log(chalk.blue.underline("https://terminalskills.io"));
console.log(chalk.gray("  (verbose details)"));

console.log(chalk.bgRed.white.bold(" ERROR ") + " Something went wrong");
console.log(chalk.hex("#ff8800").bold("Orange"), chalk.rgb(15, 100, 204)("Blue"), chalk.ansi256(200)("Pink"));

Step 2: Reusable styles

const styles = {
  error: chalk.red.bold,
  success: chalk.green,
  warn: chalk.yellow,
  info: chalk.blue,
  highlight: chalk.cyan.bold,
};
const prefix = { error: "✗", success: "✓", warn: "⚠", info: "ℹ" } as const;

function log(level: keyof typeof prefix, msg: string) {
  console.log(`${styles[level](prefix[level])} ${msg}`);
}

log("success", "Project created");
log("info", `Using ${styles.highlight("TypeScript")} template`);

Step 3: Output that is not stdout, and custom levels

import chalk, { Chalk, chalkStderr } from "chalk";

console.error(chalkStderr.red("Build failed"));     // color support detected for stderr, not stdout
const plain = new Chalk({ level: 0 });               // never emits color (levels 0-3)
const forced = new Chalk({ level: 3 });              // always truecolor, e.g. for tests

Step 4: Tagged templates

Chalk 5 and later removed the built-in template literal tag. Install the separate package and import its default export:

npm install chalk-template
import chalkTemplate from "chalk-template";

console.log(chalkTemplate`{red Error:} {bold ${"config.json not found"}}`);

Examples

Example 1: Test runner summary

User request: "Print a pass/fail summary in my CLI, green for passing counts and red when anything failed."

Actions:

import chalk from "chalk";

function summary(passed: number, failed: number) {
  const badge = failed === 0 ? chalk.bgGreen.black.bold(" PASS ") : chalk.bgRed.white.bold(" FAIL ");
  console.log(`${badge} ${chalk.green(`${passed} passed`)}, ${failed ? chalk.red(`${failed} failed`) : chalk.gray("0 failed")}`);
}
summary(42, 1);

Result: FAIL 42 passed, 1 failed with a red badge; with output piped to a file, no escape codes are written.

Example 2: Aligned stats table

User request: "Show git-style stats with dim labels and colored values."

Actions:

import chalk from "chalk";

function printStats(stats: Record<string, number>) {
  const width = Math.max(...Object.keys(stats).map((k) => k.length));
  for (const [key, value] of Object.entries(stats)) {
    console.log(`  ${chalk.gray(key.padEnd(width))}  ${value > 0 ? chalk.green(value) : chalk.red(value)}`);
  }
}
printStats({ "Files changed": 12, "Lines added": 847, Warnings: 0 });

Result: three aligned rows; counts above zero are green, zero is red.

Guidelines

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.