MCPcopy Index your code
hub / github.com/charlie0129/batt

github.com/charlie0129/batt @v0.7.3

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.7.3 ↗ · + Follow
364 symbols 1,044 edges 52 files 119 documented · 33% updated 1d agov0.7.3 · 2026-03-02★ 1,61231 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

[!TIP] 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 you are using macOS 26.4 or later. However, batt won't go anywhere so if you are on an older version of macOS or you want to set a charge limit lower than 80%, you can still use batt.

Note: Use table of contents of quickly navigate to the section you want, e.g., Installation. 👆↗

batt

Go ChecksBuind Test Binary

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

Why do you need this?

This article might be helpful. TL;DR: keep your battery at 80% or lower when plugged in, and discharge it as shallowly as feasible.

Previously, before optimized battery charging is 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 below).

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%. Once it reaches the predefined level, your computer will use power from the wall only, leaving no strain on your battery.

Quick link to installation guide.

Features

batt tried to keep as simple as possible. Charging limiting is the only thing to care about for most users:

  • Limit battery charge, with a lower and upper bound, like ThinkPads. Docs

However, if you are nerdy and want to dive into the details, it does have some advanced features for the computer nerds out there :)

  • 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
  • It solves common sleep-related issues when controlling charging. Docs1 Docs2
  • Calibrate battery automatically. Docs

How is it different from XXX?

It is free and opensource. It even comes with some features (like idle sleep preventions and pre-sleep stop charging) that are only available in paid counterparts. It comes with no ads, no tracking, no telemetry, no analytics, no bullshit. It is open source, so you can read the code and verify that it does what it says it does.

It is simple but well-thought. It only does charge limiting and does it well. For example, when using other free/unpaid tools, your MacBook will sometimes charge to 100% during sleep even if you set the limit to, like, 60%. batt have taken these edge cases into consideration and will behave as intended (in case you do encounter problems, please raise an issue so that we can solve it). Other features is intentionally limited to keep it simple. If you want some additional features, feel free to raise an issue, then we can discuss.

It is light-weight. No electron GUIs hogging your system resources like some other tools. You can use batt on the command-line, or use the native macOS menubar app if you prefer a GUI. The GUI is written using native macOS APIs, so it is light-weight and fast.

But macOS have similar features built-in, is it?

Yes, macOS have optimized battery charging. It will try to find out your charging and working schedule and prohibits charging above 80% for a couple of hours overnight. However, if you have an un-regular schedule, this will simply not work. Also, you lose predictability (which I value a lot) about your computer's behavior, i.e., by letting macOS decide for you, you, the one who knows your schedule the best, cannot control when to charge or when not to charge.

batt can make sure your computer does exactly what you want. You can set a maximum charge level, and it will stop charging when the battery reaches that level. Therefore, it is recommended to disable macOS's optimized charging when using batt.

Compatibility Matrix

Firmware Version GUI CLI (Prebuilt) CLI (Build from Source)
6723.x.x ⚠️
7429.x.x / 7459.x.x ⚠️
8419.x.x / 8422.x.x ⚠️ ⚠️
10151.x.x ⚠️ ⚠️
11881.x.x
13822.x.x
Other
  • ❌: Unsupported
  • ✅: Supported
  • ⚠️: Not verified, but expected to work.
  • ❓: Unknown, please raise an issue if you have tested it.

[!NOTE] Firmware version is different from macOS version. You can check your firmware version by running system_profiler SPHardwareDataType | grep -i firmware in Terminal.

If you want to know which MacBooks I personally developed it on, I am using it on all my personal MacBooks every single day, including MacBook Air M1 2020 (A2337), MacBook Air M2 2022 (A2681), MacBook Pro 14' M1 Pro 2021 (A2442), MacBook Pro 16' M1 Max 2021 (A2485).

If you encounter any incompatibility, please raise an issue with your MacBook model and macOS version.

Installation (GUI Version)

GUI version is a native macOS menubar app. It's not as feature-complete as the command-line version, but it is a good choice if you are not comfortable with the command-line. The command-line version is also included if you have the GUI version.

  1. Download .dmg file from Releases and open it (right-click open if macOS says it's damaged)
  2. Drag batt.app to Applications
  3. macOS may say it's damaged when you try to run it (it's NOT) and wants you to move it to trash. To fix it, run this in Terminal: sudo xattr -r -d com.apple.quarantine /Applications/batt.app.
  4. Run batt.app.
  5. Follow the MenuBar UI to install or upgrade.
  6. 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

SCR-20250624-lbmb-3 SCR-20250624-lbmb-2 SCR-20250624-lbmb-4

[!TIP] There are 3rd-party GUI versions built around batt by some amazing opensource developers: 1. BattGUI by @clzoc

Installation (Command-Line Version)

[!NOTE] Command-Line version is already included if you have installed the GUI version. You can run batt in Terminal to use it.

You have two choices to install the CLI version of batt:

  1. Homebrew (If you prefer a package manager) Docs
  2. Installation Script (Recommended) Docs

You can choose either one. Please do not use both at the same time to avoid conflicts.

Homebrew

  1. brew install batt
  2. sudo brew services start batt
  3. Please read Notes.

Thank you, @Jerry1144, for bootstrapping the Homebrew formula.

