Skip to content

guoy0701/claude-code-game-CodeDungeon

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CodeDungeon 代码地牢

A Roguelike Dungeon Game Inside Claude Code | Claude Code 内置的 Roguelike 地牢游戏

English | 中文


English

Code = Explore. A roguelike dungeon game that runs inside Claude Code. Every tool call pushes you deeper into the dungeon. Fight monsters, find treasure, dodge traps — all while you code.

Why?

  • Zero extra cost — The game engine is a local Node.js script. No API calls, no extra tokens.
  • Zero interruption — Turn it off anytime with !g off, back on with !g on.
  • Roguelike — Permadeath is real. You die, you start over. But legacy points make your next run stronger.

Preview

While you code, the terminal status line shows your adventure:

🏰 B3·Ancient Tomb | ❤️85 ⚔️12 🛡5 | 🪙32 🎒3/6 | Lv.5 | Dark corridor

When you encounter a monster:

⚔️ B3 | ❤️85 ⚡15 | Infinite Loop Snake(♥25) | fight·flee·spell·item

While Claude is thinking, the spinner shows dungeon atmosphere:

⏳ Torch crackling...
⏳ Something moving in the distance...
⏳ Gripping the sword hilt...

Requirements

Installation

# 1. Clone the project
git clone https://github.com/guoy0701/claude-code-game-CodeDungeon.git
cd claude-code-game-CodeDungeon

# 2. Install into Claude Code (auto-configures hooks, statusLine, spinner)
node install.js

# 3. Set up shortcut command (optional but highly recommended)
# Linux/macOS:
cp g ~/bin/g && chmod +x ~/bin/g
# Windows (Git Bash):
cp g /c/Users/$USERNAME/bin/g
# Make sure ~/bin is in your PATH

# 4. Restart Claude Code and start coding!

The install script will:

  • Back up your current settings.json
  • Add a PostToolUse hook that triggers the game engine on every tool call
  • Set StatusLine to show the game HUD at the bottom of your terminal
  • Replace spinner verbs with dungeon-themed text

How It Works

You don't need to do anything special. Just code normally:

What you're doing What happens in the dungeon
Claude edits a file (Edit/Write) You move forward, enter the next room
Claude runs a command (Bash) You move forward
Claude searches code (Read/Grep/Glob) Scout (no movement, no events)
Claude is thinking Spinner shows dungeon atmosphere
Not coding? Use !g walk to advance manually

When you encounter something (monster, chest, shop...), use !g commands:

Commands

Combat:

!g fight          Attack
!g flee           Run away (success rate = your SPD / total SPD)
!g spell <name>   Cast a skill (costs MP)
!g item <name>    Use an item from your bag

Combat is turn-based: you act → monster acts → wait for your next command. You can keep coding between turns.

If you ignore a monster, it leaves after 5 tool calls (no damage, but no rewards either).

Exploration:

!g walk           Move forward one step (for playing without coding)
!g open           Open a chest
!g buy <number>   Buy from shop (e.g., !g buy 1)
!g leave          Leave shop
!g descend        Go down to the next floor

Info:

!g status         Full character sheet
!g map            Current floor map
!g bag            View inventory

System:

!g on             Enable game (restores dungeon StatusLine & Spinner)
!g off            Disable game (restores original StatusLine & Spinner)
!g restart        Start over after death (optional class: !g restart mage)
!g legacy         View legacy points and upgrades
!g upgrade <stat> Spend legacy points (see !g legacy for options)
!g grow atk/def/mag  Choose stat growth on level up
!g session        Reset session lock (for multi-window setups)

Game Content

Dungeon Structure — 10-15 random rooms per floor, boss every 5 floors:

Floors Area Boss
B1-B5 Sunken Mine Centipede King
B6-B10 Ancient Tomb Necromancer
B11-B15 Frozen Corridor Ice Colossus
B16-B20 Flame Abyss Production Guardian
B21+ Void Rift Infinite challenge

Room Types: Empty corridor (35%) | Monster (25%) | Chest (10%) | Trap (8%) | Shop (7%) | Campfire (5%) | Mystery Event (10%)

Monsters — Programming-themed with unique mechanics:

