GNU General Public License v2.0

项目介绍

charlie0129/batt 是一个托管在 GitHub 上的开源项目,主要使用 Go 编写,采用 GNU General Public License v2.0 许可证,目前获得 1.8k 个 Star、86 次 Fork。

仓库全名
charlie0129/batt
开源许可证
GNU General Public License v2.0
Star 数
1.8k
Fork 数
86
未关闭 Issue
29

README 摘要

[!NOTE] Feb 17, 2026 UPDATE: Finally, after more than 5 years, macOS 26.4 and later supports charge limiting natively (adjustable from 80% to 100%), so batt is not needed if the built-in range meets your needs. batt remains useful on older releases and when you want a limit below 80%. On macOS 27, batt can set native limits from 10% to 99% when direct SMC control is unavailable. Batt batt is a tool to control…

完整内容见 GitHub 原始 README 或本页 。

常见问题

batt 用什么语言开发?

主要使用 Go 编写,采用 GNU General Public License v2.0 许可证,目前有 1.8k 个 Star。

batt 可以免费商用吗?

仓库标注的许可证为 GNU General Public License v2.0,商用前请先阅读仓库 LICENSE 文件确认授权范围。

如何获取 batt 的源码?

可以直接克隆仓库:git clone https://github.com/charlie0129/batt.git,默认分支为 master;安装与运行步骤见仓库 README。

batt 最近还在维护吗?

仓库最近一次更新为 1 天前,当前有 29 个未关闭 Issue;Star 数为 1.8k,可作为社区活跃度的参考。

关于

GitHub 原始描述(英文)

Control and limit battery charging on Apple Silicon MacBooks.

描述取自 GitHub 官方 API,保持仓库作者书写的原文。

简要分析

热度分
1983
价值分
1104
活跃状态
活跃

语言占比

C
Go
Makefile
Objective-C
Python
Shell

Release

README

[!NOTE] Feb 17, 2026 UPDATE:
Finally, after more than 5 years, macOS 26.4 and later supports charge limiting natively (adjustable from 80% to 100%), so batt is not needed if the built-in range meets your needs. batt remains useful on older releases and when you want a limit below 80%. On macOS 27, batt can set native limits from 10% to 99% when direct SMC control is unavailable.

Batt Logo

Batt

Go Checks Build Test Binary GitHub Downloads

batt is a tool to control battery charging on Apple Silicon MacBooks.

Full docs here!

Batt Screenshot

Why do you need this?

This article might be helpful.

[!NOTE] TL;DR
keep your battery at 80% or lower when plugged in, and discharge it as shallowly as feasible.

Previously, before optimized battery charging was introduced, MacBooks are known to suffer from battery swelling when they are kept at 100% all the time, especially the 2015s. Even with optimized battery charging, the effect is not optimal (described here)

batt can effectively alleviate this problem by limiting the battery charge level. It can be used to set a maximum charge level. For example, you can set it to 80%, and it will stop charging when the battery reaches 80%.

Guides

Installation Compatibility Usage Building

Other

FAQ Comparison

Releases Homebrew GitHub

Features

batt tries to keep things as simple as possible. Charge limiting is the only thing to care about for most users:

  • Limit battery charge with an upper bound, plus a ThinkPad-style lower bound where supported (not in macOS 27 native mode). Docs
  • Charge to the limit or to 100% once, without changing the limit. Docs

However, if you are nerdy and want to dive into the details, it does have some advanced features for power users. These are shown only when the current Mac’s SMC keys support them.

  • Control MagSafe LED (if present) according to charge status. Docs
  • Cut power from the wall (even if the adapter is physically plugged in) to use battery power. Docs
  • On firmware < 20xxx, it solves common sleep-related issues when controlling charging. Docs1 Docs2
  • Calibrate battery automatically. Docs

Installation

Note 注意

This is a quick and short overview,

Full-Installation-Guide

Installing the GUI

[!TIP] It is highly recommended to disable macOS’s optimized charging when using batt.
To do so, open System Settings -> Battery -> Battery Health -> i -> Turn OFF Optimized Battery Charging.
Disable the built-in charge limit when using direct SMC control. In native mode, batt manages that setting itself.

  • Download .dmg file from Releases and open it (right-click open if macOS says it’s damaged)
  • Drag batt.app to Applications
  • macOS may say it’s damaged when you try to run it. To fix it, run this in your Terminal:
    sudo xattr -r -d com.apple.quarantine /Applications/batt.app.
  • Run batt.app and follow the MenuBar UI to install or upgrade.
Screenshot GUI Setup

Installing the CLI

Homebrew
  brew install batt
  sudo brew services start batt
Installation Script
  curl -fsSL https://github.com/charlie0129/batt/raw/master/hack/install.sh

After installation run the following command to ensure that the installation succeeded:

batt help

Compatibility

Note 注意

This is a quick and short overview,

Full-Compatibility-Guide

macOS Version GUI CLI (Prebuilt) CLI (Build from Source)
macOS 11 Big Sur ❌ ❌ ⚠️
macOS 12 Monterey ❌ ⚠️ ✅
macOS 13 Ventura ⚠️ ⚠️ ✅
macOS 14 Sonoma ⚠️ ⚠️ ✅
macOS 15 Sequoia ✅ ✅ ✅
macOS 26 Tahoe ✅ ✅ ✅
macOS 27 Golden Gate Beta 1–3 ✅ ✅ ✅
macOS 27 Golden Gate Beta 4+ ✅ ✅ ✅
Other ❓ ❓ ❓
  • ✅ Supported
  • ⚠️ Not verified, but expected to work
  • ❌ Unsupported
  • ❓ Unknown

Special Notes

  • macOS 27 Beta 1–3: Firmware-managed charge limits. Limits remain active during sleep.
  • macOS 27 Beta 4+: Native macOS charge limits from 10% to 99% by default. Upper limit only; macOS may drain the battery toward the limit while plugged in. Opt-in adapter mode adds a lower limit.

Adapter Mode

Enable with:

sudo batt adapter-mode enable
  • Supports charge limits from 10% to 100%.
  • Works only while batt is awake.
  • Disables Force Discharge and auto-calibration.
  • Supports the lower limit, which native mode does not.

For release compatibility, see the release page.

Usage

See-the-full-usage-Guide-here

Building

Note 注意

This is a quick and short overview,

Full-Building-Guide

Building the CLI

make

Building the GUI

make app

Architecture

You can think of batt like docker. It has a daemon that runs in the background, and a client (CLI or GUI) that communicates with the daemon. They communicate through unix domain socket as a way of IPC. The daemon does the actual heavy-lifting, and is responsible for controlling battery charging. The client is responsible for sending users’ requirements to the daemon.

For example, when you run sudo batt limit 80, the client will send the requirement to the daemon, and the daemon will do its job to keep the charge limit to 80%.

The daemon selects a control backend from usable SMC keys and native services. The legacy backend continuously reads battery percentage and toggles charging itself. The firmware backend writes lower/upper limits and periodically reconciles them while Apple firmware enforces the range, including during sleep. The native backend keeps PowerUIAgent’s upper target in sync; opt-in adapter mode toggles wall power. The same capability data is exposed to CLI and GUI clients so unsupported features are not offered.

Motivation

I created this tool simply because I am not satisfied with existing tools 😐.

I have written and used similar utils (to limit charging) on Intel MacBooks for years. Finally I got hands on an Apple Silicon MacBook (yes, 2 years after it was introduced 😅 and I just got my first one). The old BCLM way to limit charging doesn’t work anymore. I was looking for a tool to limit charging on M1 MacBooks.

I have tried some alternatives, both closed source and open source, but I kept none of them. Some paid alternatives’ licensing options are just too limited 🤔, a bit bloated, require periodic Internet connection (hmm?) and are closed source. It doesn’t seem a good option for me. Some open source alternatives just don’t handle edge cases well and I encountered issues regularly especially when sleeping (as of Apr 2023).

I want a simple tool that does just one thing, and does it well – limiting charging, just like the Unix philosophy. It seems I don’t have any options but to develop it myself. So I spent a weekend developing an MVP, so here we are! batt is here!

Acknowledgements

Contributors

Batt contributors

Star History

Star History Chart

评论

暂无评论