$120 tested Claude codes · real before/after data · Full tier $15 one-timebuy --sheet=15 →
$Free 40-page Claude guide — setup, 120 prompt codes, MCP servers, AI agents. download --free →
clskills.sh — terminal v2.4 — 2,347 skills indexed● online
[CL]Skills_
CLI Toolsbeginner

CLI Color Output

Share

Add colored and formatted CLI output

Works with OpenClaude

You are a Node.js CLI developer. The user wants to add colored and formatted text output to command-line applications using industry-standard libraries.

What to check first

  • Run npm list chalk to verify the chalk library is installed (or npm install chalk)
  • Confirm your Node.js version supports ES modules or CommonJS (Node 12+)

Steps

  1. Import chalk at the top of your CLI file using const chalk = require('chalk'); for CommonJS or import chalk from 'chalk'; for ES modules
  2. Use chalk.red(), chalk.blue(), chalk.green() to apply foreground colors to strings
  3. Chain .bold, .italic, .underline for text styling before the color method or after it
  4. Use chalk.bgRed(), chalk.bgBlue() for background colors with 3-digit hex support like chalk.bgHex('#FF0000')
  5. Combine multiple styles with method chaining: chalk.bold.red.bgWhite()
  6. Use template literals to interpolate colored output: console.log(`Status: ${chalk.green('✓ Ready')}`)
  7. Apply colors conditionally based on environment: check process.env.NO_COLOR to disable colors when needed
  8. Test output with node yourfile.js and verify colors display correctly in your terminal

Code

const chalk = require('chalk');

// Basic color output
console.log(chalk.blue('This is blue text'));
console.log(chalk.green.bold('Success message'));
console.log(chalk.red.underline('Error message'));

// Background colors
console.log(chalk.bgYellow.black('Warning!'));
console.log(chalk.bgGreen.white('All clear'));

// Hex and RGB colors
console.log(chalk.hex('#FF6B6B')('Custom red'));
console.log(chalk.rgb(100, 200, 255)('Custom blue'));

// Combining styles
console.log(chalk.bold.italic.cyan('Important info'));

// Template literals with colors
const status = 'complete';
const result = `Task: ${chalk.green('✓')} ${chalk.bold(status)}`;
console.log(result);

// Conditional coloring
function log(message, type = 'info') {
  const styles = {
    success: chalk.green,
    error: chalk.red,
    warning: chalk.yellow,
    info: chalk.blue,
  };
  const colorFunc = styles[type] || chalk.white;
  console.log(colorFunc(message));
}

log('Operation successful', 'success');
log('Something went wrong', 'error');
log('Be careful', 'warning');

// Respecting NO_COLOR environment variable
const output = process.env.NO_COLOR ? chalk.stripColor : chalk;
console.log(output.green('This respects NO_COLOR flag'));

// Multi-

Note: this example was truncated in the source. See the GitHub repo for the latest full version.

Common Pitfalls

  • Treating this skill as a one-shot solution — most workflows need iteration and verification
  • Skipping the verification steps — you don't know it worked until you measure
  • Applying this skill without understanding the underlying problem — read the related docs first

When NOT to Use This Skill

  • When a simpler manual approach would take less than 10 minutes
  • On critical production systems without testing in staging first
  • When you don't have permission or authorization to make these changes

How to Verify It Worked

  • Run the verification steps documented above
  • Compare the output against your expected baseline
  • Check logs for any warnings or errors — silent failures are the worst kind

Production Considerations

  • Test in staging before deploying to production
  • Have a rollback plan — every change should be reversible
  • Monitor the affected systems for at least 24 hours after the change

Quick Info

CategoryCLI Tools
Difficultybeginner
Version1.0.0
AuthorClaude Skills Hub
clicolorsformatting

Install command:

curl -o ~/.claude/skills/cli-color-output.md https://claude-skills-hub.vercel.app/skills/cli/cli-color-output.md

Related CLI Tools Skills

Other Claude Code skills in the same category — free to download.

Want a CLI Tools skill personalized to YOUR project?

This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.