Installation Script

  1. (Optional) There is an installation script to help you quickly install batt (Internet connection required). Put this in your terminal: bash <(curl -fsSL https://github.com/charlie0129/batt/raw/master/hack/install.sh). You may need to provide your login password (to control charging). This will download and install the latest stable version for you. Follow the on-screen instructions, then you can skip to step 5.

Manual installation steps

  1. Get the binary. For stable and beta releases, you can find the download link in the release page. If you want development versions with the latest features and bug fixes, you can download prebuilt binaries from GitHub Actions (has a retention period of 3 months and you need to chmod +x batt after extracting the archive) or build it yourself .
  2. Put the binary somewhere safe. You don't want to move it after installation :). It is recommended to save it in your $PATH, e.g., /usr/local/bin, so you can directly call batt on the command-line. In this case, the binary location will be /usr/local/bin/batt.
  3. Install daemon using sudo batt install. If you do not want to use sudo every time after installation, add the --allow-non-root-access flag: sudo batt install --allow-non-root-access. To uninstall: please refer to How to uninstall?

  4. In case you have GateKeeper turned on, you will see something like "batt is can't be opened because it was not downloaded from the App Store" or "batt cannot be opened because the developer cannot be verified". If you don't see it, you can skip this step. To solve this, you can either 1. (recommended) Go to System Settings -> Privacy & Security --scroll-down--> Security -> Open Anyway; or 2. run sudo spctl --master-disable to disable GateKeeper entirely.

Notes

  • Test if it works by running sudo batt status. If you see your battery status, you are good to go!
  • Time to customize. By default batt will set a charge limit to 60%. For example, to set the charge limit to 80%, run sudo batt limit 80.
  • As said before, 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
  • If your current charge is above the limit, your computer will just stop charging and use power from the wall. It will stay at your current charge level, which is by design. You can use your battery until it is below the limit to see the effects.
  • You can refer to Usage for additional configurations. Don't know what a command does? Run batt help to see all available commands. To see help for a specific command, run batt help <command>.
  • To disable the charge limit, run batt disable or batt limit 100.
  • How to uninstall? How to upgrade?

Finally, if you find batt helpful, stars ⭐️ are much appreciated!

Usage

Limit battery charge

Make sure your computer doesn't charge beyond what you said.

Setting the limit to 10-99 will enable the battery charge limit, limiting the maximum charge to somewhere around your setting. However, setting the limit to 100 will disable the battery charge limit.

By default, batt will set a 60% charge limit.

To customize charge limit, see batt limit. For example,to set the limit to 80%, run batt limit 80. To disable the limit, run batt disable or batt limit 100.

Enable/disable power adapter

[!NOTE] This feature is CLI-only and is not available in the GUI version.

Cut or restore power from the wall. This has the same effect as unplugging/plugging the power adapter, even if the adapter is physically plugged in.

This is useful when you want to use your battery to lower the battery charge, but you don't want to unplug the power adapter.

NOTE: if you are using Clamshell mode (using a Mac laptop with an external monitor and the lid closed), cutting power will cause your Mac to go to sleep. This is a limitation of macOS. There are ways to prevent this, but it is not recommended for most users.

To enable/disable power adapter, see batt adapter. For example, to disable the power adapter, run sudo batt adapter disable. To enable the power adapter, run sudo batt adapter enable.

Check status

[!NOTE] This feature is CLI-only and is not available in the GUI version.

Check the current config, battery info, and charging status.

To do so, run sudo batt status.

Advanced

These advanced features are not for most users. Using the default setting for these options should work the best.

Auto Calibration (experimental)

Thanks @brookqin for implementing the initial version of this feature.

Automatically performs a full charging cycle to help calibrate reported battery percentage.

Phases: Idle → DischargeToThreshold → ChargeToFull → HoldAfterFull → DischargeAfterHold → RestoreAndFinish → Idle.

Flow: 1. Discharge below configured threshold (defaults to 15%). Charging is forced off. 2. Charge to 100%. Upper limit temporarily set to 100. 3. Hold at 100% for the configured duration (defaults to 120 minutes unless changed). 4. After hold, charging is disabled again and the battery is allowed to naturally discharge back down to the original upper limit snapshot. 5. Restore original upper/lower limits and adapter/charging states and return to Idle.

You can start, pause, resume, cancel via the GUI (Advanced → Auto Calibration) or CLI (batt calibration start|pause|resume|cancel|status) or HTTP API. Can

Extension points exported contracts — how you extend this code

TaskFunc (FuncType)
TaskFunc represents a runnable task.
pkg/daemon/scheduler.go
Config (Interface)
(no doc) [2 implementers]
pkg/config/config.go
NotifyFunc (FuncType)
(no doc)
pkg/daemon/scheduler.go

Core symbols most depended-on inside this repo

Error
called by 105
pkg/daemon/calibration.go
UpperLimit
called by 29
pkg/config/config.go
setCheckboxItem
called by 24
pkg/gui/menu.go
bold
called by 22
cmd/batt/status.go
To
called by 19
pkg/utils/ptr/ptr.go
showAlert
called by 19
pkg/gui/helpers.go
Write
called by 16
pkg/smc/smc.go
Stop
called by 13
pkg/daemon/scheduler.go

Shape

Function 163
Method 158
Struct 34
TypeAlias 6
FuncType 2
Interface 1

Languages

Go99%
C1%

Modules by API surface

pkg/config/file.go30 symbols
pkg/client/apis.go30 symbols
pkg/daemon/handlers.go28 symbols
pkg/daemon/calibration_test.go28 symbols
pkg/config/config.go24 symbols
pkg/daemon/scheduler.go19 symbols
pkg/gui/helpers.go15 symbols
pkg/daemon/calibration.go15 symbols
pkg/daemon/utils.go14 symbols
pkg/gui/menu.go11 symbols
pkg/utils/osver/darwin.go10 symbols
pkg/daemon/loop.go10 symbols

For agents

$ claude mcp add batt \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact