A Windows command-line tool that plays Clash of Clans for you inside MuMu Player 12 or LDPlayer 14. It reads the screen itself and turns what it finds into ADB taps, checking the outcome on the next screenshot. Gemini is asked exactly one question per battle: how to attack this village.
Other Languages: English | 繁體中文 | 简体中文
✨ What it does
Attacks for loot on its own. It searches for opponents, skips the ones carrying less than your thresholds, puts the whole army down in about ten seconds and plays the battle out, then comes round for the next one. It stops by itself when the storages are full. Screen reading is done here rather than sent away: the loot panel, the army bar and every card in the row are matched against templates, so a skipped opponent costs nothing and a battle is never waiting on a network call.
Asks Gemini exactly one question per battle, and only after an opponent has already passed your thresholds: how to attack this particular village. It answers where to drop the line of troops, where each rage and freeze goes, and which hero is on which card. Without an API key the app plays a fixed tactic instead and everything else still works.
Spends what it farms. Buildings, heroes, research, pets and walls are upgraded by an agent through the build panel, with tap, swipe and confirm. Wall upgrades finish the moment they are paid for, so they are where a full storage goes.
Keeps the village ticking. Empties the collectors, reads what every builder is on and how long is left, and donates troops to whoever is asking in the clan chat.
Recovers on its own. A session dropped for idling restarts the game and carries on, whichever loop was running. A server that is not answering is waited out rather than tapped at.
Village exports keep unknown fields and unknown data_ids instead of failing on them, and the sections are read off the document rather than from a written-down list.
📋 Requirements
- Windows. The app talks to
mumu-cli.exeorldconsole.exe, reads the registry throughwinregand the clipboard throughctypes.windll, none of which exist elsewhere - MuMu Player 12 or LDPlayer 14 with Clash of Clans installed, running at 1600x900. On LDPlayer, turn on ADB debugging (local connection) in its settings
- A Gemini API key, saved as
gemini.main.api_keyin the settings file below. It answers one thing and nothing else: the tactic for each battle. Without one the attack loop falls back to a fixed tactic, and no other command asks it anything in the first place
🚀 Install and run
From PyPI, without installing anything permanently:
Or as a regular install:
Prebuilt Windows executables are attached to every release.
🎮 Playing from the terminal
Everything is a sub-command; ai_coc --help lists them.
Attacking
ai_coc attack # one battle
ai_coc attack --repeat 5 # five in a row
ai_coc attack --repeat 0 # keep going until a storage fills up
ai_coc stop # stand down after the battle in progress
ai_coc giveback # end this session's hold and hand a borrowed emulator back
ai_coc attack --stop-at 0 # attack however full the storages are
ai_coc attack --repeat 0 --until-idle # stop as well once a builder or research slot here is idle
ai_coc attack --repeat 0 --until-idle builder # only the builders (`lab` for the laboratory)
stop marks ~/.ai_coc/state.json and returns at once. The loop reads it between battles and between opponents, never mid-battle, so the worst case is one more battle: abandoning one halfway would leave the army on the field and the game on a screen the next run cannot get home from. It stops the upgrade watch in the same go; ai_coc stop emulator or ai_coc stop watch stops only one. With nothing running it says so, rather than leaving a request nobody will take.
Loot thresholds come from the settings file, and can be overridden for one run. Passing 0 is different from leaving a flag out: out means "use the configured value", 0 means "take this threshold out entirely":
ai_coc attack --min-gold 800000
ai_coc attack --min-gold 0 --min-elixir 0 --min-dark 0 # attack whoever comes up first
Any command that looks at the screen can keep everything it looked at, which is what makes a battle worth arguing with afterwards:
ai_coc attack --debug # every frame the loop reads, named for what it was asking, and a DEBUG log
ai_coc attack --debug --shot-every 4 # plus one frame every four seconds
A tactic is a file rather than a set of constants, so a battle worth repeating can be repeated and one worth arguing with can be edited. Replaying one calls Gemini not at all:
ai_coc attack --plan-out used.json # write down whichever plan actually ran
ai_coc attack --plan used.json # play that one again, edits included
Spending what you farmed
ai_coc confirm --price 10800 # press the sheet's 確認 only if it asks exactly this
ai_coc confirm --price 1600000 --pay gold # pay in gold for the wall picked from the panel
ai_coc confirm --price 10800 --item "Cannon 12" # the same, recording what was bought for tended
ai_coc listprice --day # the panel shows no struck-through list price any more: status stops scaling by the old discount
Every upgrade goes through the build panel, walls included: tap and swipe press and scroll and keep the frame they left, and confirm is the one press that spends, made only when the sheet asks exactly the price given, in gold, elixir or dark elixir. With --pay it starts on the menu of a wall picked from the panel: it presses that wall's price button only when it asks the price given and the village can pay, then the sheet or the batch's dialog that button raises.
Keeping the village going
ai_coc collect # empty every collector that has something waiting
ai_coc status # when every upgrade on both villages really finishes, potions included, plus this village's storages, gems and shield, printed as one table per village with what each next level asks and takes (the list price and time scaled by what the village's purchases within the last day paid against them), a line per resource the storages fall short of if everything due within three hours continues, the potions still running, and the instructions kept with `note` for each village; --json prints the fields
ai_coc status --last # the same tables off the last saved export, without touching the game; --within 24 folds what finishes later into one line
ai_coc watch --upgrades --lead 5 --tower --minutes 180 # sleep until the earliest of those (or a --next) as the one watching the upgrades, named on state.json; run it in the background
ai_coc note add "..." --seen 3fa2 --day # keep one of the user's instructions for a village in state.json; `note` lists them with their revision, `note done 1 --seen 3fa2 --day` drops one; an edit without the current revision changes nothing
ai_coc donate # give troops to whoever in the clan is asking
ai_coc donate --dry-run # walk the whole path and stop before giving anything
Getting the game up
Every other command assumes the game is already running and brings it up if it simply is not. What it cannot fix is an emulator or a game that is up and no longer answering, which is what these are for:
ai_coc launch # start the emulator if it is down, bring the game up
ai_coc launch --restart game # relaunch the game, leave the emulator alone
ai_coc launch --restart emulator # restart the emulator, then bring the game up again
Looking at what it sees
ai_coc capture --count 30 # a burst off the live game, into this run's own folder
ai_coc <any command> --label baseline # name this run's folder so it is findable later
ai_coc <any command> --agent codex --session <id> --mission "farm" # who asked; agents always pass these, a bare run logs a warning
ai_coc read shot.png # what each reader makes of one frame
ai_coc draw shot.png # draw where each step of a plan would be tapped on a battle frame taken before the first drop, each with its number and second, and a 3x3 grid fitted to the village's red line to point with; prints the picture's path, then the army it counted on the card row, the steps and what it could not read. --plan <name or JSON> picks the plan (flat by default, --night for the builder base's), --against <plan> marks what another plan does differently, --only plan|grid draws one of the two, --camera DX DY says how far the battle camera had been dragged; --run <label> takes the frame an `attack` run kept before its newest battle's first drop, and the camera's shift, instead. Touches nothing
ai_coc decision --prompt "<yes/no question>" --image-path shot.png # ask Gemini's Decisions API one yes/no question about an image: prints yes or no and the seconds the call took; its model and key are set under `gemini.decision` in the settings file; --ground-truth yes|no records your own answer beside it; touches nothing, stands alone and is on trial, so no flow uses it
ai_coc export # the whole village out of the game, named, as JSON
ai_coc export --table # the same, drawn as a table for a person
ai_coc export --last # the last one off the disk, without touching the game
ai_coc growth # what was upgraded on each village between the oldest and newest saved exports; --start-date / --end-date narrow it
ai_coc turnaround # seconds from each upgrade finishing to the confirm for its next level, per slot, off the run journal; --since narrows it
ai_coc farmed --by <session> --since <time> # one session's farming summed over every attack run, per village, off the run journal; touches nothing
ai_coc tended --by <session> --since <time> # one session's upgrades with what each cost, clock tower boosts and lost logins, off the run journal; touches nothing
ai_coc gamedata # the game's own tables (zh and en names, max levels, each level's requirements, list price and time), read off the emulator once per game version into ~/.ai_coc/game_data/<version>/; --refresh reads them again
ai_coc search "Electro Dragon" # look a thing up by data_id or by a piece of its Chinese or English name in those tables (the nearest names, labelled as such, when no name contains it), with the levels, running upgrades and next list price of the ones the village has, what every level up to the max or the hall's cap asks in all (with an estimate at the newest purchases' discount when there is one), and what unlocks the troops and spells it lacks; --rows lists each row; touches nothing
ai_coc search --section builder --day --skip-max-lvl # list what the village holds of one section (builder, lab, pets, equipment, helpers, or all), each village in its own block, what a copy can start now first, quickest upgrade first; --day / --night keep one village, --skip-max-lvl leaves out what is at its last level, and a name narrows it further
ai_coc view --zoom out # put the camera back where every coordinate was measured
ai_coc world # which of the two villages the game is on
ai_coc world --day # sail to the home village, --night to the builder base; already being there does nothing
ai_coc attack # attack whichever village the game is on, then print what it brought home; --json prints each round
The game keeps two villages — the home village and the builder base — and reopens on whichever one it was closed on, so world is worth asking before anything that assumes one of them. Reading it is a single screenshot: no tap, no swipe, no camera move. No command sails on its own: world --day or world --night is the only one that changes villages, and one with nothing to do on the village it finds — donate on the builder base, say — says so and leaves the game where it is.
read is the quickest way to answer "did it misread the screen, or did the tap miss?" It prints what every reader got from one frame: the loot panel, the storages, the card row and the builder counter.
Where a run leaves what it saw
Every run gets a directory of its own:
~/.ai_coc/logs/2026-08-29-011423-attack/
├── run.log # this run's log, and nothing else
├── result.json # what the command answered
└── frames/ # every frame it read with --debug; without it, only the ones a command keeps
The first line of every run says which directory it is, and the name is <when>-<what> so a listing reads as a history. --label adds a third part on any command (2026-08-29-011423-attack-baseline) for a run you want to find again. ~/.ai_coc/runs.jsonl keeps one line per milestone of every run (its start and end, each attack round with the tactic it played, the emulator changing hands, every warning), outside logs/, so it survives that directory being cleared, and every report (turnaround, farmed, tended, status) reads it rather than the logs; clearing logs/ loses the frames and the full log lines, and turnaround the purchases made before 2026-11-13; grep -r ~/.ai_coc/logs/*/run.log searches the full logs across runs and tells you which one each hit came from.
Frames are kept for a week; the logs are kept forever. A run's frames/ is deleted once it is older than that, and nothing else in the directory ever is. The split is worth stating because it is lopsided: on this machine 11 456 recorded PNGs came to 27.2 GB while everything else in those directories came to 4.6 MB. Copy anything you want to keep longer out of there.
⚙️ Settings
~/.ai_coc/config.json holds the settings every command reads:
{
"thresholds": {
"min_gold": 500000,
"min_elixir": 500000,
"min_dark": 5000
},
"stop_at": 90,
"adb_serial": "127.0.0.1:16384",
"gemini": {
"main": {
"model": "gemini-4-argon",
"base_url": "",
"api_key": "",
"thinking_level": "low"
}
}
}
That is the whole file. A run that finds no file creates one only to write down adb_serial — otherwise it uses exactly these values and leaves the disk alone — so the file appears the first time a command picks an emulator. Once it exists it is kept honest on every load: a key the app no longer reads is dropped and a key the file never had is filled in, so what is on disk is always a statement of what the next run will do rather than of what was saved once.
- thresholds: who is worth attacking. Set them too high and a run skips dozens of opponents without ever starting a battle. A storage already past
stop_atstops counting, since the run already treats it as full - stop_at: how full every storage has to be before a run stands down, as a percentage. One number for both villages, because the loop reads each storage's real ceiling off the game — tap a storage bar and it writes 最大儲存量 on the spot. Every storage has to reach it, not just one of them: a battle brings home three, so one at the ceiling is no reason to stop earning the other two. On the builder base the elixir cart counts as one more: past a full elixir storage it keeps banking each battle's defence reward, so a run there stands down only once the cart has reached the same share of the ceiling written on it.
0never stands a run down, and a storage whose ceiling would not read is left out of the count.--stop-atoverrides it for one run,0included, which is what a test battle against a village that farming has just filled needs - adb_serial: which emulator instance to drive, by the serial
adb devicesshows (127.0.0.1:16384,127.0.0.1:5555, oremulator-5554, which is the same LDPlayer instance as127.0.0.1:5555). Left empty, the first run takes the instance with the game running, MuMu's where both have it, and writes its serial here. A serial no installed emulator answers to is an error rather than a guess - gemini: which model answers each kind of call.
mainis asked once per run against a whole screenshot — the attack plan on either village — so nothing there is racing anything and the better model is simply the right one.base_urlempty means Google's own endpoint. Each model carries its ownapi_key, so one pointed at a proxy can hold that proxy's key. It is kept in plain text, and while it is empty aGEMINI_API_KEYfrom the environment or a.envstands in
There are no ability or spell timings here any more. They were a table of per-hero constants, and editing them meant guessing how long an army takes to walk across a village nobody had looked at — which is the planner's job, done with the village on screen. Every clock lives on the plan now: see plans/flat.json for the shape, and --plan to replay one.
Everything else lives in ~/.ai_coc: the account JSON ai_coc export and ai_coc status write, one file a day, the run logs, and state.json — which command is driving the emulator, its pid, its log directory, and who started it (--agent, --session, --mission). It is kept after a run ends rather than removed, so the record says what the last run was instead of going blank. It is also a lock: a command that drives the emulator asks the live run holding it to stand down and waits for it to finish, and takes over at once from a run whose process is gone. A run started with --yield is background work: it never stands anything down, and when something else needs the emulator it is lent out instead of stopped, and its agent starts it again once ai_coc giveback hands the emulator back, or half an hour after the borrower's last command. A command that names a --session also holds the emulator for that session while it runs and for two minutes after, so another session's command cannot land between two of its commands: it answers held instead (or waits up to --queue seconds), and tap, swipe and confirm press only inside their own session's hold. ai_coc hold takes one and does nothing else, ai_coc giveback ends it, and ai_coc stop cancels it. The file has a second section, watch: the ai_coc watch process an agent sleeps on until an upgrade comes due, with its own pid, so whether anyone is watching is whether that process is alive. A new watch stops a live one and takes its place, and ai_coc stop ends it. The third section, notes, holds the user's standing instructions for each village, kept with ai_coc note. Every write also keeps a copy in ~/.ai_coc/backups/, the newest 20, and a file that will not read is carried on from the newest copy rather than written over.
🤝 Contributing
Setup, architecture, packaging and the CI layout live in CONTRIBUTING.md.
⚠️ Disclaimer
This project is not affiliated with, endorsed or sponsored by Supercell. Clash of Clans is a trademark of Supercell, and the game's names and artwork belong to Supercell.
Supercell's Terms of Service forbid automation software, emulators and bots, and let Supercell suspend or delete an account that uses them. Running this tool puts the account it plays at exactly that risk; use it at your own risk.
📄 License
MIT, see LICENSE.