These are 28 coding prompts worth saving for Kimi K2.7, the coding-focused agentic model Moonshot AI shipped in June 2026. It's a 1-trillion-parameter mixture-of-experts model with roughly 32B active parameters, a 256K-token context window, and multimodal input — and it's strong at agentic coding and long-horizon tasks. The assistant is free at kimi.com, the weights are open, and every prompt below is written out in full. Swap anything in [BRACKETS] for your own details.
Two habits make Kimi far more useful for code. First, paste real code — the 256K context handles whole files or a repo section — and state the language, version, framework, and the exact error. Second, match the mode to the job: flip on Thinking mode for hard bugs and edge cases, and use Agent Mode (branded "OK Computer") when you want Kimi to build and edit whole projects on its own. For the full overview see the best Kimi prompts roundup, and for autonomous work the Kimi prompts for agents.
Write new code
Give Kimi a clear Role + Task + Context + Constraints + Output format and it writes clean, idiomatic code. State the language and version, name the framework, and say what "done" looks like so it doesn't guess.
1. Build a function from a spec
Write a [LANGUAGE version] function that [WHAT IT SHOULD DO]. Inputs: [DESCRIBE INPUTS AND TYPES]. Output: [DESCRIBE RETURN]. Constraints: [PERFORMANCE / MEMORY / STYLE]. Handle invalid input explicitly. Return the function with a short docstring, then list any assumptions you made and any edge cases the caller still needs to handle.Why it works: Naming inputs, output, and constraints up front stops Kimi from inventing a signature that doesn't fit your codebase.
2. Scaffold a small app or module
Scaffold a [WHAT] in [LANGUAGE / FRAMEWORK version]. It should [CORE FEATURES]. Give me the file structure first as a tree, then the contents of each file, using idiomatic patterns for this framework. Keep dependencies minimal and note which ones I need to install. End with the exact commands to run it locally.Why it works: Asking for the tree first, then files, gives you a working skeleton in one message instead of a pile of loose snippets.
3. API endpoint with validation
Write a [METHOD] endpoint at [ROUTE] in [FRAMEWORK version] that [WHAT IT DOES]. Validate the request body against these rules: [RULES]. Return proper status codes for success, validation errors, and server errors, and never leak internal errors to the client. Include the route handler, the validation schema, and a sample request and response.Why it works: Spelling out status codes and the "no leaked errors" rule gives you a production-shaped endpoint, not a happy-path stub.
4. CLI script from a description
Write a command-line script in [LANGUAGE version] that [WHAT IT SHOULD DO]. It takes these arguments/flags: [DESCRIBE THEM]. Handle missing or bad arguments with a clear usage message, print progress for long operations, and exit with meaningful codes. Add a --help output and a one-line comment above each main step.Why it works: Spelling out flags, usage errors, and exit codes turns a snippet into a script that behaves like a real CLI tool.
5. Convert code between languages
Convert this [SOURCE LANGUAGE] code to [TARGET LANGUAGE version], keeping the behavior identical: [PASTE CODE]. Use idiomatic patterns and standard libraries for the target language rather than a literal line-by-line translation. Point out anything that doesn't map cleanly, and note any behavior differences I should test after the port.Why it works: Asking for idiomatic target-language patterns and flagged mismatches avoids a fragile literal translation that "works" but reads wrong.
Debug
This is where Kimi earns the Thinking mode toggle. For anything subtle — a bug you can't reproduce, a race condition, a stack trace you don't understand — turn it on and let Kimi reason before the fix. Always paste the real code and the exact error.
6. Debug a specific error with Thinking mode
Turn on Thinking mode. I'm getting this error in [LANGUAGE / FRAMEWORK version]: [PASTE ERROR]. Here's the relevant code: [PASTE CODE]. Walk through the likely root cause step by step, give me the corrected code, and explain in two sentences what was actually wrong. If more than one cause is possible, rank them by likelihood. Then verify the fix against the error and list any edge cases you didn't handle.Why it works: Thinking mode spends real reasoning on the root cause, and "verify the fix against the error" stops Kimi from handing back a plausible-but-wrong patch.
7. Fix a bug you can describe but not find
Turn on Thinking mode. This code is supposed to [EXPECTED BEHAVIOR] but instead it [ACTUAL BEHAVIOR]. There's no error thrown. Here's the code: [PASTE CODE]. Input that triggers it: [PASTE INPUT]. Reason through the execution path step by step, find where the actual and expected behavior diverge, and give me the fix plus a one-line explanation of the bug.Why it works: Forcing Kimi to trace the execution path is what catches silent logic bugs where nothing crashes but the output is wrong.
8. Diagnose a race condition or deadlock
Turn on Thinking mode. This concurrent code in [LANGUAGE version] occasionally [HANGS / RETURNS WRONG DATA / DEADLOCKS] under load, but works in single-threaded tests: [PASTE CODE]. Identify the shared state and the interleavings that cause the problem, explain the exact sequence that goes wrong, and give me a corrected version. Note which synchronization primitive you chose and why.Why it works: Concurrency bugs live in the interleavings, and Thinking mode's step-by-step reasoning is what surfaces the bad sequence you couldn't reproduce.
9. Explain a confusing stack trace
Explain this stack trace in plain English and tell me where to start looking: [PASTE STACK TRACE]. My environment is [LANGUAGE / RUNTIME / FRAMEWORK version]. Identify the actual failing line versus library noise, the most likely cause, and the two or three things I should check first. If you need to see a specific file to be sure, tell me which one.Why it works: Asking Kimi to separate the failing line from library noise gets you to the real cause buried under framework frames.
10. Find the performance bottleneck
Turn on Thinking mode. This code is slower than it should be for input of size [SIZE]: [PASTE CODE]. Analyze its time and space complexity, identify the actual bottleneck (not just style), and propose the highest-impact optimization first. Give me the improved code, state the new complexity, and note any tradeoff in readability or memory I'm accepting.Why it works: Asking for complexity analysis and the highest-impact fix first keeps Kimi from micro-optimizing the wrong loop.
Refactor & optimize
Kimi's 256K context lets it hold a large file and reason about it as a whole. Give it the constraint that behavior must not change, and it cleans up code you can merge with confidence.
11. Refactor for readability
Refactor this code for readability and maintainability without changing behavior: [PASTE CODE]. Improve naming, reduce nesting, extract logic where it clarifies intent, and remove dead code. Keep it idiomatic for [LANGUAGE version] and add no new dependencies. Return the refactored version, then a short bullet list of what you changed and why.Why it works: "Without changing behavior" and "no new dependencies" keep the refactor safe to drop into a real PR.
12. Modernize legacy code
Modernize this legacy [LANGUAGE] code to current [LANGUAGE version] idioms and best practices, keeping behavior identical: [PASTE CODE]. Replace deprecated APIs, use modern language features where they genuinely improve the code, and keep the public interface stable. List each change with the reason, and flag anything that needs a test before I ship it.Why it works: Keeping the public interface stable and flagging risky changes lets you modernize old code without a risky rewrite.
13. Add error handling and logging
Add robust error handling and logging to this code without changing its happy-path behavior: [PASTE CODE]. Handle the failure modes that actually matter here (bad input, network, timeouts, missing data), fail loudly where it should and gracefully where it can recover, and log enough context to debug in production without leaking secrets. Use idiomatic [LANGUAGE version] patterns and explain each addition briefly.Why it works: Naming the real failure modes and the "no leaked secrets" rule produces logging you'd actually keep in production.
Code review
Paste a diff or a whole file and Kimi reviews it like a senior engineer. Ask for grouped, actionable feedback so you get a merge decision, not a wall of comments.
14. Code review before merge
Review this code as a senior engineer would before approving the merge: [PASTE CODE OR DIFF]. Check correctness, edge cases, error handling, security, and readability. List issues grouped as Blocking, Should-fix, and Nitpick, each with the line or function and a concrete suggested change. Be direct; don't pad the review with praise.Why it works: Grouping issues by severity with a concrete fix each turns the review into a merge decision instead of a wall of comments.
15. Explain unfamiliar code
Explain what this code does to a developer new to [LANGUAGE / LIBRARY version]: [PASTE CODE]. Start with a one-paragraph overview of its purpose, then walk through the tricky parts block by block. Call out any bugs, edge cases, or performance concerns you notice along the way, and end with the one thing I most need to understand before changing it.Why it works: Pairing the walkthrough with "the one thing to understand before changing it" turns explanation into safe editing.
Tests
Kimi writes thorough tests when you name the framework and ask it to flag ambiguous behavior. It's especially good at turning a bug you just fixed into a regression test so it never comes back.
16. Write unit tests for a function
Write thorough unit tests for this function using [TEST FRAMEWORK]: [PASTE FUNCTION]. Cover the happy path, edge cases, invalid inputs, and boundary conditions. Give each test a clear name and a one-line comment on what it verifies. If any behavior in the function looks like a bug or is ambiguous enough to need a spec decision, note it separately instead of testing the buggy behavior as correct.Why it works: Asking Kimi to flag ambiguous behavior surfaces spec gaps instead of freezing a bug into your test suite.
17. Generate edge-case test data
Generate a set of test inputs for a function that [WHAT IT DOES], with signature [PASTE SIGNATURE]. Cover typical cases, boundaries, empty and null values, extreme sizes, and malformed input. Present them as a table: input | why it matters | expected behavior. Call out any inputs where the correct behavior isn't obvious and needs a decision.Why it works: The table format forces coverage across boundaries and malformed input before you write a single test.
18. Write an integration test
Write an integration test in [TEST FRAMEWORK] for this flow: [DESCRIBE THE FLOW, e.g. request hits endpoint, writes to DB, returns response]. Here's the relevant code: [PASTE CODE]. Set up and tear down any state cleanly, test the real interaction rather than mocking everything, and assert on the observable outcome. Note any external dependency I should stub and why.Why it works: Testing the observable outcome across components catches the wiring bugs that pure unit tests miss.
19. Turn a bug into a regression test
I just fixed this bug: [DESCRIBE THE BUG AND THE FIX]. Here's the fixed code: [PASTE CODE]. Write a regression test in [TEST FRAMEWORK] that would have failed before the fix and passes now, so this exact bug can't come back silently. Name the test after the bug, and add a one-line comment linking it to what went wrong.Why it works: A test that fails before the fix and passes after is the only way to make sure a squashed bug stays dead.
SQL & regex
Paste your schema or a sample of the data and state the database, and Kimi writes correct, performance-aware queries. For regex, name the flavor and give match and non-match examples so it can verify its own pattern.
20. SQL query from plain English
Write a [PostgreSQL] query for this request: [WHAT I WANT]. Here's the schema: [PASTE TABLES / COLUMNS]. Return the query, a one-line explanation of each join and filter, and a note on which indexes would keep it fast at scale. If my request is ambiguous, state the assumption you made rather than guessing silently.Why it works: Giving Kimi the real schema and asking it to name assumptions produces a query you can trust, not a syntactically valid guess.
21. Optimize a slow SQL query
Turn on Thinking mode. This [DATABASE version] query is slow: [PASTE QUERY]. Schema and rough row counts: [PASTE DETAILS]. Here's the query plan if it helps: [PASTE EXPLAIN OUTPUT]. Explain why it's slow, rewrite it for performance while returning identical results, and recommend the specific indexes to add. Show the before-and-after and estimate the impact.Why it works: Feeding Kimi the EXPLAIN plan and row counts lets it optimize the real bottleneck instead of guessing at a query that times out in production.
22. Regex builder and explainer
Build a regex for [LANGUAGE / FLAVOR] that matches [WHAT TO MATCH] but not [WHAT TO EXCLUDE]. Give me the pattern, a plain-English breakdown of each part, and 6 test strings (4 that should match, 2 that shouldn't) with the expected result for each. Keep it as simple as the task allows, and warn me about any catastrophic-backtracking risk.Why it works: Match and non-match examples plus a backtracking warning give you a regex you can maintain instead of a fragile one-liner.
System design
For algorithm choices and architecture, turn on Thinking mode so you see the tradeoffs reasoned out, not just the final answer. Kimi's long-horizon strength shows up when the design has many moving parts.
23. Explain an algorithm and its complexity
Explain how [ALGORITHM] works to a developer who knows the basics but hasn't used it. Walk through the intuition, then the steps with a small worked example, then the time and space complexity and why. Show a clean reference implementation in [LANGUAGE version], and note when this is the right choice versus a simpler alternative.Why it works: The intuition-then-worked-example structure gets you genuine understanding before you drop the algorithm into your code.
24. Design a system with Thinking mode
Turn on Thinking mode. Design a system for [WHAT IT DOES] at roughly [SCALE: users / requests per second / data size]. Cover the high-level architecture, the main components and how they communicate, the data stores and why, and how it handles load, failures, and growth. Discuss two or three key tradeoffs explicitly, and call out the biggest risk in your design.Why it works: Forcing explicit tradeoffs and a named biggest risk turns a component diagram into a design you can actually defend.
Agentic builds (Agent Mode / OK Computer)
Kimi's headline strength is agentic coding. In Agent Mode (branded "OK Computer") it runs an Agent Swarm of sub-agents that plan, write files, run code, and fix errors over many steps. Describe the outcome and the constraints, then let it work. For a deeper playbook see how to prompt Kimi for agentic tasks.
25. Build a full app in Agent Mode
Use Agent Mode. Build a working [WHAT THE APP IS] using [STACK / FRAMEWORK version]. Core features: [LIST THEM]. Constraints: [AUTH / DATABASE / STYLING / NO PAID SERVICES]. Plan the file structure first and show it to me, then build each file, run the app, and fix any errors you hit. When it runs, give me the exact commands to start it locally and a short list of what's done versus what I'd add next.Why it works: Asking for the plan first, then a build-run-fix loop, uses the Agent Swarm to deliver a running app instead of a pile of untested files.
26. Add a feature across a codebase in Agent Mode
Use Agent Mode. In this project, add [FEATURE]. Files that likely matter: [LIST OR "explore the repo first"]. Trace how the current code handles [RELATED EXISTING FEATURE], mirror that pattern, and touch as few files as possible. Update any tests and docs affected, run the test suite, and fix failures. When you're done, summarize every file you changed and why, and flag anything you were unsure about.Why it works: Telling Kimi to mirror an existing pattern and touch few files keeps a multi-file change consistent with the codebase instead of bolted on.
27. Turn a screenshot into working code
Use Agent Mode with this screenshot: [ATTACH IMAGE OF THE UI / MOCKUP]. Build it as a responsive [FRAMEWORK version] component using [STYLING APPROACH]. Match the layout, spacing, and states you can see, use semantic HTML and accessible markup, and use placeholder data where the real content isn't shown. Build it, render it, and adjust until it matches the screenshot, then show me the final files and note anything you had to guess.Why it works: Kimi is multimodal, so a real screenshot plus the design-to-code loop gets a closer match than any written description of the layout.
28. Autonomous debug-and-fix loop in Agent Mode
Use Agent Mode. This project is failing with: [PASTE ERROR / DESCRIBE THE BROKEN BEHAVIOR]. Reproduce the failure by running [COMMAND / STEPS], then find the root cause across the relevant files, apply the fix, and re-run to confirm it's resolved. Don't change unrelated code. When it passes, show me the diff, explain what was wrong in two sentences, and add a test that would have caught it.Why it works: The reproduce-fix-re-run loop lets the Agent Swarm confirm its own fix, so you get a verified diff rather than a guess.
Want the shortest possible reference? The Kimi prompt cheat sheet lists every mode and toggle on one page, and bookmark the full Kimi prompts roundup for the rest of the collection.
Frequently Asked Questions
Which Kimi model are these coding prompts built for?
They target Kimi K2.7, the coding-focused agentic model Moonshot AI released in June 2026, part of the K2 family. It's a 1-trillion-parameter mixture-of-experts model with about 32B active parameters, a 256K-token context window, and multimodal input. The weights are open, and everything here runs on the free assistant at kimi.com.
When should I turn on Thinking mode for coding?
Turn on Thinking mode for hard bugs, edge cases, race conditions, and system design, where you want Kimi to reason step by step before answering. For quick edits, boilerplate, or explaining a snippet, Instant mode is faster and works fine.
How much code can I paste into Kimi at once?
Kimi K2.7 has a 256K-token context window, so you can paste whole files or a large section of a repo in one message. For anything bigger, upload the files directly or use Agent Mode, which reads and edits files across a project on its own.
What is Agent Mode (OK Computer)?
Agent Mode, branded OK Computer, lets Kimi autonomously build and edit whole apps and files over many steps. It runs an Agent Swarm of sub-agents that plan, write code, run it, and fix errors, so you describe the outcome and let it work rather than copy-pasting each file yourself.
Is Kimi good for SQL and regex?
Yes. Paste your schema or sample data and state the database (PostgreSQL, MySQL, SQLite) and it writes correct, performance-aware queries. For regex, name the flavor and give match and non-match examples, and it returns a pattern with a plain-English breakdown and test cases.
Can Kimi read my code files and images?
Yes. Kimi is multimodal, so you can upload code files, documents, and images, including screenshots or design mockups for design-to-code. Attaching the real file or a screenshot of the error beats describing it, and it all stays in the 256K context.
Should I use Web search for coding questions?
Turn on Web search when you need current library versions, breaking changes, or recent API docs, and ask Kimi to cite its sources. For pure logic, debugging your own pasted code, or algorithm work, you don't need it, and it keeps answers faster.
How do the [BRACKET] placeholders work?
Anything in square brackets is a swap-in. Replace [LANGUAGE], [PASTE CODE], or [PASTE ERROR] with your own details before sending. The rest of each prompt is written to be copy-paste ready.