cpp-reinforcement-learning

cpp-reinforcement-learning is a skill for Claude Code from Aznatkoiny/zAI-Skills. It costs 131 tokens per session (1,309 once invoked), scanned A, original, MIT.

Guidance for implementing reinforcement learning in C++ with LibTorch, PyTorch's C++ interface, and modern C++ standards.

In plain words
What is it for?
Use it to build algorithms such as DQN, PPO, or SAC for robotics, games, simulations, and other performance-sensitive applications.
Why use it?
It helps structure high-performance training systems while handling tensors, replay buffers, parallel environment runs, and model deployment.

Skill for Claude Code

Written for Claude Code: shipped in a Claude Code plugin.

Part of the ai-toolkit plugin — 6 skills, 4 commands, 2 agents shipped together

Good fit Use it to build algorithms such as DQN, PPO, or SAC for robotics, games, simulations, and other performance-sensitive applications.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/aznatkoiny/zai-skills/cpp-reinforcement-learning
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add Aznatkoiny/zAI-Skills --skill cpp-reinforcement-learning
Clone the repo
git clone --depth 1 https://github.com/Aznatkoiny/zAI-Skills

Made for: Claude Code.

Or install ai-toolkit, the plugin that ships this one along with the rest of its 6 skills, 4 commands, 2 agents.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for cpp-reinforcement-learning

README.md
[![agentmods](https://agentmods.dev/badge/skills/aznatkoiny/zai-skills/cpp-reinforcement-learning/github.svg)](https://agentmods.dev/skills/aznatkoiny/zai-skills/cpp-reinforcement-learning)
Your own site
<a href="https://agentmods.dev/skills/aznatkoiny/zai-skills/cpp-reinforcement-learning"><img src="https://agentmods.dev/badge/skills/aznatkoiny/zai-skills/cpp-reinforcement-learning/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for cpp-reinforcement-learning

Your own site · 80×15
<a href="https://agentmods.dev/skills/aznatkoiny/zai-skills/cpp-reinforcement-learning"><img src="https://agentmods.dev/badge/skills/aznatkoiny/zai-skills/cpp-reinforcement-learning.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 131 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,309 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00131 $0.01309
Opus 5.5 $0.00052 $0.00524
Sonnet 5.5 $0.00026 $0.00262
Haiku 4.5 $0.00013 $0.00131

Measured 25d ago against content hash 0eea3a9fdbbd, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

cpp-reinforcement-learning scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 25d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

AI-Toolkit/skills/cpp-reinforcement-learning/SKILL.md · 144 lines

How it starts

The opening of the file, as written. The whole thing — 144 lines — stays where its author put it; the contents beside it link to each section on GitHub.

C++ reinforcement learning

Help the user build RL in C++ that is correct first and fast second. The C++ frontend mirrors PyTorch's Python API closely, so a good approach is often to get the algorithm right against a Python reference (Stable-Baselines3 or CleanRL) and then translate it, checking the outputs match.

LibTorch changes between releases, and current versions require C++20. Check the version the user builds against (it's in <libtorch>/build-version) before relying on an API, and if a docs or web tool is available, look up anything you're unsure of.

Core Libraries

Primary: LibTorch (PyTorch C++ Frontend)

LibTorch provides the same tensor operations and autograd capabilities as PyTorch in C++.

Installation: Download from https://pytorch.org/get-started/locally (select C++/LibTorch)

CMake Integration:

cmake_minimum_required(VERSION 3.18)
project(rl_project)

set(CMAKE_CXX_STANDARD 20)   # current libtorch requires C++20
find_package(Torch REQUIRED)

add_executable(train_agent src/main.cpp)
target_link_libraries(train_agent "${TORCH_LIBRARIES}")

Other pieces

  • ONNX Runtime: cross-platform inference for policies exported from Python
  • AOTInductor (.pt2 packages): the current way to run a Python-exported PyTorch model from C++; TorchScript is deprecated (see references/libtorch.md)
  • Environments: there's no standard C++ Gymnasium; most projects wrap their own simulator behind a small reset()/step() interface

Quick Start: DQN Agent

#include <torch/torch.h>

struct DQNNet : torch::nn::Module {
    torch::nn::Linear fc1{nullptr}, fc2{nullptr}, fc3{nullptr};

    DQNNet(int64_t state_dim, int64_t action_dim) {
        fc1 = register_module("fc1", torch::nn::Linear(state_dim, 128));
        fc2 = register_module("fc2", torch::nn::Linear(128, 128));
        fc3 = register_module("fc3", torch::nn::Linear(128, action_dim));
    }

    torch::Tensor forward(torch::Tensor x) {
        x = torch::relu(fc1->forward(x));
        x = torch::relu(fc2->forward(x));
        return fc3->forward(x);
    }
};

// Training loop
auto policy_net = std::make_shared<DQNNet>(state_dim, action_dim);
auto target_net = std::make_shared<DQNNet>(state_dim, action_dim);
torch::optim::Adam optimizer(policy_net->parameters(), lr);

// Compute loss
auto q_values = policy_net->forward(states).gather(1, actions);
// Tensor::max(dim) returns std::tuple<values, indices> in C++
auto next_q = std::get<0>(target_net->forward(next_states).max(1)).detach();
auto target = rewards + gamma * next_q * (1 - dones);
auto loss = torch::mse_loss(q_values.squeeze(), target);

// Backward pass
optimizer.zero_grad();
loss.backward();
optimizer.step();

Read the full file on GitHub · 144 lines

Files

What ships with it

5 files beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 25d ago Changed · -16 lines · +48 tokens per session 0eea3a9fdbbd
  2. 3mo ago First seen · 160 lines · 83 tokens per session scan A 579fbd7b22ea

Subscribe to this mod's changes

cpp-reinforcement-learning is a skill published in the GitHub repository Aznatkoiny/zAI-Skills (10 stars, last pushed 26d ago), licensed MIT. It adds 131 tokens to every session and 1,309 once invoked, about $0.0005 per session on Opus 5.5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.

Related

cpp-reinforcement-learning compared with skills from other repositories

cpp-reinforcement-learning next to 6 skills from other repositories
ModTypeStarsLast pushLicenceScanTokensWorks with
cpp-reinforcement-learningAznatkoiny/zAI-SkillsSkill1026d agoMITA131Claude Code
r-ops0xDarkMatter/claude-modsSkill869d agoMITA83Claude Code
agent-cpp-experttravisjneuman/.claudeSkill1162d agoMITA88Claude Code
ia-c-systemsiliaal/whetstoneSkill37yesterdayMITA84Claude Code
clean-code-cppCassetteTapeCrackle/claude-startersSkill11mo agoMITA42Claude Code
clean-code-audioCassetteTapeCrackle/claude-startersSkill11mo agoMITA52Claude Code
clean-code-cCassetteTapeCrackle/claude-startersSkill11mo agoMITA34Claude Code