Monster Special Ability
Syntax Roach None (tutorial)
Null Pointer Ghost 30% chance to dodge physical attacks
Infinite Loop Snake Regenerates 5 HP per turn
Memory Leak Slime MaxHP grows every turn
Wild Bug May clone itself
Segfault Knight 20% crit for double damage
Recursion Wizard ATK increases as HP drops

4 Classes — Warrior (default), Mage, Rogue, Paladin (unlock with legacy points)

7 Skills — Unlock by level (Lv.3-20), from Heavy Strike to Execute

Permadeath & Legacy — Die and lose everything, but earn legacy points to permanently upgrade future characters.

Uninstall

node install.js uninstall
rm ~/bin/g  # remove shortcut

FAQ

Can I see the game while coding? Yes. StatusLine and Spinner are fixed at the bottom of the terminal. They never get pushed up by code output.

Does !g cost tokens? No. The ! prefix runs commands locally. The game engine is pure Node.js. Zero API calls.

Can I play without coding? Yes. Use !g walk to advance manually.

What if I ignore a monster? It leaves after 5 tool calls. No damage, but no XP or gold either.

Multiple Claude Code windows? The first window locks the game. Use !g session to let another window take over.


中文

写代码就是闯地牢。 一个运行在 Claude Code 内部的 Roguelike 地牢冒险游戏。每次工具调用都推进你在地牢中前进一步。遭遇怪物、发现宝箱、踩到陷阱——终端底部一行 HUD 实时显示一切。

为什么做这个?

  • 零额外费用 — 游戏引擎是纯本地 Node.js 脚本,不消耗 token,不调用 API。
  • 不影响工作 — 随时 !g off 一键关闭,!g on 恢复。
  • Roguelike — 角色会真的死,死了从头来,但保留传承点让你越来越强。

效果预览

正常编码时,终端底部始终显示:

🏰 B3·古墓遗迹 | ❤️85 ⚔️12 🛡5 | 🪙32 🎒3/6 | Lv.5 | 幽暗走廊

遭遇怪物时变为:

⚔️ B3 | ❤️85 ⚡15 | 死循环蛇(♥25) | fight·flee·spell·item

Claude 思考时 spinner 显示:

⏳ 火把噼啪作响中...
⏳ 远处有东西在移动中...
⏳ 握紧了剑柄中...

前置条件

安装

# 1. 克隆项目
git clone https://github.com/guoy0701/claude-code-game-CodeDungeon.git
cd claude-code-game-CodeDungeon

# 2. 安装到 Claude Code(自动配置 hooks、statusLine、spinner)
node install.js

# 3. 设置快捷命令(可选但强烈推荐)
# Linux/macOS:
cp g ~/bin/g && chmod +x ~/bin/g
# Windows (Git Bash):
cp g /c/Users/$USERNAME/bin/g
# 确保 ~/bin 在你的 PATH 中

# 4. 重启 Claude Code,开始冒险!

安装脚本会:

  • 备份你当前的 settings.json
  • 添加 PostToolUse hook,每次工具调用触发游戏引擎
  • 设置 StatusLine,终端底部显示游戏 HUD
  • 替换 Spinner 为地牢氛围文字

多窗口注意:同时开多个 Claude Code 窗口时,第一个窗口会自动锁定游戏控制权。用 !g session 重置锁,让另一个窗口接管。

核心机制

你不需要做任何额外操作。正常写代码就是在玩游戏

你在做的事 地牢里发生的事
Claude 编辑文件(Edit/Write) 你前进一步,进入下一个房间
Claude 运行命令(Bash) 你前进一步
Claude 搜索代码(Read/Grep/Glob) 侦查(不前进,不触发事件)
Claude 在思考 Spinner 显示地牢氛围文字
你不写代码时 !g walk 手动前进

遇到需要决策的事件(怪物、宝箱、商店等),用 !g 命令操作:

命令一览

战斗:

!g fight          普通攻击
!g flee           逃跑(成功率 = 你的速度/总速度)
!g spell 重击      释放技能(消耗 MP)
!g item 红药水     使用背包道具

战斗是回合制:你出一招 → 怪物出一招 → 等你下一个命令。中间可以继续写代码,怪物不会主动打你。

如果你不理会怪物,继续写代码触发 5 次工具调用后怪物自行离开(不造成伤害,但你也拿不到奖励)。

探索:

!g walk           手动前进一步(不写代码时专门玩游戏用)
!g open           打开宝箱
!g buy 1          购买商店第1件商品
!g leave          离开商店
!g descend        走完一层后下楼梯

查看:

!g status         完整角色面板
!g map            当前层地图
!g bag            查看背包

事件选择:

!g look / !g ignore      古老的镜子
!g help / !g ignore      受伤的冒险者
!g enter / !g pass       传送法阵
!g deal / !g refuse      神秘商人
!g gamble / !g leave     赌博骷髅
!g answer / !g leave     幽灵程序员
!g read / !g ignore      墙上的诗句

系统:

!g on             开启游戏(恢复地牢 StatusLine 和 Spinner)
!g off            关闭游戏(恢复原始 StatusLine 和 Spinner)
!g restart        死亡后重新开始(可选职业:!g restart mage)
!g legacy         查看传承点和可购买强化
!g upgrade hp     花传承点升级(详见 !g legacy)
!g grow atk       升级时选择成长方向(atk/def/mag)
!g session        重置会话锁(多窗口时切换控制权)

游戏内容

地牢结构 — 每层 10-15 个随机房间,每 5 层一个主题区域和 Boss:

楼层 区域 Boss
B1-B5 沉沦矿洞 矿洞蜈蚣王
B6-B10 古墓遗迹 亡灵法师
B11-B15 冰封回廊 寒冰巨像
B16-B20 火焰深渊 生产环境守护者
B21+ 虚空裂隙 无限深度挑战

房间类型: 空走廊(35%) | 怪物(25%) | 宝箱(10%) | 陷阱(8%) | 商店(7%) | 篝火(5%) | 神秘事件(10%)

怪物 — 编程主题,各有独特机制:

怪物 特殊能力
语法蟑螂 无,练手用
空指针幽灵 物理攻击30%概率 miss
死循环蛇 每回合回血5
内存泄漏史莱姆 越打越肉(每回合MaxHP+10)
野生Bug 可能复制自身
段错误骑士 20%暴击双倍伤害
递归巫师 残血时攻击暴涨

4 个职业 — 战士(默认)、法师、盗贼、圣骑士(传承点解锁)

7 个技能 — 按等级解锁(Lv.3-20),从重击到终结技

死亡与传承 — 死了角色全没,但获得传承点永久强化下一个角色。这就是 Roguelike 的核心循环。

卸载

node install.js uninstall
rm ~/bin/g  # 删除快捷命令

常见问题

写代码时看得到游戏吗? 看得到。StatusLine 和 Spinner 固定在终端底部,不会被代码输出推上去。

!g 命令会消耗 token 吗? 不会。! 前缀命令在本地 shell 执行,游戏引擎是纯 Node.js 脚本,零 API 调用。

不写代码时能玩吗? 可以,用 !g walk 手动前进。

我不理怪物会怎样? 继续写代码,5 次工具调用后怪物自动离开。不造成伤害,但你也拿不到经验和金币。

多窗口冲突? 第一个窗口自动锁定。用 !g session 重置锁,让另一个窗口接管。


Architecture

CodeDungeon/
├── engine.js          # Core engine (~1400 lines)
├── hud.js             # StatusLine HUD renderer
├── install.js         # Install/uninstall script
├── g                  # Shortcut bash script for !g commands
├── data/
│   ├── monsters.json  # 10 normal monsters + 4 bosses
│   ├── items.json     # Consumables & equipment
│   ├── skills.json    # 7 skills
│   ├── floors.json    # 5 dungeon themes
│   ├── events.json    # 7 mystery events
│   └── spinner.json   # Dungeon spinner verbs (explore/combat/boss)
├── state.json         # Game save (auto-generated, gitignored)
└── legacy.json        # Legacy data (auto-generated, gitignored)

How it hooks into Claude Code:

  • Hooks (PostToolUse) — Every tool call triggers engine.js tick via stdin JSON (tool_name + session_id)
  • StatusLine — Runs hud.js to render a one-line HUD fixed at the terminal bottom
  • Spinner — Replaced with dungeon-themed verbs, auto-switches on !g on/off

100% local execution. Zero dependencies. Zero extra token cost.

License

MIT

About

A Roguelike dungeon game embedded in Claude Code. Code = Explore. 在 Claude Code 中内置的 Roguelike 地牢游戏,写代码就是闯地牢。

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors