How Fastfetch Detects Hardware Temperatures: Inside the Cross-Platform Implementation

Fastfetch detects hardware temperatures by querying platform-specific sensor interfaces—Linux sysfs hwmon/thermal zones, Windows WMI and NVML, or macOS SMC APIs—and formats the resulting Celsius values using the centralized ffTempsAppendNum() function.

Fastfetch, the high-performance system information tool from fastfetch-cli/fastfetch, gathers thermal data from CPUs, GPUs, storage devices, and batteries through a modular, multi-layered detection architecture. The implementation reads raw sensor values from operating system interfaces, stores them in component-specific result structures, and renders them through a unified formatting pipeline defined in the source code.

Overview of the Temperature Detection Pipeline

The detection process follows a strict five-stage pipeline that isolates platform-specific logic from presentation code:

  1. Option parsing – The global --temp flag or temp=true configuration option enables temperature collection, while the optional tempSensor field (e.g., hwmon0) allows users to specify a specific sensor. These settings are defined in src/options/display.c within the FFOptions structure.
  2. Component-specific detection – Each hardware module implements a detect…Temp routine that executes only when temperature detection is enabled. These functions return a double representing degrees Celsius or FF_*_TEMP_UNSET when sensors are unavailable.
  3. Result aggregation – Detected values are written into component result structures such as FFCPUResult.temperature, FFGPUResult.temperature, and FFPhysicalDiskResult.temperature.
  4. Formatting – The ffTempsAppendNum() function in src/options/display.c converts raw doubles into formatted strings using user-configured precision, units (C/F/K), and color rules.
  5. Presentation – Each module appends the formatted temperature to its output buffer for display in text or JSON formats.

CPU Temperature Detection

The CPU temperature detection logic resides in platform-specific files under src/detection/cpu/. On Linux, the detectCPUTemp() function in src/detection/cpu/cpu_linux.c implements a four-tier fallback system:

// src/detection/cpu/cpu_linux.c (excerpt)
static double detectCPUTemp(const FFCPUOptions* options) {
    FF_STRBUF_AUTO_DESTROY buffer = ffStrbufCreate();

    // 1. User-specified sensor (e.g., "hwmon0")
    if (options->tempSensor.length > 0) {
        return readTempFile(subfd, fileName, &buffer);
    }

    // 2. Scan /sys/class/hwmon/* for CPU-related sensors
    // Checks "name" file for "cpu", "coretemp", etc., reads "temp1_input"

    // 3. Scan /sys/class/thermal/* for thermal zones
    // Filters names starting with "cpu" or "soc"

    // 4. Fallback: /sys/devices/platform/* (cputemp.*)
    return FF_CPU_TEMP_UNSET;
}

Key implementation details:

  • Sensor values are read as millidegrees Celsius from files like temp1_input and divided by 1000 to produce the final double value.
  • The readTempFile() helper (lines 17–27 of cpu_linux.c) handles the integer-to-double conversion.
  • On Windows, src/detection/cpu/cpu_windows.c queries WMI thermal zones, while macOS uses the SMC API in src/detection/cpu/cpu_apple.c.
  • The final value populates FFCPUResult.temperature, which src/modules/cpu/cpu.c formats at line 78 using ffTempsAppendNum().

GPU Temperature Detection

Fastfetch supports GPU temperature detection across multiple operating systems and driver stacks, with each platform implementing a distinct backend:

Linux (sysfs DRM)src/detection/gpu/gpu_linux.c scans /sys/class/drm/card*/device/hwmon/hwmon*/temp*_input, reading the first available temperature file and converting from millidegrees to Celsius.

Windows (WMI/NVML)src/detection/gpu/gpu_windows.c utilizes Windows Performance Counters (PDH) for AMD/Intel GPUs or the NVIDIA Management Library (nvmlDeviceGetTemperature) for NVIDIA hardware.

macOS (SMC)src/detection/gpu/gpu_apple.c calls the System Management Controller API using keys such as "TC0P" to retrieve GPU temperature data.

Vulkan APIsrc/detection/vulkan/vulkan.c queries VkPhysicalDeviceTemperaturePropertiesKHR when available for Vulkan-compatible GPUs.

The detected value is stored in FFGPUResult.temperature and later formatted by src/modules/gpu/gpu.c.

Physical Disk and Battery Temperature Detection

Fastfetch extends temperature monitoring to NVMe drives and laptop batteries through dedicated detection modules.

Physical Disk (NVMe/SSD):

Battery:

Formatting Temperature Output

All temperature values pass through the centralized formatting utility ffTempsAppendNum() defined in src/options/display.c:

// src/options/display.c (excerpt)
void ffTempsAppendNum(double temp, FFstrbuf* buf,
                      const FFTempConfig* cfg,
                      const FFModuleArgs* args) {
    // cfg contains ndigits, unit (C/F/K), colour rules
    // Rounds value, appends unit suffix, applies ANSI colors
}

The FFTempConfig structure controls:

  • Precision: Configurable decimal digits via display.temperature.ndigits
  • Units: Celsius, Fahrenheit, or Kelvin via display.temperature.unit
  • Colorization: Threshold-based coloring rules

These configuration options are documented in doc/json_schema.json around line 1884.

Enabling and Configuring Temperature Output

To display hardware temperatures, enable the global temperature flag or configure specific modules:


# Enable all available temperature sensors

fastfetch --temp

# Specify a particular CPU sensor on Linux

fastfetch --temp --temp-sensor hwmon1

# Show only GPU temperature

fastfetch --module gpu --temp

Configuration file example (~/.config/fastfetch/config.conf):

[display]
temp = true
tempSensor = "hwmon0"
temp.unit = "C"
temp.ndigits = 1

Summary

  • Modular detection: Each hardware type (CPU, GPU, disk, battery) implements platform-specific detection in src/detection/*/, trying multiple sensor sources before returning FF_*_TEMP_UNSET.
  • Unified formatting: The ffTempsAppendNum() function in src/options/display.c handles all temperature formatting, supporting configurable units, precision, and colors.
  • Linux sysfs priority: On Linux, the CPU detection prefers hwmon interfaces, falling back to thermal zones and platform-specific entries.
  • Cross-platform APIs: Windows uses WMI and NVML, macOS relies on SMC keys, and Vulkan provides GPU temperatures when available.
  • User configuration: The temp and tempSensor options in src/options/display.c allow selective enablement and sensor targeting without modifying detection logic.

Frequently Asked Questions

Which sensor files does Fastfetch read on Linux?

Fastfetch reads hardware monitor files from /sys/class/hwmon/*/temp*_input (millidegrees), thermal zone files from /sys/class/thermal/*/temp, and platform-specific entries like /sys/devices/platform/cputemp.*/temp. For GPUs, it scans /sys/class/drm/card*/device/hwmon/hwmon*/temp*_input. NVMe drives expose temperature directly through /sys/class/nvme/nvme*/temperature.

Can I display temperatures in Fahrenheit or Kelvin?

Yes. Set display.temperature.unit to "F" for Fahrenheit or "K" for Kelvin in your configuration file, or use the JSON schema options defined in doc/json_schema.json. The ffTempsAppendNum() function automatically handles unit conversion and suffix appending.

Why does Fastfetch show no temperature for my hardware?

Fastfetch returns FF_*_TEMP_UNSET (rendered as "Not Set") when detection fails. This occurs if the kernel exposes no thermal zones (common in VMs), the driver lacks hwmon support, or the user lacks read permissions for /sys/class/hwmon/. On Windows, unsupported proprietary drivers may prevent WMI or NVML access.

Does Fastfetch require external tools like lm-sensors?

No. Fastfetch reads kernel sysfs interfaces directly without depending on userspace tools like sensors or nvidia-smi. The detection code in src/detection/*/*.c opens and parses thermal files using standard C library functions, making temperature detection self-contained and performant.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →